[
  {
    "path": ".devcontainer/devcontainer.json",
    "content": "// For format details, see https://aka.ms/devcontainer.json. For config options, see the\n// README at: https://github.com/devcontainers/templates/tree/main/src/debian\n{\n  \"name\": \"Development\",\n  \"image\": \"mcr.microsoft.com/devcontainers/typescript-node:latest\",\n  \"features\": {\n    \"ghcr.io/devcontainers/features/node:1\": {}\n  },\n  \"postCreateCommand\": \"yarn install\",\n  \"customizations\": {\n    \"vscode\": {\n      \"extensions\": [\"esbenp.prettier-vscode\"]\n    }\n  }\n}\n"
  },
  {
    "path": ".github/CODEOWNERS",
    "content": "# This file is used to automatically assign reviewers to PRs\n# For more information see: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners\n\n* @openai/sdks-team\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.yml",
    "content": "name: Bug report\ndescription: Report an issue or bug with this library\nlabels: ['bug']\nbody:\n  - type: markdown\n    attributes:\n      value: |\n        Thanks for taking the time to fill out this bug report!\n  - type: checkboxes\n    id: non_api\n    attributes:\n      label: Confirm this is a Node library issue and not an underlying OpenAI API issue\n      description: Issues with the underlying OpenAI API should be reported on our [Developer Community](https://community.openai.com/c/api/7)\n      options:\n        - label: This is an issue with the Node library\n          required: true\n  - type: textarea\n    id: what-happened\n    attributes:\n      label: Describe the bug\n      description: A clear and concise description of what the bug is, and any additional context.\n      placeholder: Tell us what you see!\n    validations:\n      required: true\n  - type: textarea\n    id: repro-steps\n    attributes:\n      label: To Reproduce\n      description: Steps to reproduce the behavior.\n      placeholder: |\n        1. Fetch a '...'\n        2. Update the '....'\n        3. See error\n    validations:\n      required: true\n  - type: textarea\n    id: code-snippets\n    attributes:\n      label: Code snippets\n      description: If applicable, add code snippets to help explain your problem.\n      render: JavaScript\n    validations:\n      required: false\n  - type: input\n    id: os\n    attributes:\n      label: OS\n      placeholder: macOS\n    validations:\n      required: true\n  - type: input\n    id: language-version\n    attributes:\n      label: Node version\n      placeholder: Node v16.14.2\n    validations:\n      required: true\n  - type: input\n    id: lib-version\n    attributes:\n      label: Library version\n      placeholder: openai v3.0.1\n    validations:\n      required: true\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/config.yml",
    "content": "blank_issues_enabled: false\ncontact_links:\n  - name: OpenAI support\n    url: https://help.openai.com/\n    about: |\n      Please only file issues here that you believe represent actual bugs or feature requests for the OpenAI Node library.\n      If you're having general trouble with the OpenAI API, please visit our help center to get support.\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.yml",
    "content": "name: Feature request\ndescription: Suggest an idea for this library\nlabels: ['feature-request']\nbody:\n  - type: markdown\n    attributes:\n      value: |\n        Thanks for taking the time to fill out this feature request!\n  - type: checkboxes\n    id: non_api\n    attributes:\n      label: Confirm this is a feature request for the Node library and not the underlying OpenAI API.\n      description: Feature requests for the underlying OpenAI API should be reported on our [Developer Community](https://community.openai.com/c/api/7)\n      options:\n        - label: This is a feature request for the Node library\n          required: true\n  - type: textarea\n    id: feature\n    attributes:\n      label: Describe the feature or improvement you're requesting\n      description: A clear and concise description of what you want to happen.\n    validations:\n      required: true\n  - type: textarea\n    id: context\n    attributes:\n      label: Additional context\n      description: Add any other context about the feature request here.\n"
  },
  {
    "path": ".github/pull_request_template.md",
    "content": "<!-- Thank you for contributing to this project! -->\n<!-- The code in this repository is all auto-generated, and is not meant to be edited manually. -->\n<!-- We recommend opening an Issue instead, but you are still welcome to open a PR to share for -->\n<!-- an improvement if you wish, just note that we are unlikely to merge it as-is. -->\n\n- [ ] I understand that this repository is auto-generated and my pull request may not be merged\n\n## Changes being requested\n\n## Additional context & links\n"
  },
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: CI\non:\n  push:\n    branches:\n      - '**'\n      - '!integrated/**'\n      - '!stl-preview-head/**'\n      - '!stl-preview-base/**'\n      - '!generated'\n      - '!codegen/**'\n      - 'codegen/stl/**'\n  pull_request:\n    branches-ignore:\n      - 'stl-preview-head/**'\n      - 'stl-preview-base/**'\n\njobs:\n  lint:\n    timeout-minutes: 10\n    name: lint\n    runs-on: ${{ github.repository == 'stainless-sdks/openai-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}\n    if: github.event_name == 'push' || github.event.pull_request.head.repo.fork\n    steps:\n      - uses: actions/checkout@v6\n\n      - name: Set up Node\n        uses: actions/setup-node@v4\n        with:\n          node-version: '20'\n\n      - name: Bootstrap\n        run: ./scripts/bootstrap\n\n      - name: Check types\n        run: ./scripts/lint\n\n  build:\n    timeout-minutes: 5\n    name: build\n    runs-on: ${{ github.repository == 'stainless-sdks/openai-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}\n    if: github.event_name == 'push' || github.event.pull_request.head.repo.fork\n    permissions:\n      contents: read\n      id-token: write\n    steps:\n      - uses: actions/checkout@v6\n\n      - name: Set up Node\n        uses: actions/setup-node@v4\n        with:\n          node-version: '20'\n\n      - name: Bootstrap\n        run: ./scripts/bootstrap\n\n      - name: Check build\n        run: ./scripts/build\n\n      - name: Get GitHub OIDC Token\n        if: |-\n          github.repository == 'stainless-sdks/openai-typescript' &&\n          !startsWith(github.ref, 'refs/heads/stl/')\n        id: github-oidc\n        uses: actions/github-script@v8\n        with:\n          script: core.setOutput('github_token', await core.getIDToken());\n\n      - name: Upload tarball\n        if: |-\n          github.repository == 'stainless-sdks/openai-typescript' &&\n          !startsWith(github.ref, 'refs/heads/stl/')\n        env:\n          URL: https://pkg.stainless.com/s\n          AUTH: ${{ steps.github-oidc.outputs.github_token }}\n          SHA: ${{ github.sha }}\n        run: ./scripts/utils/upload-artifact.sh\n  test:\n    timeout-minutes: 10\n    name: test\n    runs-on: ${{ github.repository == 'stainless-sdks/openai-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}\n    if: github.event_name == 'push' || github.event.pull_request.head.repo.fork\n    steps:\n      - uses: actions/checkout@v6\n\n      - name: Set up Node\n        uses: actions/setup-node@v4\n        with:\n          node-version: '20'\n\n      - name: Bootstrap\n        run: ./scripts/bootstrap\n\n      - name: Run tests\n        run: ./scripts/test\n\n  examples:\n    timeout-minutes: 10\n    name: examples\n    runs-on: ${{ github.repository == 'stainless-sdks/openai-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}\n    if: github.repository == 'openai/openai-node'\n\n    steps:\n      - uses: actions/checkout@v4\n\n      - name: Set up Node\n        uses: actions/setup-node@v4\n        with:\n          node-version: '20'\n      - name: Install dependencies\n        run: |\n          yarn install\n\n      - env:\n          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}\n        run: |\n          yarn tsn examples/demo.ts\n\n  ecosystem_tests:\n    name: ecosystem tests (v${{ matrix.node-version }})\n    runs-on: ubuntu-latest\n    timeout-minutes: 20\n    strategy:\n      fail-fast: false\n      matrix:\n        node-version: ['20']\n\n    steps:\n      - uses: actions/checkout@v4\n\n      - name: Set up Node\n        uses: actions/setup-node@v4\n        with:\n          node-version: '${{ matrix.node-version }}'\n\n      - uses: denoland/setup-deno@v1\n        with:\n          deno-version: v1.39.0\n\n      - uses: oven-sh/setup-bun@v2\n\n      - name: Bootstrap\n        run: ./scripts/bootstrap\n\n      - name: Run ecosystem tests\n        run: |\n          yarn tsn ecosystem-tests/cli.ts --live --verbose --parallel --jobs=4 --retry=3\n        env:\n          DISABLE_V8_COMPILE_CACHE: '1'\n          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}\n"
  },
  {
    "path": ".github/workflows/create-releases.yml",
    "content": "name: Create releases\non:\n  schedule:\n    - cron: '0 5 * * *' # every day at 5am UTC\n  push:\n    branches:\n      - master\n\njobs:\n  release:\n    name: release\n    if: github.ref == 'refs/heads/master' && github.repository == 'openai/openai-node'\n    runs-on: ubuntu-latest\n    environment: publish\n    permissions:\n      contents: read\n      id-token: write\n\n    steps:\n      - uses: actions/checkout@v6\n\n      - uses: stainless-api/trigger-release-please@v1\n        id: release\n        with:\n          repo: ${{ github.event.repository.full_name }}\n          stainless-api-key: ${{ secrets.STAINLESS_API_KEY }}\n\n      - name: Set up Node\n        if: ${{ steps.release.outputs.releases_created }}\n        uses: actions/setup-node@v3\n        with:\n          node-version: '20'\n\n      - name: Install dependencies\n        if: ${{ steps.release.outputs.releases_created }}\n        run: |\n          yarn install\n\n      - name: Publish to NPM\n        if: ${{ steps.release.outputs.releases_created }}\n        run: |\n          bash ./bin/publish-npm\n\n      - name: Publish to JSR\n        if: ${{ steps.release.outputs.releases_created }}\n        run: |\n          bash ./bin/publish-jsr\n\n"
  },
  {
    "path": ".github/workflows/detect-breaking-changes.yml",
    "content": "name: CI\non:\n  pull_request:\n    branches:\n      - main\n      - next\n\njobs:\n  detect_breaking_changes:\n    runs-on: 'ubuntu-latest'\n    name: detect-breaking-changes\n    if: github.repository == 'openai/openai-node'\n    steps:\n      - name: Calculate fetch-depth\n        run: |\n          echo \"FETCH_DEPTH=$(expr ${{ github.event.pull_request.commits }} + 1)\" >> $GITHUB_ENV\n\n      - uses: actions/checkout@v6\n        with:\n          # Ensure we can check out the pull request base in the script below.\n          fetch-depth: ${{ env.FETCH_DEPTH }}\n\n      - name: Set up Node\n        uses: actions/setup-node@v3\n        with:\n          node-version: '20'\n      - name: Install dependencies\n        run: |\n          yarn install\n\n      - name: Detect breaking changes\n        run: |\n          # Try to check out previous versions of the breaking change detection script. This ensures that\n          # we still detect breaking changes when entire files and their tests are removed.\n          git checkout \"${{ github.event.pull_request.base.sha }}\" -- ./scripts/detect-breaking-changes 2>/dev/null || true\n          ./scripts/detect-breaking-changes ${{ github.event.pull_request.base.sha }}\n  agents_sdk:\n    runs-on: 'ubuntu-latest'\n    name: Detect Agents SDK regressions\n    if: github.repository == 'openai/openai-node'\n    steps:\n      - name: Set up Node\n        uses: actions/setup-node@v4\n        with:\n          node-version: '20'\n\n      - name: Install pnpm\n        uses: pnpm/action-setup@v4\n        with:\n          version: 10.25.0\n          run_install: false\n\n      # Setup this sdk\n      - uses: actions/checkout@v4\n        with:\n          path: openai-node\n\n      - name: Bootstrap\n        working-directory: openai-node\n        run: ./scripts/bootstrap\n\n      - name: Build\n        working-directory: openai-node\n        run: ./scripts/build\n\n      # Setup the agents packages\n      - uses: actions/checkout@v4\n        with:\n          repository: openai/openai-agents-js\n          path: openai-agents-js\n\n      - name: Link agents packages to local SDKs\n        working-directory: openai-agents-js\n        run: pnpm --filter @openai/agents-core --filter @openai/agents-openai --filter @openai/agents add file:../../../openai-node/dist\n\n      - name: Install dependencies\n        working-directory: openai-agents-js\n        run: pnpm install\n\n      - name: Build all packages\n        working-directory: openai-agents-js\n        run: pnpm build\n\n      - name: Run linter\n        working-directory: openai-agents-js\n        run: pnpm lint\n\n      - name: Type-check docs scripts\n        working-directory: openai-agents-js\n        run: pnpm docs:scripts:check\n"
  },
  {
    "path": ".github/workflows/publish-jsr.yml",
    "content": "# This workflow publishes the package to JSR.\n# You can run this workflow manually by navigating to https://www.github.com/openai/openai-node/actions/workflows/publish-jsr.yml\nname: Publish JSR\non:\n  workflow_dispatch:\n\njobs:\n  publish:\n    name: publish\n    runs-on: ubuntu-latest\n    permissions:\n      contents: read\n      id-token: write\n    environment: publish\n\n    steps:\n      - uses: actions/checkout@v6\n\n      - name: Set up Node\n        uses: actions/setup-node@v3\n        with:\n          node-version: '20'\n\n      - name: Install dependencies\n        run: |\n          yarn install\n\n      - name: Publish to JSR\n        run: |\n          bash ./bin/publish-jsr\n"
  },
  {
    "path": ".github/workflows/publish-npm.yml",
    "content": "# This workflow publishes the package to NPM.\n# You can run this workflow manually by navigating to https://www.github.com/openai/openai-node/actions/workflows/publish-npm.yml\nname: Publish NPM\non:\n  workflow_dispatch:\n\njobs:\n  publish:\n    name: publish\n    runs-on: ubuntu-latest\n    permissions:\n      contents: read\n      id-token: write\n    environment: publish\n\n    steps:\n      - uses: actions/checkout@v6\n\n      - name: Set up Node\n        uses: actions/setup-node@v3\n        with:\n          node-version: '20'\n\n      - name: Install dependencies\n        run: |\n          yarn install\n\n      - name: Publish to NPM\n        run: |\n          bash ./bin/publish-npm\n"
  },
  {
    "path": ".github/workflows/release-doctor.yml",
    "content": "name: Release Doctor\non:\n  push:\n    branches:\n      - master\n  workflow_dispatch:\n\njobs:\n  release_doctor:\n    name: release doctor\n    runs-on: ubuntu-latest\n    environment: publish\n    if: github.repository == 'openai/openai-node' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')\n\n    steps:\n      - uses: actions/checkout@v6\n\n      - name: Check release environment\n        run: |\n          bash ./bin/check-release-environment\n        env:\n          STAINLESS_API_KEY: ${{ secrets.STAINLESS_API_KEY }}\n\n"
  },
  {
    "path": ".gitignore",
    "content": ".prism.log\nnode_modules\nyarn-error.log\ncodegen.log\nBrewfile.lock.json\ndist\ndist-deno\n/oidc\n/*.tgz\n.idea/\ntmp\n.pack\necosystem-tests/deno/package.json\necosystem-tests/*/openai.tgz\n.dev.vars\n.eslintcache\n"
  },
  {
    "path": ".prettierignore",
    "content": "CHANGELOG.md\n/ecosystem-tests/*/**\n/node_modules\n/deno\n\n# don't format tsc output, will break source maps\n/dist\n"
  },
  {
    "path": ".prettierrc.json",
    "content": "{\n  \"arrowParens\": \"always\",\n  \"experimentalTernaries\": true,\n  \"printWidth\": 110,\n  \"singleQuote\": true,\n  \"trailingComma\": \"all\"\n}\n"
  },
  {
    "path": ".release-please-manifest.json",
    "content": "{\n  \".\": \"6.32.0\"\n}\n"
  },
  {
    "path": ".stats.yml",
    "content": "configured_endpoints: 151\nopenapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-55ef7034334e938c30656a404ce5e21466103be87542a796425346299f450404.yml\nopenapi_spec_hash: 4a5bfd2ee4ad47f5b7cf6f1ad08d5d7f\nconfig_hash: 96fbf82cf74a44ccd513f5acf0956ffd\n"
  },
  {
    "path": "Brewfile",
    "content": "brew \"node\"\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\n\n## 6.32.0 (2026-03-17)\n\nFull Changelog: [v6.31.0...v6.32.0](https://github.com/openai/openai-node/compare/v6.31.0...v6.32.0)\n\n### Features\n\n* **api:** 5.4 nano and mini model slugs ([068df6d](https://github.com/openai/openai-node/commit/068df6d625d7faa76dfac160065f1ca550539ba8))\n\n## 6.31.0 (2026-03-16)\n\nFull Changelog: [v6.30.1...v6.31.0](https://github.com/openai/openai-node/compare/v6.30.1...v6.31.0)\n\n### Features\n\n* **api:** add in/nin filter types to ComparisonFilter ([b2eda27](https://github.com/openai/openai-node/commit/b2eda274418ceb9bbdb3778cb6a5ee28090df8ad))\n\n## 6.30.1 (2026-03-16)\n\nFull Changelog: [v6.30.0...v6.30.1](https://github.com/openai/openai-node/compare/v6.30.0...v6.30.1)\n\n### Chores\n\n* **internal:** tweak CI branches ([25f5d74](https://github.com/openai/openai-node/commit/25f5d74c1fc16e3303fcb87022f5f0559b052cbf))\n\n## 6.30.0 (2026-03-16)\n\nFull Changelog: [v6.29.0...v6.30.0](https://github.com/openai/openai-node/compare/v6.29.0...v6.30.0)\n\n### Features\n\n* **api:** add /v1/videos endpoint option to batches ([271d879](https://github.com/openai/openai-node/commit/271d87979f16950900f4253915bdda319b7fe935))\n* **api:** add defer_loading field to NamespaceTool ([7cc8f0a](https://github.com/openai/openai-node/commit/7cc8f0a736ea7ba0aa3e7860b4c30eaaa5795966))\n\n\n### Bug Fixes\n\n* **api:** oidc publishing for npm ([fa50066](https://github.com/openai/openai-node/commit/fa500666e38379f2241ac43d60e2eb7eef7d39cb))\n\n## 6.29.0 (2026-03-13)\n\nFull Changelog: [v6.28.0...v6.29.0](https://github.com/openai/openai-node/compare/v6.28.0...v6.29.0)\n\n### Features\n\n* **api:** custom voices ([a11307a](https://github.com/openai/openai-node/commit/a11307afab49299fdf7e7ed3675d3e277d9b5c60))\n\n## 6.28.0 (2026-03-13)\n\nFull Changelog: [v6.27.0...v6.28.0](https://github.com/openai/openai-node/compare/v6.27.0...v6.28.0)\n\n### Features\n\n* **api:** manual updates ([d543959](https://github.com/openai/openai-node/commit/d54395976aa4c1c1864bb45dbaf81ec1d66b8c6b))\n* **api:** manual updates ([4f87840](https://github.com/openai/openai-node/commit/4f878406e029ae7527201251632e3fa00b800045))\n* **api:** sora api improvements: character api, video extensions/edits, higher resolution exports. ([262dac2](https://github.com/openai/openai-node/commit/262dac25aec6c9caa561f57a0b9e2a086f47a26a))\n\n\n### Bug Fixes\n\n* **types:** remove detail field from ResponseInputFile and ResponseInputFileContent ([8d6c0cd](https://github.com/openai/openai-node/commit/8d6c0cdbbf08829db08745597e1806661534853f))\n\n\n### Chores\n\n* **internal:** update dependencies to address dependabot vulnerabilities ([f5810ee](https://github.com/openai/openai-node/commit/f5810ee5f5bf96e81a77f91939f3d56427c46e00))\n* match http protocol with ws protocol instead of wss ([6f4e936](https://github.com/openai/openai-node/commit/6f4e936bc2211da885bf492615b2bf413887576b))\n* **mcp-server:** improve instructions ([aad9ca1](https://github.com/openai/openai-node/commit/aad9ca15ddbb8dbc27ed6b2aa9b242af9bbf7b8f))\n* use proper capitalization for WebSockets ([cb4cf62](https://github.com/openai/openai-node/commit/cb4cf6297c2a0eb7d3f55f8850e6e8ffc4c7ecc6))\n\n## 6.27.0 (2026-03-05)\n\nFull Changelog: [v6.26.0...v6.27.0](https://github.com/openai/openai-node/compare/v6.26.0...v6.27.0)\n\n### Features\n\n* **api:** The GA ComputerTool now uses the CompuerTool class. The 'computer_use_preview' tool is moved to ComputerUsePreview ([0206188](https://github.com/openai/openai-node/commit/0206188f760be830738136e37dcf7be6ea0fe20c))\n\n\n### Chores\n\n* **internal:** improve import alias names ([9cc2478](https://github.com/openai/openai-node/commit/9cc24789730a309037ef81f5a30af515d700459a))\n\n## 6.26.0 (2026-03-05)\n\nFull Changelog: [v6.25.0...v6.26.0](https://github.com/openai/openai-node/compare/v6.25.0...v6.26.0)\n\n### Features\n\n* **api:** gpt-5.4, tool search tool, and new computer tool ([1d1e5a9](https://github.com/openai/openai-node/commit/1d1e5a9b5aeb11b0e940b4532dcd6a3fcc23898a))\n\n\n### Bug Fixes\n\n* **api:** internal schema fixes ([6b401ad](https://github.com/openai/openai-node/commit/6b401ad7d3ff2ead9cfa577daf8381f62ea85b93))\n* **api:** manual updates ([2b54919](https://github.com/openai/openai-node/commit/2b549195c70581022d9d64c443ab08202c6faeb7))\n* **api:** readd phase ([4a0cf29](https://github.com/openai/openai-node/commit/4a0cf2974865519d3b512fb377bc4ba305dce7b7))\n* **api:** remove phase from message types, prompt_cache_key param in responses ([088fca6](https://github.com/openai/openai-node/commit/088fca6a4d5d1a577500acb5579ee403292d8911))\n\n\n### Chores\n\n* **internal:** codegen related update ([6a0aa9e](https://github.com/openai/openai-node/commit/6a0aa9e2ff10e78f8b9afd777174d16537a29c8e))\n* **internal:** codegen related update ([b2a4299](https://github.com/openai/openai-node/commit/b2a42991cbe83eee45a342f19a5a99ce1d78b36a))\n* **internal:** move stringifyQuery implementation to internal function ([f9f4660](https://github.com/openai/openai-node/commit/f9f46609cf5c1fc51e437c23251c5a7d0519d55d))\n* **internal:** reduce warnings ([7e19492](https://github.com/openai/openai-node/commit/7e194929156052b0efbda9ca48c3ed6de8c18d2f))\n\n## 6.25.0 (2026-02-24)\n\nFull Changelog: [v6.24.0...v6.25.0](https://github.com/openai/openai-node/compare/v6.24.0...v6.25.0)\n\n### Features\n\n* **api:** add phase ([e32b853](https://github.com/openai/openai-node/commit/e32b853c3c57f2d0e4c05b09177b94677aed0e5a))\n\n\n### Bug Fixes\n\n* **api:** fix phase enum ([2ffe1be](https://github.com/openai/openai-node/commit/2ffe1be2600d0154b3355eefa61707470a341a95))\n* **api:** phase docs ([7fdfa38](https://github.com/openai/openai-node/commit/7fdfa38c1fa2bd383e1171510918c6db5f0937d8))\n\n\n### Chores\n\n* **internal:** refactor sse event parsing ([0ea2380](https://github.com/openai/openai-node/commit/0ea238054c0473adc97f4173a0ad5ba8bcfa4e29))\n\n## 6.24.0 (2026-02-24)\n\nFull Changelog: [v6.23.0...v6.24.0](https://github.com/openai/openai-node/compare/v6.23.0...v6.24.0)\n\n### Features\n\n* **api:** add gpt-realtime-1.5 and gpt-audio-1.5 models to realtime ([75875bf](https://github.com/openai/openai-node/commit/75875bfb850c0780878553c566fe8821048ae5e8))\n\n## 6.23.0 (2026-02-23)\n\nFull Changelog: [v6.22.0...v6.23.0](https://github.com/openai/openai-node/compare/v6.22.0...v6.23.0)\n\n### Features\n\n* **api:** websockets for responses api ([c6b96b8](https://github.com/openai/openai-node/commit/c6b96b8b8d5f8132e0a4c5f7399a04185302adcc))\n\n\n### Bug Fixes\n\n* **docs/contributing:** correct pnpm link command ([8a198a5](https://github.com/openai/openai-node/commit/8a198a5aa60209e26509651cdad110aadf164527))\n* **internal:** skip tests that depend on mock server ([3d88cb0](https://github.com/openai/openai-node/commit/3d88cb061a9a4d187931d4c892a87bd5e5f09c4d))\n\n\n### Chores\n\n* **internal/client:** fix form-urlencoded requests ([646cedd](https://github.com/openai/openai-node/commit/646cedd2842716b1768d81705110cc573d6ddc33))\n* update mock server docs ([29f78f3](https://github.com/openai/openai-node/commit/29f78f310b7c336318705c382fd92a324d4b1ea2))\n\n\n### Documentation\n\n* **api:** document 2000 file limit in file-batches create parameters ([ff7bde0](https://github.com/openai/openai-node/commit/ff7bde08d8d02b8bda5f4e50bef65271a8f2a190))\n* **api:** enhance method descriptions across audio/chat/skills/videos/responses ([f5e02a1](https://github.com/openai/openai-node/commit/f5e02a1dcad492fd3dab2d1a289c12af082cdef4))\n* **api:** update safety_identifier description in chat/responses ([a55e0ef](https://github.com/openai/openai-node/commit/a55e0ef720cfb231e09e598ff0e8e60ef91e9088))\n\n## 6.22.0 (2026-02-14)\n\nFull Changelog: [v6.21.0...v6.22.0](https://github.com/openai/openai-node/compare/v6.21.0...v6.22.0)\n\n### Features\n\n* **api:** container network_policy and skills ([65c1482](https://github.com/openai/openai-node/commit/65c1482a41f16d39ff6ba26849a72b417b27403e))\n\n\n### Bug Fixes\n\n* **docs:** restore helper methods in API reference ([3a4c189](https://github.com/openai/openai-node/commit/3a4c189712292f280ca34326fe17e202180951bf))\n* **webhooks:** restore webhook type exports ([49bbf46](https://github.com/openai/openai-node/commit/49bbf46f0ed14ce2a050d10baa4ad7a8481a773d))\n\n\n### Chores\n\n* **internal:** avoid type checking errors with ts-reset ([4b0d1f2](https://github.com/openai/openai-node/commit/4b0d1f27207dea6054291707d7bbdeb86dbcf4b2))\n\n\n### Documentation\n\n* split `api.md` by standalone resources ([48e07d6](https://github.com/openai/openai-node/commit/48e07d65894c22b543e669d62fa42a00cc3d0430))\n* update comment ([e3a1ea0](https://github.com/openai/openai-node/commit/e3a1ea0400b428e0e21666f96e3a9345468678d5))\n\n## 6.21.0 (2026-02-10)\n\nFull Changelog: [v6.20.0...v6.21.0](https://github.com/openai/openai-node/compare/v6.20.0...v6.21.0)\n\n### Features\n\n* **api:** support for images in batch api ([017ba1c](https://github.com/openai/openai-node/commit/017ba1cb5a08428ca59197764cff460c70950e84))\n\n## 6.20.0 (2026-02-10)\n\nFull Changelog: [v6.19.0...v6.20.0](https://github.com/openai/openai-node/compare/v6.19.0...v6.20.0)\n\n### Features\n\n* **api:** skills and hosted shell ([e4bdd62](https://github.com/openai/openai-node/commit/e4bdd6205a0225d662ddeb07367f26094eaadbdd))\n\n## 6.19.0 (2026-02-09)\n\nFull Changelog: [v6.18.0...v6.19.0](https://github.com/openai/openai-node/compare/v6.18.0...v6.19.0)\n\n### Features\n\n* **api:** responses context_management ([40e7671](https://github.com/openai/openai-node/commit/40e7671675159966fe219b3aebfb24b9b03f2c95))\n\n## 6.18.0 (2026-02-05)\n\nFull Changelog: [v6.17.0...v6.18.0](https://github.com/openai/openai-node/compare/v6.17.0...v6.18.0)\n\n### Features\n\n* **api:** image generation actions for responses; ResponseFunctionCallArgumentsDoneEvent.name ([d373c32](https://github.com/openai/openai-node/commit/d373c3210d9299381e20520c217167b387b46105))\n\n\n### Bug Fixes\n\n* **client:** avoid memory leak with abort signals ([b449f36](https://github.com/openai/openai-node/commit/b449f36609b727f3f147fad19e8d064225bc8621))\n* **client:** avoid removing abort listener too early ([1c045f7](https://github.com/openai/openai-node/commit/1c045f701743017ac7b4e2be0dfc8706a3b0213a))\n* **client:** undo change to web search Find action ([8259b45](https://github.com/openai/openai-node/commit/8259b457c6f73c78066af0e1a76be0125caeb1ae))\n* **client:** update type for `find_in_page` action ([9aa8d98](https://github.com/openai/openai-node/commit/9aa8d9822e60afb595c585f7be75087378b724bd))\n\n\n### Chores\n\n* **client:** do not parse responses with empty content-length ([4a118fa](https://github.com/openai/openai-node/commit/4a118fa3e09b0ad2bc4899b2a074fd60103796a0))\n* **client:** restructure abort controller binding ([a4d7151](https://github.com/openai/openai-node/commit/a4d71518787849ec1f530da3c8550ea0f8746668))\n* **internal:** fix pagination internals not accepting option promises ([6677905](https://github.com/openai/openai-node/commit/667790549f9160ba0cac484a8de09d8966cc13f0))\n\n## 6.17.0 (2026-01-28)\n\nFull Changelog: [v6.16.0...v6.17.0](https://github.com/openai/openai-node/compare/v6.16.0...v6.17.0)\n\n### Features\n\n* **api:** add shell_call_output status field ([edf9590](https://github.com/openai/openai-node/commit/edf95904294cce6cdcac521ee75dc8e0a033df4c))\n* **api:** api update ([6a2eb80](https://github.com/openai/openai-node/commit/6a2eb80f53c21f52ff217faef9b783e1cf9846c1))\n* **api:** api updates ([19ca100](https://github.com/openai/openai-node/commit/19ca100e9ebb2d03983da923c4bf944aa23c1f00))\n\n\n### Bug Fixes\n\n* **api:** mark assistants as deprecated ([3ae2a14](https://github.com/openai/openai-node/commit/3ae2a1439bc30d83c81e30ab30ddd06f91fee61f))\n\n\n### Chores\n\n* **ci:** upgrade `actions/github-script` ([4ea73d3](https://github.com/openai/openai-node/commit/4ea73d389b1b96d88c4c37c1a3a08ea143317c08))\n* **internal:** update `actions/checkout` version ([f163b77](https://github.com/openai/openai-node/commit/f163b77bf2bb127f8049a0a7b1a2795c4f2bae50))\n* **internal:** upgrade babel, qs, js-yaml ([2e2f3c6](https://github.com/openai/openai-node/commit/2e2f3c66ed61c0666e19831b123ea13d42978112))\n\n## 6.16.0 (2026-01-09)\n\nFull Changelog: [v6.15.0...v6.16.0](https://github.com/openai/openai-node/compare/v6.15.0...v6.16.0)\n\n### Features\n\n* **api:** add new Response completed_at prop ([ca40534](https://github.com/openai/openai-node/commit/ca40534778311def52bc7dbbab043d925cdaf847))\n* **ci:** add breaking change detection workflow ([a6f3dea](https://github.com/openai/openai-node/commit/a6f3deaf89ea0ef85cc57e1150032bb6b807c3b9))\n\n\n### Chores\n\n* break long lines in snippets into multiline ([80dee2f](https://github.com/openai/openai-node/commit/80dee2fe64d1b13f181bd482b31eb06fd6c5f3f4))\n* **internal:** codegen related update ([b2fac3e](https://github.com/openai/openai-node/commit/b2fac3ecdc3aecc3303c26304c4c94deda061edb))\n\n## 6.15.0 (2025-12-19)\n\nFull Changelog: [v6.14.0...v6.15.0](https://github.com/openai/openai-node/compare/v6.14.0...v6.15.0)\n\n### Bug Fixes\n\n* rebuild ([5627b41](https://github.com/openai/openai-node/commit/5627b4181775981e48991ea246e091afdfdc3caf))\n\n## 6.14.0 (2025-12-16)\n\nFull Changelog: [v6.13.0...v6.14.0](https://github.com/openai/openai-node/compare/v6.13.0...v6.14.0)\n\n### Features\n\n* **api:** gpt-image-1.5 ([6c1ac1d](https://github.com/openai/openai-node/commit/6c1ac1d8a2947c59f38aabaf07795a244c45a688))\n\n## 6.13.0 (2025-12-15)\n\nFull Changelog: [v6.12.0...v6.13.0](https://github.com/openai/openai-node/compare/v6.12.0...v6.13.0)\n\n### Features\n\n* **api:** api update ([bc759dc](https://github.com/openai/openai-node/commit/bc759dc39518412b58b2ebf7e57758776971ce15))\n* **api:** fix grader input list, add dated slugs for sora-2 ([6b2a38f](https://github.com/openai/openai-node/commit/6b2a38fb040eb45535818fb0157ae55949033dc1))\n\n## 6.12.0 (2025-12-11)\n\nFull Changelog: [v6.11.0...v6.12.0](https://github.com/openai/openai-node/compare/v6.11.0...v6.12.0)\n\n### Features\n\n* **api:** gpt 5.2 ([7000ddb](https://github.com/openai/openai-node/commit/7000ddb09ad4e272f43fe0d70cb1f6e5ca9ff725))\n\n## 6.11.0 (2025-12-10)\n\nFull Changelog: [v6.10.0...v6.11.0](https://github.com/openai/openai-node/compare/v6.10.0...v6.11.0)\n\n### Features\n\n* **api:** make model required for the responses/compact endpoint ([0b52b12](https://github.com/openai/openai-node/commit/0b52b12e535b07ef3b1213892ccb50dc4030ecf4))\n\n\n### Bug Fixes\n\n* **mcp:** correct code tool API endpoint ([e3f2a33](https://github.com/openai/openai-node/commit/e3f2a33bc7ae941d0870e7bc0a333951e88925e2))\n* **mcp:** return correct lines on typescript errors ([f485c3c](https://github.com/openai/openai-node/commit/f485c3c36ebb3cb9c2dbff676872a5470d1a9e47))\n\n\n### Chores\n\n* **internal:** codegen related update ([5af1c38](https://github.com/openai/openai-node/commit/5af1c38043118fd8e6f0fd072243bc63660963e4))\n* **internal:** codegen related update ([e43a8d9](https://github.com/openai/openai-node/commit/e43a8d97fd3e9be7c6ae0ebaf6e85d68dbb33432))\n\n## 6.10.0 (2025-12-04)\n\nFull Changelog: [v6.9.1...v6.10.0](https://github.com/openai/openai-node/compare/v6.9.1...v6.10.0)\n\n### Features\n\n* **api:** gpt-5.1-codex-max and responses/compact ([935f79e](https://github.com/openai/openai-node/commit/935f79efbb090d1d6016ac6874456594f5fd4553))\n\n\n### Chores\n\n* **client:** fix logger property type ([fdc671f](https://github.com/openai/openai-node/commit/fdc671f1b21249a8610b38e2535910d956dc3611))\n* **internal:** upgrade eslint ([9de0f90](https://github.com/openai/openai-node/commit/9de0f905bbd965a5d945ddb70c66dc0c6403ed35))\n\n## 6.9.1 (2025-11-17)\n\nFull Changelog: [v6.9.0...v6.9.1](https://github.com/openai/openai-node/compare/v6.9.0...v6.9.1)\n\n### Bug Fixes\n\n* **api:** align types of input items / output items for typescript ([99adaa7](https://github.com/openai/openai-node/commit/99adaa70dc31d07d5c7fa4d67194ac4de375c98f))\n\n## 6.9.0 (2025-11-13)\n\nFull Changelog: [v6.8.1...v6.9.0](https://github.com/openai/openai-node/compare/v6.8.1...v6.9.0)\n\n### Features\n\n* **api:** gpt 5.1 ([58e78a8](https://github.com/openai/openai-node/commit/58e78a86899b43eb9afdb6f0afd60b912eae41f2))\n\n\n### Chores\n\n* add typescript-estree dependency for jsr readme script ([3759514](https://github.com/openai/openai-node/commit/37595149720edd7bf4c11760084cad7753c2f289))\n\n## 6.8.1 (2025-11-05)\n\nFull Changelog: [v6.8.0...v6.8.1](https://github.com/openai/openai-node/compare/v6.8.0...v6.8.1)\n\n### Bug Fixes\n\n* **api:** fix nullability of logprobs ([40a403c](https://github.com/openai/openai-node/commit/40a403cc9a35b11cc665ccde19f9c5ef07247585))\n\n## 6.8.0 (2025-11-03)\n\nFull Changelog: [v6.7.0...v6.8.0](https://github.com/openai/openai-node/compare/v6.7.0...v6.8.0)\n\n### Features\n\n* **api:** Realtime API token_limits, Hybrid searching ranking options ([6a5b48c](https://github.com/openai/openai-node/commit/6a5b48c9c8961bc7409c20546d9d845a4f2674ce))\n* **api:** remove InputAudio from ResponseInputContent ([9909fef](https://github.com/openai/openai-node/commit/9909fef596280fc16174679d97c3e81543c68646))\n\n\n### Chores\n\n* **internal:** codegen related update ([3ad52aa](https://github.com/openai/openai-node/commit/3ad52aaa94cdbe1926fee1e5f8eacebefdfc399d))\n\n## 6.7.0 (2025-10-24)\n\nFull Changelog: [v6.6.0...v6.7.0](https://github.com/openai/openai-node/compare/v6.6.0...v6.7.0)\n\n### Features\n\n* add support for zod@4 schemas ([#1666](https://github.com/openai/openai-node/issues/1666)) ([10ef7ff](https://github.com/openai/openai-node/commit/10ef7ff4cb4aefeaa831b239943118ff52872f5c))\n\n\n### Bug Fixes\n\n* **api:** docs updates ([2591c21](https://github.com/openai/openai-node/commit/2591c211bce29d078579445d9a3b45d8de453ec3))\n\n## 6.6.0 (2025-10-20)\n\nFull Changelog: [v6.5.0...v6.6.0](https://github.com/openai/openai-node/compare/v6.5.0...v6.6.0)\n\n### Features\n\n* **api:** Add responses.input_tokens.count ([520c8a9](https://github.com/openai/openai-node/commit/520c8a95c857307b9329c4725cb40707d4e3eeee))\n\n\n### Bug Fixes\n\n* **api:** internal openapi updates ([d4aaef9](https://github.com/openai/openai-node/commit/d4aaef9c2e3d9f00b33d59e569149a937e5bd3f5))\n\n## 6.5.0 (2025-10-17)\n\nFull Changelog: [v6.4.0...v6.5.0](https://github.com/openai/openai-node/compare/v6.4.0...v6.5.0)\n\n### Features\n\n* **api:** api update ([4d21af3](https://github.com/openai/openai-node/commit/4d21af3e6a04baa0ea42d360cf3601fcc3d39705))\n\n## 6.4.0 (2025-10-16)\n\nFull Changelog: [v6.3.0...v6.4.0](https://github.com/openai/openai-node/compare/v6.3.0...v6.4.0)\n\n### Features\n\n* **api:** Add support for gpt-4o-transcribe-diarize on audio/transcriptions endpoint ([2d27392](https://github.com/openai/openai-node/commit/2d27392ac1cd082f7defb730326d11d8e733353f))\n\n## 6.3.0 (2025-10-10)\n\nFull Changelog: [v6.2.0...v6.3.0](https://github.com/openai/openai-node/compare/v6.2.0...v6.3.0)\n\n### Features\n\n* **api:** comparison filter in/not in ([1a733c6](https://github.com/openai/openai-node/commit/1a733c69ffff094568707b3f615d110c7e2edd6e))\n\n\n### Chores\n\n* **internal:** use npm pack for build uploads ([a532410](https://github.com/openai/openai-node/commit/a53241032e1177a390337986399da57e39be25ec))\n\n## 6.2.0 (2025-10-06)\n\nFull Changelog: [v6.1.0...v6.2.0](https://github.com/openai/openai-node/compare/v6.1.0...v6.2.0)\n\n### Features\n\n* **api:** dev day 2025 launches ([f2816db](https://github.com/openai/openai-node/commit/f2816dbc6ae162d39017e7bafb0d23d0b51dd585))\n\n\n### Chores\n\n* **internal:** codegen related update ([b6f64b7](https://github.com/openai/openai-node/commit/b6f64b70ea681b174695d930f957aa49194553ed))\n* **jsdoc:** fix [@link](https://github.com/link) annotations to refer only to parts of the package‘s public interface ([73e465d](https://github.com/openai/openai-node/commit/73e465d382a45389ab47a0a92575e4415e8d3276))\n\n## 6.1.0 (2025-10-02)\n\nFull Changelog: [v6.0.1...v6.1.0](https://github.com/openai/openai-node/compare/v6.0.1...v6.1.0)\n\n### Features\n\n* **api:** add support for realtime calls ([5de9585](https://github.com/openai/openai-node/commit/5de958556679182dfbdce95b4db6b65ca742aa61))\n\n## 6.0.1 (2025-10-01)\n\nFull Changelog: [v6.0.0...v6.0.1](https://github.com/openai/openai-node/compare/v6.0.0...v6.0.1)\n\n### Bug Fixes\n\n* **api:** add status, approval_request_id to MCP tool call ([498c6a5](https://github.com/openai/openai-node/commit/498c6a5d4cab7ad10e31acd01cb49915a70e576a))\n\n## 6.0.0 (2025-09-30)\n\nFull Changelog: [v5.23.2...v6.0.0](https://github.com/openai/openai-node/compare/v5.23.2...v6.0.0)\n\n### ⚠ BREAKING CHANGES\n\n* **api:** `ResponseFunctionToolCallOutputItem.output` and `ResponseCustomToolCallOutput.output` now return `string | Array<ResponseInputText | ResponseInputImage | ResponseInputFile>` instead of `string` only. This may break existing callsites that assume `output` is always a string.\n\n### Features\n\n* **api:** Support images and files for function call outputs in responses, BatchUsage ([abe56f8](https://github.com/openai/openai-node/commit/abe56f86afdf28fc1a1b410ace1dd422672361a7))\n\n\n### Chores\n\n* compat with zod v4 ([#1658](https://github.com/openai/openai-node/issues/1658)) ([94569a0](https://github.com/openai/openai-node/commit/94569a07ce55317b0166e742b90a463df0f70e56))\n\n## 5.23.2 (2025-09-29)\n\nFull Changelog: [v5.23.1...v5.23.2](https://github.com/openai/openai-node/compare/v5.23.1...v5.23.2)\n\n### Chores\n\n* **env-tests:** upgrade jest-fixed-jsdom 0.0.9 -&gt; 0.0.10 ([6d6d0b0](https://github.com/openai/openai-node/commit/6d6d0b0eaaff86a99141af031f55b7cc6a22772a))\n* **internal:** codegen related update ([1b684af](https://github.com/openai/openai-node/commit/1b684afd387ccd7b16d226dca3adee92db6e4878))\n* **internal:** ignore .eslintcache ([da9e146](https://github.com/openai/openai-node/commit/da9e1468d62aa9044ee9d236b419f744f8792bdb))\n\n## 5.23.1 (2025-09-26)\n\nFull Changelog: [v5.23.0...v5.23.1](https://github.com/openai/openai-node/compare/v5.23.0...v5.23.1)\n\n### Bug Fixes\n\n* **realtime:** remove beta header from GA classes ([a5e9e70](https://github.com/openai/openai-node/commit/a5e9e70af8691f2850ad7ccfec966e5fb0d5b56d))\n\n\n### Performance Improvements\n\n* faster formatting ([d56f309](https://github.com/openai/openai-node/commit/d56f309f359f7f4d87c95bfaaffdc463312850e4))\n\n\n### Chores\n\n* **internal:** fix incremental formatting in some cases ([166d28f](https://github.com/openai/openai-node/commit/166d28ff34edb6b1c3ef310bc825952dcb30ba4b))\n* **internal:** remove deprecated `compilerOptions.baseUrl` from tsconfig.json ([dfab408](https://github.com/openai/openai-node/commit/dfab40857547b272cdad4309baf84e43a07775ed))\n\n## 5.23.0 (2025-09-23)\n\nFull Changelog: [v5.22.1...v5.23.0](https://github.com/openai/openai-node/compare/v5.22.1...v5.23.0)\n\n### Features\n\n* **api:** gpt-5-codex ([2e4ece6](https://github.com/openai/openai-node/commit/2e4ece6a01e1b7c4c69627137900b7f70558a85b))\n\n## 5.22.1 (2025-09-22)\n\nFull Changelog: [v5.22.0...v5.22.1](https://github.com/openai/openai-node/compare/v5.22.0...v5.22.1)\n\n### Bug Fixes\n\n* **api:** fix mcp tool name ([fa9f305](https://github.com/openai/openai-node/commit/fa9f3055c63f83ddc19085ebeb7ac38cb303673a))\n\n\n### Chores\n\n* **api:** openapi updates for conversations ([975c075](https://github.com/openai/openai-node/commit/975c0757da3474439d166a27d61ba6606d439bb0))\n* do not install brew dependencies in ./scripts/bootstrap by default ([6f5e45f](https://github.com/openai/openai-node/commit/6f5e45fc8a0c2dee1f68d00b135034653ed23200))\n* improve example values ([b336a64](https://github.com/openai/openai-node/commit/b336a642fd9507bf28e0ed8976ec102d796f9b9d))\n\n## 5.22.0 (2025-09-19)\n\nFull Changelog: [v5.21.0...v5.22.0](https://github.com/openai/openai-node/compare/v5.21.0...v5.22.0)\n\n### Features\n\n* **api:** add reasoning_text ([7ff6186](https://github.com/openai/openai-node/commit/7ff61860a14ae20d0734b4f592002dfe67330488))\n\n\n### Chores\n\n* **api:** manual fixes for streaming ([3a2ae4c](https://github.com/openai/openai-node/commit/3a2ae4ce2a0796f5201dd9373f103bd94689b733))\n\n## 5.21.0 (2025-09-17)\n\nFull Changelog: [v5.20.3...v5.21.0](https://github.com/openai/openai-node/compare/v5.20.3...v5.21.0)\n\n### Features\n\n* **api:** type updates for conversations, reasoning_effort and results for evals ([f243f54](https://github.com/openai/openai-node/commit/f243f54072d00cb8d83b8c6093accaaabf34d4cf))\n\n## 5.20.3 (2025-09-15)\n\nFull Changelog: [v5.20.2...v5.20.3](https://github.com/openai/openai-node/compare/v5.20.2...v5.20.3)\n\n### Chores\n\n* **api:** docs and spec refactoring ([05b4498](https://github.com/openai/openai-node/commit/05b44987c699f7683b8706c8de363165150e5f31))\n\n## 5.20.2 (2025-09-12)\n\nFull Changelog: [v5.20.1...v5.20.2](https://github.com/openai/openai-node/compare/v5.20.1...v5.20.2)\n\n### Bug Fixes\n\n* coerce nullable values to undefined ([836d1b4](https://github.com/openai/openai-node/commit/836d1b4cdd077c206e1c647c762f4c16e9db444c))\n\n\n### Chores\n\n* **api:** Minor docs and type updates for realtime ([ccb00dc](https://github.com/openai/openai-node/commit/ccb00dcbd1466976045aafee152cbc038bb293b9))\n\n## 5.20.1 (2025-09-10)\n\nFull Changelog: [v5.20.0...v5.20.1](https://github.com/openai/openai-node/compare/v5.20.0...v5.20.1)\n\n### Chores\n\n* **api:** fix realtime GA types ([1c0d314](https://github.com/openai/openai-node/commit/1c0d3145e920a55f3c710323849bcac1fd60b703))\n\n## 5.20.0 (2025-09-08)\n\nFull Changelog: [v5.19.1...v5.20.0](https://github.com/openai/openai-node/compare/v5.19.1...v5.20.0)\n\n### Features\n\n* **api:** ship the RealtimeGA API shape ([4286ddd](https://github.com/openai/openai-node/commit/4286ddd4f990dd26e15e510039457f17d787820d))\n\n\n### Chores\n\n* ci build action ([c8ce143](https://github.com/openai/openai-node/commit/c8ce143196fdbc7ee1c7832bce2417b6e3d25885))\n\n## 5.19.1 (2025-09-03)\n\nFull Changelog: [v5.19.0...v5.19.1](https://github.com/openai/openai-node/compare/v5.19.0...v5.19.1)\n\n### Bug Fixes\n\n* **azure:** correctly send API key ([#1635](https://github.com/openai/openai-node/issues/1635)) ([08f6178](https://github.com/openai/openai-node/commit/08f6178ff0d4ccc6b80462c86a36f11eb3bfd5fe))\n\n## 5.19.0 (2025-09-03)\n\nFull Changelog: [v5.18.1...v5.19.0](https://github.com/openai/openai-node/compare/v5.18.1...v5.19.0)\n\n### Features\n\n* **api:** Add gpt-realtime models ([256d932](https://github.com/openai/openai-node/commit/256d93247da7f31e34f5f80d8added0bc6f52fe9))\n\n## 5.18.1 (2025-09-02)\n\nFull Changelog: [v5.18.0...v5.18.1](https://github.com/openai/openai-node/compare/v5.18.0...v5.18.1)\n\n### Chores\n\n* **api:** manual updates for ResponseInputAudio ([570501b](https://github.com/openai/openai-node/commit/570501b8c66f3f23d0dca05bc948339623732a8e))\n\n## 5.18.0 (2025-09-02)\n\nFull Changelog: [v5.17.0...v5.18.0](https://github.com/openai/openai-node/compare/v5.17.0...v5.18.0)\n\n### Features\n\n* **client:** support api key provider functions ([#1587](https://github.com/openai/openai-node/issues/1587)) ([c3a92c7](https://github.com/openai/openai-node/commit/c3a92c7ee6f5f7c26c9297be04343326c9854bfd))\n\n\n### Bug Fixes\n\n* update non beta realtime websockets helpers ([265a42f](https://github.com/openai/openai-node/commit/265a42f9101b0479b7d8dcbf05d45ce29539a7f3))\n\n## 5.17.0 (2025-09-02)\n\nFull Changelog: [v5.16.0...v5.17.0](https://github.com/openai/openai-node/compare/v5.16.0...v5.17.0)\n\n### Features\n\n* **api:** realtime API updates ([e817255](https://github.com/openai/openai-node/commit/e817255e6ff9e3ad6bd08b001644c335e0459537))\n\n\n### Chores\n\n* **internal:** update global Error reference ([e566ff3](https://github.com/openai/openai-node/commit/e566ff321642a100756224b75a67d44e262e5bea))\n\n## 5.16.0 (2025-08-26)\n\nFull Changelog: [v5.15.0...v5.16.0](https://github.com/openai/openai-node/compare/v5.15.0...v5.16.0)\n\n### Features\n\n* **api:** add web search filters ([975b141](https://github.com/openai/openai-node/commit/975b1417052bdcc0111f546ce3fbbea2e71414af))\n\n\n### Chores\n\n* **client:** qualify global Blob ([7998d3f](https://github.com/openai/openai-node/commit/7998d3fd3715ab2c06ea011155420ac126681649))\n* update CI script ([accb0c1](https://github.com/openai/openai-node/commit/accb0c1188dbaef20c1a40bd3047087960c99a07))\n\n## 5.15.0 (2025-08-21)\n\nFull Changelog: [v5.14.0...v5.15.0](https://github.com/openai/openai-node/compare/v5.14.0...v5.15.0)\n\n### Features\n\n* **api:** Add connectors support for MCP tool ([048bee3](https://github.com/openai/openai-node/commit/048bee3693822c75181012c47b4f54074e1efdd6))\n* **api:** adding support for /v1/conversations to the API ([1380d17](https://github.com/openai/openai-node/commit/1380d1734b1e7eeb5d10fb73fe9cfce6199e5c8e))\n\n\n### Chores\n\n* add package to package.json ([6748b2b](https://github.com/openai/openai-node/commit/6748b2b64f6c06ee324694b95ae7df99493ff08d))\n\n## 5.14.0 (2025-08-20)\n\nFull Changelog: [v5.13.1...v5.14.0](https://github.com/openai/openai-node/compare/v5.13.1...v5.14.0)\n\n### Features\n\n* **mcp:** add code execution tool ([3f8264c](https://github.com/openai/openai-node/commit/3f8264cfaafb8d03aedabe53a0d17a7e3dc326d8))\n\n\n### Chores\n\n* **internal/ci:** setup breaking change detection ([87e8004](https://github.com/openai/openai-node/commit/87e8004d05eb27d14a11d433239af525c9c493b9))\n\n## 5.13.1 (2025-08-19)\n\nFull Changelog: [v5.13.0...v5.13.1](https://github.com/openai/openai-node/compare/v5.13.0...v5.13.1)\n\n### Chores\n\n* **api:** accurately represent shape for verbosity on Chat Completions ([5ddac3c](https://github.com/openai/openai-node/commit/5ddac3c7535e2df4b562fe1237b639e112bf5eef))\n\n## 5.13.0 (2025-08-18)\n\nFull Changelog: [v5.12.3...v5.13.0](https://github.com/openai/openai-node/compare/v5.12.3...v5.13.0)\n\n### Features\n\n* **api:** add new text parameters, expiration options ([499179c](https://github.com/openai/openai-node/commit/499179c095eae77dcccec5e2758ab72c8d829ea7))\n\n\n### Chores\n\n* **deps:** update dependency @types/node to v20.17.58 ([7812d0d](https://github.com/openai/openai-node/commit/7812d0db43309144cb46714a64fe97a3e12f5b04))\n* **internal:** formatting change ([56b2073](https://github.com/openai/openai-node/commit/56b2073ac3553d6b9cca1185fe52a7e697d0b733))\n\n## 5.12.3 (2025-08-12)\n\nFull Changelog: [v5.12.2...v5.12.3](https://github.com/openai/openai-node/compare/v5.12.2...v5.12.3)\n\n### Chores\n\n* **internal:** update comment in script ([2488faf](https://github.com/openai/openai-node/commit/2488faf387da1c9bd7565d4bb5aded7bb53b8799))\n* update @stainless-api/prism-cli to v5.15.0 ([db44a7d](https://github.com/openai/openai-node/commit/db44a7d2afa4e0330f4981c106f9abf2fd4ab432))\n\n## 5.12.2 (2025-08-08)\n\nFull Changelog: [v5.12.1...v5.12.2](https://github.com/openai/openai-node/compare/v5.12.1...v5.12.2)\n\n### Bug Fixes\n\n* **client:** fix verbosity parameter location in Responses ([eaa246f](https://github.com/openai/openai-node/commit/eaa246ffe00ffcdec45c695a96aeed3d87bb3f74))\n\n## 5.12.1 (2025-08-07)\n\nFull Changelog: [v5.12.0...v5.12.1](https://github.com/openai/openai-node/compare/v5.12.0...v5.12.1)\n\n### Features\n\n* **api:** adds GPT-5 and new API features: platform.openai.com/docs/guides/gpt-5 ([59acd85](https://github.com/openai/openai-node/commit/59acd85a3e0d4db7f7eca9a287b23ec00191fa68))\n\n\n### Chores\n\n* **internal:** move publish config ([b3d02f6](https://github.com/openai/openai-node/commit/b3d02f6faab5aa8e62998446485e43ebc802d68e))\n\n## 5.12.0 (2025-08-05)\n\nFull Changelog: [v5.11.0...v5.12.0](https://github.com/openai/openai-node/compare/v5.11.0...v5.12.0)\n\n### Features\n\n* **api:** manual updates ([f0d3056](https://github.com/openai/openai-node/commit/f0d3056932adb8e448fd1141eae4b07ad0c66ddb))\n\n## 5.11.0 (2025-07-30)\n\nFull Changelog: [v5.10.3...v5.11.0](https://github.com/openai/openai-node/compare/v5.10.3...v5.11.0)\n\n### Features\n\n* **api:** manual updates ([442dc25](https://github.com/openai/openai-node/commit/442dc25d7b31a374daf440f32f5694c3b6c20a81))\n\n## 5.10.3 (2025-07-30)\n\nFull Changelog: [v5.10.2...v5.10.3](https://github.com/openai/openai-node/compare/v5.10.2...v5.10.3)\n\n### Bug Fixes\n\n* **zod:** avoid adding redundant not to optional schemas [#1593](https://github.com/openai/openai-node/issues/1593) ([162b697](https://github.com/openai/openai-node/commit/162b697d1b946dc4af213c8efcdb7a7b5317bb6e))\n\n\n### Chores\n\n* **client:** refactor streaming slightly to better future proof it ([292427f](https://github.com/openai/openai-node/commit/292427f7f39f6dd64e46ba4360b0b96c8e49adc9))\n* **internal:** remove redundant imports config ([28dd66d](https://github.com/openai/openai-node/commit/28dd66de15032d6ee620d3cf9f3e33ba61cad4e7))\n* **internal:** version bump ([56e0760](https://github.com/openai/openai-node/commit/56e076090a9ce5c6b7f4ac4d84d33ca3f6522973))\n\n## 5.10.2 (2025-07-22)\n\nFull Changelog: [v5.10.1...v5.10.2](https://github.com/openai/openai-node/compare/v5.10.1...v5.10.2)\n\n### Chores\n\n* **api:** event shapes more accurate ([78f4e1d](https://github.com/openai/openai-node/commit/78f4e1d8e7400001a7bc6a05dc9a6e52a2047523))\n* **internal:** version bump ([ea885ca](https://github.com/openai/openai-node/commit/ea885cac5c4231597141e91bd454e540830deb95))\n\n\n### Documentation\n\n* fix typos in helpers and realtime ([#1592](https://github.com/openai/openai-node/issues/1592)) ([17733b7](https://github.com/openai/openai-node/commit/17733b7e4a19754c9ca2ec815cf7d246b1dc138d))\n\n## 5.10.1 (2025-07-16)\n\nFull Changelog: [v5.10.0...v5.10.1](https://github.com/openai/openai-node/compare/v5.10.0...v5.10.1)\n\n### Chores\n\n* **internal:** version bump ([896b418](https://github.com/openai/openai-node/commit/896b41828ce468fed36ceb50082633e21a0945ca))\n* **ts:** reorder package.json imports ([2f8d2f7](https://github.com/openai/openai-node/commit/2f8d2f7726dbc717c3c6e2a27dbd5b50ff9ef4b4))\n\n## 5.10.0 (2025-07-16)\n\nFull Changelog: [v5.9.2...v5.10.0](https://github.com/openai/openai-node/compare/v5.9.2...v5.10.0)\n\n### Features\n\n* **api:** manual updates ([35338b4](https://github.com/openai/openai-node/commit/35338b44ace44f0f0c0b48ea94aa96d3c81ea385))\n\n\n### Chores\n\n* **internal:** version bump ([3d9de4b](https://github.com/openai/openai-node/commit/3d9de4b2f28c80ea1f92446c092b23d69955ef30))\n\n## 5.9.2 (2025-07-15)\n\nFull Changelog: [v5.9.1...v5.9.2](https://github.com/openai/openai-node/compare/v5.9.1...v5.9.2)\n\n### Chores\n\n* **api:** update realtime specs ([4a20a3d](https://github.com/openai/openai-node/commit/4a20a3da8319667540a7b120f0f94e253420058e))\n* **internal:** version bump ([103e8de](https://github.com/openai/openai-node/commit/103e8def71408724fb37104cfcb9419e01022f24))\n\n## 5.9.1 (2025-07-15)\n\nFull Changelog: [v5.9.0...v5.9.1](https://github.com/openai/openai-node/compare/v5.9.0...v5.9.1)\n\n### Chores\n\n* **api:** update realtime specs, build config ([bb4649f](https://github.com/openai/openai-node/commit/bb4649feb69a6d91e4eea857fd6f5e8c00f2a35d))\n\n## 5.9.0 (2025-07-10)\n\nFull Changelog: [v5.8.4...v5.9.0](https://github.com/openai/openai-node/compare/v5.8.4...v5.9.0)\n\n### Features\n\n* **api:** add file_url, fix event ID ([5f5d39e](https://github.com/openai/openai-node/commit/5f5d39e9e11224bf18a0301041b69548727ed4f3))\n\n## 5.8.4 (2025-07-10)\n\nFull Changelog: [v5.8.3...v5.8.4](https://github.com/openai/openai-node/compare/v5.8.3...v5.8.4)\n\n### Chores\n\n* **internal:** bump undici version in tests ([6f38b80](https://github.com/openai/openai-node/commit/6f38b809a69b6ab3fcbf1235e57bdb8912024ab3))\n* make some internal functions async ([841940d](https://github.com/openai/openai-node/commit/841940d2ae036191b456e8398fbcb1f24c6e4deb))\n\n## 5.8.3 (2025-07-08)\n\nFull Changelog: [v5.8.2...v5.8.3](https://github.com/openai/openai-node/compare/v5.8.2...v5.8.3)\n\n### Bug Fixes\n\n* avoid console usage ([aec57c5](https://github.com/openai/openai-node/commit/aec57c5902b47d2d643f48d98a6014e0e77ba6cc))\n\n\n### Chores\n\n* add docs to RequestOptions type ([3735172](https://github.com/openai/openai-node/commit/37351723bc5a24c06a96c95e11104cda42a1bec3))\n* **ci:** only run for pushes and fork pull requests ([e200bc4](https://github.com/openai/openai-node/commit/e200bc4db18a09d4148fff0056801140411bfa53))\n* **client:** improve path param validation ([b5a043b](https://github.com/openai/openai-node/commit/b5a043bc96b6b6bfe8cca05e103a6e4d6fea962b))\n* **internal/tests:** pin bun types version ([fcffa88](https://github.com/openai/openai-node/commit/fcffa880c1b31aeca70a6fa093f4b1f9d3db1a74))\n\n## 5.8.2 (2025-06-27)\n\nFull Changelog: [v5.8.1...v5.8.2](https://github.com/openai/openai-node/compare/v5.8.1...v5.8.2)\n\n### Bug Fixes\n\n* **client:** get fetchOptions type more reliably ([b3c959d](https://github.com/openai/openai-node/commit/b3c959d22d1002a85772385476f9a5098c8e1514))\n\n## 5.8.1 (2025-06-26)\n\nFull Changelog: [v5.8.0...v5.8.1](https://github.com/openai/openai-node/compare/v5.8.0...v5.8.1)\n\n### Bug Fixes\n\n* **client:** ensure addOutputText is called on responses.retrieve ([d55bb64](https://github.com/openai/openai-node/commit/d55bb64f8022c1e861b4b4d1c23ad4cc0e80e536))\n\n\n### Chores\n\n* **api:** remove unsupported property ([1966954](https://github.com/openai/openai-node/commit/19669545157dc0339f4c88855bd1ae9acaaac53d))\n* **docs:** update README to include links to docs on Webhooks ([586d5da](https://github.com/openai/openai-node/commit/586d5daf5babc9f12793201f1e1e4c79829151f0))\n* **webhooks:** make private methods really private ([0ee396a](https://github.com/openai/openai-node/commit/0ee396a2a0e03c794c7cfa3c9f1beb848fd77f1d))\n\n## 5.8.0 (2025-06-26)\n\nFull Changelog: [v5.7.0...v5.8.0](https://github.com/openai/openai-node/compare/v5.7.0...v5.8.0)\n\n### Features\n\n* **api:** webhook and deep research support ([f2b4f66](https://github.com/openai/openai-node/commit/f2b4f66226ad514d702f8acbb4820ae90b4fd40e))\n\n\n### Bug Fixes\n\n* **ci:** release-doctor — report correct token name ([aed2587](https://github.com/openai/openai-node/commit/aed2587294922415aeaece0b9a6911c3e1577c51))\n\n\n### Refactors\n\n* **types:** replace Record with mapped types ([7865910](https://github.com/openai/openai-node/commit/7865910c7d66a14dac70ea119e109975d9169414))\n\n## 5.7.0 (2025-06-23)\n\nFull Changelog: [v5.6.0...v5.7.0](https://github.com/openai/openai-node/compare/v5.6.0...v5.7.0)\n\n### Features\n\n* **api:** update api shapes for usage and code interpreter ([f2100e8](https://github.com/openai/openai-node/commit/f2100e89334753e7f580f7f20f48b43eb8ba2fe3))\n\n## 5.6.0 (2025-06-20)\n\nFull Changelog: [v5.5.1...v5.6.0](https://github.com/openai/openai-node/compare/v5.5.1...v5.6.0)\n\n### Features\n\n* **api:** make model and inputs not required to create response ([52211c0](https://github.com/openai/openai-node/commit/52211c0e67c2926b27f4adee1f626066d90b6a2e))\n\n\n### Bug Fixes\n\n* **client:** explicitly copy fetch in withOptions ([0efacae](https://github.com/openai/openai-node/commit/0efacaeb8eb0bfbad6bd6bc29fc57f00916411c0))\n\n\n### Chores\n\n* **readme:** update badges ([6898954](https://github.com/openai/openai-node/commit/689895400adf38e85810ba8b63dc16ed56839ddd))\n* **readme:** use better example snippet for undocumented params ([668611f](https://github.com/openai/openai-node/commit/668611f4331ffa375257f3bc138c54d6ee965cd6))\n\n## 5.5.1 (2025-06-17)\n\nFull Changelog: [v5.5.0...v5.5.1](https://github.com/openai/openai-node/compare/v5.5.0...v5.5.1)\n\n### Chores\n\n* **ci:** enable for pull requests ([e1cf00c](https://github.com/openai/openai-node/commit/e1cf00cf2a2ce832d759f3253f10826d3c16338e))\n\n## 5.5.0 (2025-06-16)\n\nFull Changelog: [v5.4.0...v5.5.0](https://github.com/openai/openai-node/compare/v5.4.0...v5.5.0)\n\n### Features\n\n* **api:** manual updates ([ab6b57c](https://github.com/openai/openai-node/commit/ab6b57c241dc7c57e411fae572842da801e9828b))\n\n## 5.4.0 (2025-06-16)\n\nFull Changelog: [v5.3.0...v5.4.0](https://github.com/openai/openai-node/compare/v5.3.0...v5.4.0)\n\n### Features\n\n* **api:** add reusable prompt IDs ([c720bb3](https://github.com/openai/openai-node/commit/c720bb3fb909cdef1cc679df38357f046d3d2756))\n* **client:** add support for endpoint-specific base URLs ([05f558b](https://github.com/openai/openai-node/commit/05f558bcdd362ae56000fe515a24593363d59e83))\n\n\n### Bug Fixes\n\n* publish script — handle NPM errors correctly ([a803cce](https://github.com/openai/openai-node/commit/a803cce6d44116eaba34f2bd7cb0f5d8f5c72be8))\n\n\n### Chores\n\n* **client:** refactor imports ([9eb4470](https://github.com/openai/openai-node/commit/9eb44703432d7e22290564013f8e1798c82918a3))\n* **internal:** add pure annotations, make base APIResource abstract ([418eb02](https://github.com/openai/openai-node/commit/418eb02e3ebe3ef58d851405f9eb5cae275194b4))\n\n## 5.3.0 (2025-06-10)\n\nFull Changelog: [v5.2.0...v5.3.0](https://github.com/openai/openai-node/compare/v5.2.0...v5.3.0)\n\n### Features\n\n* **api:** Add o3-pro model IDs ([9988f8e](https://github.com/openai/openai-node/commit/9988f8ea50a370abfc03bc97882d1ddd83837217))\n\n## 5.2.0 (2025-06-09)\n\nFull Changelog: [v5.1.1...v5.2.0](https://github.com/openai/openai-node/compare/v5.1.1...v5.2.0)\n\n### Features\n\n* **api:** Add tools and structured outputs to evals ([64844f1](https://github.com/openai/openai-node/commit/64844f1be2da9658a603fac304d1387f28a110a4))\n\n\n### Bug Fixes\n\n* **changelog:** remove duplicated entries ([18484cc](https://github.com/openai/openai-node/commit/18484cceea615a01b62590b9b626b9e2140c7dd9))\n\n\n### Chores\n\n* avoid type error in certain environments ([44ac3d9](https://github.com/openai/openai-node/commit/44ac3d96eb258cd777edb02004763ccef253ae7a))\n\n\n### Documentation\n\n* **changelog:** reference MIGRATION.md ([b3d488f](https://github.com/openai/openai-node/commit/b3d488feff5acb020f5db6f27ea94884c56bc767)), closes [#1539](https://github.com/openai/openai-node/issues/1539)\n\n## 5.1.1 (2025-06-05)\n\nFull Changelog: [v5.1.0...v5.1.1](https://github.com/openai/openai-node/compare/v5.1.0...v5.1.1)\n\n### Bug Fixes\n\n* **assistants:** handle thread.run.incomplete while streaming ([8f5e7f3](https://github.com/openai/openai-node/commit/8f5e7f3ffaad7bdd0424743eb68a63f918dbabb8))\n\n\n### Chores\n\n* **docs:** use top-level-await in example snippets ([065d3b0](https://github.com/openai/openai-node/commit/065d3b08b29e10d7af58bb66816245f71f386833))\n* **internal:** fix readablestream types in node 20 ([771ae81](https://github.com/openai/openai-node/commit/771ae818c32d855778c3847d9005efb80b0a8cd5))\n\n## 5.1.0 (2025-06-03)\n\nFull Changelog: [v5.0.2...v5.1.0](https://github.com/openai/openai-node/compare/v5.0.2...v5.1.0)\n\n### Features\n\n* **api:** add new realtime and audio models, realtime session options ([1219f09](https://github.com/openai/openai-node/commit/1219f090b02b8d53f29abf5a0e7564af0f9f68fc))\n\n\n### Chores\n\n* adjust eslint.config.mjs ignore pattern ([9b5c898](https://github.com/openai/openai-node/commit/9b5c898fe5099859252d3c3fd62010d6aa552fef))\n* **api:** update type names ([7c296d6](https://github.com/openai/openai-node/commit/7c296d62bbde52ec84e3af78ed12f1cd196f9d52))\n\n## 5.0.2 (2025-06-02)\n\nFull Changelog: [v5.0.1...v5.0.2](https://github.com/openai/openai-node/compare/v5.0.1...v5.0.2)\n\n### Bug Fixes\n\n* **api:** Fix evals and code interpreter interfaces ([992a9d8](https://github.com/openai/openai-node/commit/992a9d84fe412d96496b11b7a6be5c927f78db6c))\n\n\n### Chores\n\n* **deps:** bump eslint-plugin-prettier ([1428a8b](https://github.com/openai/openai-node/commit/1428a8b4f82e79695c2cbed5e12ca0da4958423b))\n* **internal:** codegen related update ([a65428f](https://github.com/openai/openai-node/commit/a65428fc81e05f681eab806e7efc6ad26062221b))\n\n## 5.0.1 (2025-05-29)\n\nFull Changelog: [v5.0.0...v5.0.1](https://github.com/openai/openai-node/compare/v5.0.0...v5.0.1)\n\n### Chores\n\n* sync changes ([90b100d](https://github.com/openai/openai-node/commit/90b100dcf504ecf0b98620702cb6bd0988695320))\n* **types:** add missing type annotation ([de37b55](https://github.com/openai/openai-node/commit/de37b55e6e95d7089ee845d4144883d93bb18ca0))\n\n## 5.0.0 (2025-05-29)\n\nThis release migrates from node-fetch to builtin fetch, for full release notes see [MIGRATION.md](https://github.com/openai/openai-node/blob/master/MIGRATION.md).\n\nFull Changelog: [v5.0.0-alpha.0...v5.0.0](https://github.com/openai/openai-node/compare/v5.0.0-alpha.0...v5.0.0)\n\n### Features\n\n* add audio helpers ([ec5067d](https://github.com/openai/openai-node/commit/ec5067deba1fe4202d90db42e45c3bd774936af1))\n* add migration guide ([cfd2088](https://github.com/openai/openai-node/commit/cfd2088219464381077dec62d38d1830ab0b43f3))\n* add SKIP_BREW env var to ./scripts/bootstrap ([7ea4a24](https://github.com/openai/openai-node/commit/7ea4a244d5b39e0745aea1a89abff940e2c3922f))\n* **api:** add /v1/responses and built-in tools ([91af47c](https://github.com/openai/openai-node/commit/91af47cc4f62b08a451bc39f44c64244a71c1f2c))\n* **api:** add `get /chat/completions` endpoint ([9697139](https://github.com/openai/openai-node/commit/9697139a5f38bcc2dffa3322ff575eb1fc8b4e35))\n* **api:** add `get /responses/{response_id}/input_items` endpoint ([f2c5aba](https://github.com/openai/openai-node/commit/f2c5aba736f99550a9a7837be22b39b36a7495d0))\n* **api:** add container endpoint ([3ffca5c](https://github.com/openai/openai-node/commit/3ffca5c5b2dc6819e955ed343b2bb6e2095e7bdf))\n* **api:** Add evalapi to sdk ([70092d7](https://github.com/openai/openai-node/commit/70092d768426b8e0dd4bca21e7a3dea009e25b9f))\n* **api:** add gpt-4.5-preview ([1d4478d](https://github.com/openai/openai-node/commit/1d4478d7935028e20a9d9d11ff29ff8b991c44f9))\n* **api:** add image sizes, reasoning encryption ([0c25021](https://github.com/openai/openai-node/commit/0c2502187f8895f029277a7be9825862f458e9aa))\n* **api:** add o3 and o4-mini model IDs ([19cda5d](https://github.com/openai/openai-node/commit/19cda5d3b908238ae6c6f5609ac3a118d4d8acc2))\n* **api:** Add reinforcement fine-tuning api support ([e6bbaf5](https://github.com/openai/openai-node/commit/e6bbaf577aa6bdf3bcdaf25a5a7d4e8202831c7a))\n* **api:** add support for storing chat completions ([59da177](https://github.com/openai/openai-node/commit/59da1771b93158d5d89efc9e63e1ef9c09a634f3))\n* **api:** adding gpt-4.1 family of model IDs ([8a2a745](https://github.com/openai/openai-node/commit/8a2a7454bee0fbe9e4729d47f6b894e5f25d68f5))\n* **api:** adding new image model support ([a0010fd](https://github.com/openai/openai-node/commit/a0010fdb60fe723ebc70103cceca552aca51855e))\n* **api:** Config update for pakrym-stream-param ([469ad7b](https://github.com/openai/openai-node/commit/469ad7b9d76b674aa3fd829128a54758ab7adfbd))\n* **api:** further updates for evals API ([3f6f248](https://github.com/openai/openai-node/commit/3f6f248191b45015924be76fd5154d149c4ed8a0))\n* **api:** manual updates ([debe529](https://github.com/openai/openai-node/commit/debe5295d077f79cc4b4eefefb008e5a10b32793))\n* **api:** manual updates ([e83286b](https://github.com/openai/openai-node/commit/e83286b10b20d3e4c02903739b045af5cbf71cde))\n* **api:** manual updates ([959eace](https://github.com/openai/openai-node/commit/959eace6ec132a83f731fa496d5b8b7a11fa6bb2))\n* **api:** manual updates ([179a607](https://github.com/openai/openai-node/commit/179a607a89fabda32ebad62cc7ee86b5332a29f4))\n* **api:** manual updates ([0cb0c86](https://github.com/openai/openai-node/commit/0cb0c863b3bda6e6d72b3b5cdba3c8791db9bb77))\n* **api:** manual updates ([678ae6b](https://github.com/openai/openai-node/commit/678ae6b7112ed9b27d092b3234dd034d572deb9c))\n* **api:** manual updates ([4560dc6](https://github.com/openai/openai-node/commit/4560dc62f8c65e9857085409e382760aa601d60b))\n* **api:** manual updates ([554c3b1](https://github.com/openai/openai-node/commit/554c3b142024bec8010474cd7e42b99a209d4daa))\n* **api:** manual updates ([b893d81](https://github.com/openai/openai-node/commit/b893d81420359c712dab6997c2dbc9f309549712))\n* **api:** manual updates ([c1c2819](https://github.com/openai/openai-node/commit/c1c281983e23dcfdca964720265d3cba28b17795))\n* **api:** manual updates ([efce6d3](https://github.com/openai/openai-node/commit/efce6d3d719ad463b035b22e9a1cf461ab62b5af))\n* **api:** manual updates ([32afb00](https://github.com/openai/openai-node/commit/32afb0022939b19069c37fcd9cabfe666ea86b77))\n* **api:** new API tools ([fb4014f](https://github.com/openai/openai-node/commit/fb4014ffac7b220d37bd03c94fa745386b010bf0))\n* **api:** new models for TTS, STT, + new audio features for Realtime ([#1407](https://github.com/openai/openai-node/issues/1407)) ([d11b13c](https://github.com/openai/openai-node/commit/d11b13cdf5412f03e551365297a27e610a36edda))\n* **api:** new streaming helpers for background responses ([1ddd6ff](https://github.com/openai/openai-node/commit/1ddd6ff182b09d696954fda4bde50fb82f1d6585))\n* **api:** o1-pro now available through the API ([#1398](https://github.com/openai/openai-node/issues/1398)) ([aefd267](https://github.com/openai/openai-node/commit/aefd2675154ff848032a7fec856f0db6ed2ad629))\n* **api:** responses x eval api ([ea1d56c](https://github.com/openai/openai-node/commit/ea1d56c979ad7136aa584a773904b0570ba14783))\n* **api:** Updating Assistants and Evals API schemas ([8cc63d3](https://github.com/openai/openai-node/commit/8cc63d351057678d474fe1a16e3077370c83fddb))\n* **client:** accept RFC6838 JSON content types ([67da9ce](https://github.com/openai/openai-node/commit/67da9ce89ea010813779b98c18fea84d9964c7de))\n* **client:** add Realtime API support ([7737d25](https://github.com/openai/openai-node/commit/7737d2547c5c6c45004fe281b8122c9e2adc0efb))\n* **client:** add withOptions helper ([7e9ea85](https://github.com/openai/openai-node/commit/7e9ea85f63a0989b3446834d9e1a94c0d050cf87))\n* **client:** improve logging ([ead0ba4](https://github.com/openai/openai-node/commit/ead0ba4dc9f51c35007c5fe20f9954855f558652))\n* **client:** promote beta completions methods to GA ([4c622f9](https://github.com/openai/openai-node/commit/4c622f9f55529e3aab30c834349d341038499db1))\n\n\n### Bug Fixes\n\n* **api:** add missing file rank enum + more metadata ([b943a0a](https://github.com/openai/openai-node/commit/b943a0ae4682a410172e1063a9424f5150cd9010))\n* **api:** correct some Responses types ([#1391](https://github.com/openai/openai-node/issues/1391)) ([e983d0c](https://github.com/openai/openai-node/commit/e983d0c61d33b106f149d87eed90378bd0bbc349))\n* **api:** improve type resolution when importing as a package ([#1444](https://github.com/openai/openai-node/issues/1444)) ([4af79dd](https://github.com/openai/openai-node/commit/4af79ddd5b19925fa09d9ae877470aa8304535c2))\n* **assistants:** handle `thread.run.incomplete` event ([a2714bb](https://github.com/openai/openai-node/commit/a2714bb5253ade80cb15455ceb8f6dbea63cb1d0))\n* **audio:** correctly handle transcription streaming ([9c7d352](https://github.com/openai/openai-node/commit/9c7d352181c690156e26c9538c00edff6db5b384))\n* avoid type error in certain environments ([#1413](https://github.com/openai/openai-node/issues/1413)) ([f395e95](https://github.com/openai/openai-node/commit/f395e9584ac63780442bb54c2d292914eaecf3c7))\n* **azure/audio:** use model param for deployments ([0eda70a](https://github.com/openai/openai-node/commit/0eda70adc3c88c12792c1eee9c3279579a86d412))\n* **azure:** add /images/edits to deployments endpoints ([#1509](https://github.com/openai/openai-node/issues/1509)) ([4b18059](https://github.com/openai/openai-node/commit/4b180597633a527c435e049d885103ab06311b90))\n* **azure:** add /images/edits to deployments endpoints ([#1509](https://github.com/openai/openai-node/issues/1509)) ([84fc31a](https://github.com/openai/openai-node/commit/84fc31aa903eceeb80815f6b17562fc463a71cfc))\n* **azure:** use correct internal method ([a9c7821](https://github.com/openai/openai-node/commit/a9c78216d88379bc1d5103b30970f041d22083b8))\n* **client:** always overwrite when merging headers ([c160550](https://github.com/openai/openai-node/commit/c160550761eed22b038ac8a5b477729fe298834c))\n* **client:** fix export map for index exports ([#1328](https://github.com/openai/openai-node/issues/1328)) ([26d5868](https://github.com/openai/openai-node/commit/26d5868dd53045bc820a607100eab1070785f50c))\n* **client:** fix export map for index exports, accept BunFile ([9416c96](https://github.com/openai/openai-node/commit/9416c96fdc12c9ea22da04ac317d93cb2ad94f57))\n* **client:** fix TypeError with undefined File ([0e980d0](https://github.com/openai/openai-node/commit/0e980d05e8e1fb4befae443fb84b8b9fab8dbd50))\n* **client:** remove duplicate types ([bee2ce5](https://github.com/openai/openai-node/commit/bee2ce5841f25b1f56cdc1fd0b36b0758d2c9bdc))\n* **client:** remove duplicate types ([#1410](https://github.com/openai/openai-node/issues/1410)) ([23fd3ff](https://github.com/openai/openai-node/commit/23fd3ffef3b19656b27576b4d0c613d19ea1ae2f))\n* **client:** return binary content from `get /containers/{container_id}/files/{file_id}/content` ([8502966](https://github.com/openai/openai-node/commit/8502966ed2fee9162ad14fdf04c893e1fa130a51))\n* **client:** return binary content from `get /containers/{container_id}/files/{file_id}/content` ([899869b](https://github.com/openai/openai-node/commit/899869b40ab5f64145c48521378f1925f6b5b33a))\n* **client:** return binary content from `get /containers/{container_id}/files/{file_id}/content` ([83129d7](https://github.com/openai/openai-node/commit/83129d7eac3dd784bb1c29fa344c5b808a59db73))\n* **client:** send `X-Stainless-Timeout` in seconds ([5a272a7](https://github.com/openai/openai-node/commit/5a272a76515b09810fcb5d0ca63dd6050d1a8023))\n* **client:** send `X-Stainless-Timeout` in seconds ([#1442](https://github.com/openai/openai-node/issues/1442)) ([5e5e460](https://github.com/openai/openai-node/commit/5e5e4607a103fcb6257c071bb4bf57902ee6415f))\n* **client:** send all configured auth headers ([ee01414](https://github.com/openai/openai-node/commit/ee01414c206f18a537f3616bcf1e208aab311030))\n* compat with more runtimes ([f743730](https://github.com/openai/openai-node/commit/f74373020ab01ace999a72d916e017db0177bf16))\n* correct imports ([21f2107](https://github.com/openai/openai-node/commit/21f210782b1ee3b33231cfed0277ab8e3a764bcb))\n* correctly decode multi-byte characters over multiple chunks ([f3d7083](https://github.com/openai/openai-node/commit/f3d708390a36427206edfc67875a7987eb483e55))\n* **docs:** correct docstring on responses.stream ([1847673](https://github.com/openai/openai-node/commit/1847673de09586c809e1057a6b08c604471e13ff))\n* **ecosystem-tests/bun:** bump dependencies ([1e52734](https://github.com/openai/openai-node/commit/1e52734e28a0e474b11c90977fd3161ea2e50f8c))\n* **ecosystem-tests/cloudflare-worker:** ignore lib errors for now ([157248a](https://github.com/openai/openai-node/commit/157248ae85d2261f9538128703d0ebbc24347c61))\n* **ecosystem-tests:** correct ecosystem tests setup ([6fa0675](https://github.com/openai/openai-node/commit/6fa06756624071fb1486c69a496ba906fef96de2))\n* **embeddings:** correctly decode base64 data ([#1448](https://github.com/openai/openai-node/issues/1448)) ([d6b99c8](https://github.com/openai/openai-node/commit/d6b99c8fcbd35ef6b45d66f487aea759c01febbc))\n* **exports:** add missing type exports ([a816029](https://github.com/openai/openai-node/commit/a81602996a1d9c3ceda79d88fe163a1e6b823e77))\n* **exports:** add missing type exports ([#1417](https://github.com/openai/openai-node/issues/1417)) ([06c03d7](https://github.com/openai/openai-node/commit/06c03d7125d8331679dd206d0e34705d65669046))\n* **exports:** ensure resource imports don't require /index ([d028ad7](https://github.com/openai/openai-node/commit/d028ad7b0debb585534acb73fa5cafe6f8d90f37))\n* **helpers/zod:** error on optional + not nullable fields ([6e424b5](https://github.com/openai/openai-node/commit/6e424b5cac1b2ea7e108ce24154be5bdddf56bdd))\n* **internal:** add mts file + crypto shim types ([a06deb8](https://github.com/openai/openai-node/commit/a06deb8aec21ecf8bfbc369112da10a790039178))\n* **internal:** clean up undefined File test ([da43aa9](https://github.com/openai/openai-node/commit/da43aa91586fe80137c6500e850dca82085936b8))\n* **internal:** fix file uploads in node 18 jest ([abfff03](https://github.com/openai/openai-node/commit/abfff03f49e62e195d112229127be674cc44497d))\n* **internal:** work around https://github.com/vercel/next.js/issues/76881 ([#1427](https://github.com/openai/openai-node/issues/1427)) ([84edc62](https://github.com/openai/openai-node/commit/84edc62d05eddaefee0973f9687fcfdd43b0afa9))\n* **jsr:** correct zod config ([04e30c0](https://github.com/openai/openai-node/commit/04e30c03ce0496a718aebf4cc2daac82ebba1ddb))\n* **jsr:** export realtime helpers ([0ea64eb](https://github.com/openai/openai-node/commit/0ea64eb2bde99e243761ea2e3d9d3c294c9f7fbc))\n* **jsr:** export zod helpers ([77e1180](https://github.com/openai/openai-node/commit/77e118082334710cab361efb95934422e4db6b18))\n* **mcp:** remove unused tools.ts ([#1445](https://github.com/openai/openai-node/issues/1445)) ([4ba9947](https://github.com/openai/openai-node/commit/4ba994773b41a3ed05a3ad908b235fc5f3810dfc))\n* optimize sse chunk reading off-by-one error ([#1339](https://github.com/openai/openai-node/issues/1339)) ([b0b4189](https://github.com/openai/openai-node/commit/b0b4189420e1c5bb5fc4bbb8925f88fe65f9b217))\n* **package:** add chat/completions.ts back in ([#1333](https://github.com/openai/openai-node/issues/1333)) ([1f38cc1](https://github.com/openai/openai-node/commit/1f38cc1976f4091a90a38d49e6ddc1c22e5c39ab))\n* **parsing:** remove tool_calls default empty array ([#1341](https://github.com/openai/openai-node/issues/1341)) ([6d056bf](https://github.com/openai/openai-node/commit/6d056bf95c9be4046decf20ec4c98dfa2bea2723))\n* **realtime:** call .toString() on WebSocket url ([#1324](https://github.com/openai/openai-node/issues/1324)) ([6e9444c](https://github.com/openai/openai-node/commit/6e9444c6c77a93ff4ce06bd5b27a9c236ba6f307))\n* **responses:** correct computer use enum value ([66fb815](https://github.com/openai/openai-node/commit/66fb8157217de604d7f535e917b085fa8b6754d4))\n* **responses:** correct reasoning output type ([9cb9576](https://github.com/openai/openai-node/commit/9cb95763cab5678c5098b37ad0fe1ec83d2c1cb7))\n* **responses:** correctly add output_text ([8ae07cc](https://github.com/openai/openai-node/commit/8ae07cc036895529a028134451fe2ab5c1661871))\n* **responses:** support streaming retrieve calls ([657807c](https://github.com/openai/openai-node/commit/657807c2d7cbf2c6fc9a92ce98bb7295bb156326))\n* **tests/embeddings:** avoid cross-realm issue ([aceaac0](https://github.com/openai/openai-node/commit/aceaac05c05fa318c4bff7ff340b512a6bd904b9))\n* **tests:** don't rely on OPENAI_API_KEY env variable ([087580a](https://github.com/openai/openai-node/commit/087580ae5ebedc88f6f219c7d00c08607722a519))\n* **tests:** manually reset node:buffer File ([1d18ed4](https://github.com/openai/openai-node/commit/1d18ed4f90436e7041835d201c8cb1c373ded418))\n* **tests:** port tests to new setup ([9eb9854](https://github.com/openai/openai-node/commit/9eb98543660c86f0b11766ef95b35fa28fd16e47))\n* **tests:** stop using node:stream ([317a04d](https://github.com/openai/openai-node/commit/317a04d8d189ee33a9dd5308668296a708b391a8))\n* **threads:** remove unused duplicative types ([0b77c7c](https://github.com/openai/openai-node/commit/0b77c7c9da64962fd50854be06661cdce549d326))\n* **types:** export AssistantStream ([#1472](https://github.com/openai/openai-node/issues/1472)) ([bc492ba](https://github.com/openai/openai-node/commit/bc492ba124cddd545eec7a1199712452c573a7a4))\n* **types:** export ParseableToolsParams ([#1486](https://github.com/openai/openai-node/issues/1486)) ([3e7c92c](https://github.com/openai/openai-node/commit/3e7c92c8a76c1f747610d63d9d69a88b796ee9fc))\n* **types:** ignore missing `id` in responses pagination ([d2be74a](https://github.com/openai/openai-node/commit/d2be74a28dec48cd7d88db88af95e8bc608cdede))\n* **types:** improve responses type names ([#1392](https://github.com/openai/openai-node/issues/1392)) ([4548326](https://github.com/openai/openai-node/commit/454832606ebe9d5cf8ffd436eac09375f682c495))\n* **zod:** warn on optional field usage ([#1469](https://github.com/openai/openai-node/issues/1469)) ([aea2d12](https://github.com/openai/openai-node/commit/aea2d123d200e6a7eae11e66583127270a8db8bf))\n\n\n### Performance Improvements\n\n* **embedding:** default embedding creation to base64 ([#1312](https://github.com/openai/openai-node/issues/1312)) ([be00d29](https://github.com/openai/openai-node/commit/be00d29fadb2b78920bcae1e6e72750bc6f973a4)), closes [#1310](https://github.com/openai/openai-node/issues/1310)\n\n\n### Chores\n\n* add hash of OpenAPI spec/config inputs to .stats.yml ([1b0a94d](https://github.com/openai/openai-node/commit/1b0a94d088c2891fcad0ca0de3a1e4e205a7c9cf))\n* add missing type alias exports ([5d75cb9](https://github.com/openai/openai-node/commit/5d75cb95019ae77eafb0c878b355f09a1f87c3bd))\n* **api:** updates to supported Voice IDs ([28130c7](https://github.com/openai/openai-node/commit/28130c7fe172dd90fcf2036dc72750e485e42645))\n* **ci:** add timeout thresholds for CI jobs ([5775451](https://github.com/openai/openai-node/commit/5775451a55212687ba998b332c1394528d98121f))\n* **ci:** bump node version for release workflows ([bbf5d45](https://github.com/openai/openai-node/commit/bbf5d45259a8bfba62e2217955597ec0f6cfead4))\n* **ci:** only use depot for staging repos ([c59c3b5](https://github.com/openai/openai-node/commit/c59c3b5ead95b424b27c8c9f2120ad4283fb280e))\n* **ci:** run on more branches and use depot runners ([e17a4f8](https://github.com/openai/openai-node/commit/e17a4f8e1fc3de02c953421debf39827ea72d52c))\n* **client:** drop support for EOL node versions ([a326944](https://github.com/openai/openai-node/commit/a326944e8a8822bc70f86d7046de3142f9dff530))\n* **client:** expose headers on some streaming errors ([#1423](https://github.com/openai/openai-node/issues/1423)) ([6c93a23](https://github.com/openai/openai-node/commit/6c93a23b79f335a21c65b52d1192890a5325ed6d))\n* **client:** minor internal fixes ([5032c28](https://github.com/openai/openai-node/commit/5032c2802bd51885270badf47e27768f62240d25))\n* **client:** more accurate streaming errors ([0c21914](https://github.com/openai/openai-node/commit/0c21914d90b0ef1073d99c539cf9ef18912b8d0b))\n* **client:** move misc public files to new `core/` directory, deprecate old paths ([38c9d54](https://github.com/openai/openai-node/commit/38c9d548fded9000cde85270b38085c61905b5c1))\n* **client:** only accept standard types for file uploads ([53e35c8](https://github.com/openai/openai-node/commit/53e35c8b10a8e3ef95c0d644d59ab915225b8114))\n* deprecate Assistants API ([0be23b9](https://github.com/openai/openai-node/commit/0be23b98b6be9f8922d035270b1c907307010a29))\n* **docs:** add missing deprecation warnings ([995075b](https://github.com/openai/openai-node/commit/995075b632051b5bb33c0381056107b2fe93931e))\n* **docs:** grammar improvements ([7761cfb](https://github.com/openai/openai-node/commit/7761cfb0a8a56d056a73c046a6a613f66ada4abe))\n* **docs:** improve docs for withResponse/asResponse ([9f4c30b](https://github.com/openai/openai-node/commit/9f4c30b9bcc2f373b3087dba69bd837f96f79d81))\n* **docs:** improve migration doc ([732d870](https://github.com/openai/openai-node/commit/732d87001cbd9aa095e7b58dc843e86547e3f510))\n* **docs:** update zod tool call example, fix azure tests ([f18ced8](https://github.com/openai/openai-node/commit/f18ced883e4b5d689e0569d9b163b1958688b669))\n* **exports:** cleaner resource index imports ([#1396](https://github.com/openai/openai-node/issues/1396)) ([023d106](https://github.com/openai/openai-node/commit/023d106185abf62f892bff66faf617eb45777004))\n* **exports:** stop using path fallbacks ([09af7ff](https://github.com/openai/openai-node/commit/09af7ffd42458c6c26d9325060fcb8925aca7c81))\n* **exports:** stop using path fallbacks ([#1397](https://github.com/openai/openai-node/issues/1397)) ([7c3d212](https://github.com/openai/openai-node/commit/7c3d212b47ee3090f5bbb82dd21026ba532da6e0))\n* fix example types ([20f179d](https://github.com/openai/openai-node/commit/20f179db1bb681db5d1a91adcaab16012d6ffcdf))\n* improve publish-npm script --latest tag logic ([6207a2a](https://github.com/openai/openai-node/commit/6207a2a03d3279423de594eed18c5efb4ce321af))\n* **internal:** add aliases for Record and Array ([#1443](https://github.com/openai/openai-node/issues/1443)) ([1cb66b6](https://github.com/openai/openai-node/commit/1cb66b6ccbcecaa6e48b90d37d8cac4840bb69a4))\n* **internal:** add back release workflow ([ca6266e](https://github.com/openai/openai-node/commit/ca6266eea5229056a3bc2b5e4225b9ea9eaa459e))\n* **internal:** add Bun.File ecosystem test ([cb4194f](https://github.com/openai/openai-node/commit/cb4194f08a2dcb4fc4231bf1b74ed5d6e0aca435))\n* **internal:** add missing return type annotation ([#1334](https://github.com/openai/openai-node/issues/1334)) ([13aab10](https://github.com/openai/openai-node/commit/13aab101588c2eee1250d7c50b2abfeca1c5fa3d))\n* **internal:** add proxy ecosystem tests ([619711a](https://github.com/openai/openai-node/commit/619711ae0da5243c64c266d615703279f7651f58))\n* **internal:** bump migration cli version ([a899c97](https://github.com/openai/openai-node/commit/a899c9748de17ef468a03a97b9ed82124189ff4c))\n* **internal:** codegen related update ([c735a3c](https://github.com/openai/openai-node/commit/c735a3c24ac8255df50f89c519fb7dfc617db045))\n* **internal:** fix devcontainers setup ([#1343](https://github.com/openai/openai-node/issues/1343)) ([9485f5d](https://github.com/openai/openai-node/commit/9485f5d4d6718bff7f579223c9aa528898451533))\n* **internal:** fix eslint ignores ([ad5a9b6](https://github.com/openai/openai-node/commit/ad5a9b6f07002df70764f1b9e5d6cd675eba87ea))\n* **internal:** fix examples ([#1457](https://github.com/openai/openai-node/issues/1457)) ([a100f0a](https://github.com/openai/openai-node/commit/a100f0a0e1d336f8a78c8bbd9e3703cda3f0c5d8))\n* **internal:** fix format script ([3e1ea40](https://github.com/openai/openai-node/commit/3e1ea4063327ac34f4f46536600a8923f96dbbb0))\n* **internal:** fix formatting ([6469d53](https://github.com/openai/openai-node/commit/6469d5323b653f19e90a7470d81c914c640c6f8b))\n* **internal:** fix lint ([45a372c](https://github.com/openai/openai-node/commit/45a372ca0436f2f79c2387665b1c1bc04fd3bfed))\n* **internal:** fix release workflows ([353349d](https://github.com/openai/openai-node/commit/353349de9ee10d32d3243cb5c60a8ae982c49d37))\n* **internal:** fix tests failing on node v18 ([c54270a](https://github.com/openai/openai-node/commit/c54270a58ada1d0d7878ce80c7c2093a56fed158))\n* **internal:** fix tests not always being type checked ([0266b41](https://github.com/openai/openai-node/commit/0266b41efa311205f0fc51b6dc6d29ab003254a6))\n* **internal:** improve node 18 shims ([ee3f483](https://github.com/openai/openai-node/commit/ee3f48333a1d73a096f3417b2701fd722e4fbc68))\n* **internal:** minor client file refactoring ([d1aa00a](https://github.com/openai/openai-node/commit/d1aa00afc760f73624a8a109600c03deba40e72b))\n* **internal:** only run examples workflow in main repo ([#1450](https://github.com/openai/openai-node/issues/1450)) ([93569f3](https://github.com/openai/openai-node/commit/93569f39799512604db439af20f0ef0ad3dae295))\n* **internal:** reduce CI branch coverage ([77fc77f](https://github.com/openai/openai-node/commit/77fc77f7d05d03eafe6c8f002044c60c4bab3c64))\n* **internal:** refactor utils ([e7fbfbc](https://github.com/openai/openai-node/commit/e7fbfbce41c00aaa7d3b75a4bf001c7562b5b722))\n* **internal:** remove CI condition ([#1381](https://github.com/openai/openai-node/issues/1381)) ([e905c95](https://github.com/openai/openai-node/commit/e905c95a27213ee65210b061ead4c982de01648b))\n* **internal:** remove unnecessary todo ([b55321e](https://github.com/openai/openai-node/commit/b55321e2d0713d41b4050e8ccf0ac4eefb45be3a))\n* **internal:** run CI on update-specs branch ([9c45ef3](https://github.com/openai/openai-node/commit/9c45ef37249e7db3ba8aa2e81886ffe306b95da4))\n* **internal:** run example files in CI ([#1357](https://github.com/openai/openai-node/issues/1357)) ([1044c48](https://github.com/openai/openai-node/commit/1044c487566569e773d5f6c1a94ce6b614e62b80))\n* **internal:** share typescript helpers ([2470933](https://github.com/openai/openai-node/commit/247093374538f0e714178134c38813bc4fde9ecf))\n* **internal:** skip broken test ([#1458](https://github.com/openai/openai-node/issues/1458)) ([58f4559](https://github.com/openai/openai-node/commit/58f4559d952f6e56a8f27a6bcaba0acf295623df))\n* **internal:** update @types/bun ([d94b41a](https://github.com/openai/openai-node/commit/d94b41a58e24c82c3f7369bd1360b394e93cf1dd))\n* **internal:** update release workflows ([2cbf49a](https://github.com/openai/openai-node/commit/2cbf49a0b9a8cfbee29cec558c5ccdcebd72396f))\n* **internal:** upload builds and expand CI branch coverage ([#1460](https://github.com/openai/openai-node/issues/1460)) ([2d45287](https://github.com/openai/openai-node/commit/2d452879000c07f3ef4e775e19a527f5f6fa7b4c))\n* **migration:** add beta handling ([3508099](https://github.com/openai/openai-node/commit/3508099991ecfa260d77678037275133130e09dc))\n* move ChatModel type to shared ([236dbf4](https://github.com/openai/openai-node/commit/236dbf4092fccf7697852c6341a8f38f0241770c))\n* **package:** remove engines ([500a82f](https://github.com/openai/openai-node/commit/500a82f45d46697be14987e12d896acb2b109d32))\n* **perf:** faster base64 decoding ([11b9534](https://github.com/openai/openai-node/commit/11b9534d317f87cdcb1934ead013f058865e675e))\n* **tests:** improve enum examples ([#1454](https://github.com/openai/openai-node/issues/1454)) ([15a86c9](https://github.com/openai/openai-node/commit/15a86c958bf300486907f2498e1028fc9bc50b00))\n* **tests:** stop using node-fetch, don't directly upload FormDataFile ([ebd464f](https://github.com/openai/openai-node/commit/ebd464f5ad07f440ad476c0a7ce733947da414e2))\n* **tests:** switch proxy tests to fetchOptions ([da6ed5f](https://github.com/openai/openai-node/commit/da6ed5fc4c9ec203d9add28c34c90532b0334a3e))\n* **types:** improved go to definition on fetchOptions ([f1712cd](https://github.com/openai/openai-node/commit/f1712cdea42e9d95d4b2dc40aae5cebc8e14c76d))\n* update next to 14.2.25 for CVE-2025-29927 ([1ed4288](https://github.com/openai/openai-node/commit/1ed4288c7b9ca8fcb00e524bc6f39c255c6661c5))\n* workaround build errors ([e4a7f67](https://github.com/openai/openai-node/commit/e4a7f674f719a87bb78378a5ce4639d84620e17a))\n* workaround build errors ([d6b396b](https://github.com/openai/openai-node/commit/d6b396b94d9ccf64ddfe945069012b6162225fa9))\n\n\n### Documentation\n\n* add examples to tsdocs ([e8d2092](https://github.com/openai/openai-node/commit/e8d2092e51015b05fe7ef33ef5a9d7652846b137))\n* fix \"procesing\" -&gt; \"processing\" in realtime examples ([#1406](https://github.com/openai/openai-node/issues/1406)) ([dfbdc65](https://github.com/openai/openai-node/commit/dfbdc65d3ed17f0063d02906239371b88e04e5fd))\n* **migration:** mention zod helpers error ([43b870d](https://github.com/openai/openai-node/commit/43b870d1651d0c13e4ec10a53de2dfbae276c3e7))\n* **readme:** fix typo ([c44ed98](https://github.com/openai/openai-node/commit/c44ed98a3e7f497a656d612037667dd1f2e6816b))\n* **readme:** fix typo ([0989ddc](https://github.com/openai/openai-node/commit/0989ddcfd5ed0a149bbc67d61f93e0f49c397c72))\n* update URLs from stainlessapi.com to stainless.com ([#1352](https://github.com/openai/openai-node/issues/1352)) ([634a209](https://github.com/openai/openai-node/commit/634a209a6025640e2849133f6997af8faa28d4d8))\n\n\n### Refactors\n\n* **client:** remove deprecated runFunctions method ([e29a009](https://github.com/openai/openai-node/commit/e29a0092e9b077c2a99cd521a316aea4c25ea632))\n* **functions:** rename function helper methods to include tools ([fdd6f66](https://github.com/openai/openai-node/commit/fdd6f6672ec577cbb6876fe3857a2161402513c3))\n\n## 4.104.0 (2025-05-29)\n\nFull Changelog: [v4.103.0...v4.104.0](https://github.com/openai/openai-node/compare/v4.103.0...v4.104.0)\n\n### Features\n\n* **api:** Config update for pakrym-stream-param ([469ad7b](https://github.com/openai/openai-node/commit/469ad7b9d76b674aa3fd829128a54758ab7adfbd))\n\n\n### Bug Fixes\n\n* **azure:** add /images/edits to deployments endpoints ([#1509](https://github.com/openai/openai-node/issues/1509)) ([84fc31a](https://github.com/openai/openai-node/commit/84fc31aa903eceeb80815f6b17562fc463a71cfc))\n* **client:** return binary content from `get /containers/{container_id}/files/{file_id}/content` ([83129d7](https://github.com/openai/openai-node/commit/83129d7eac3dd784bb1c29fa344c5b808a59db73))\n\n\n### Chores\n\n* deprecate Assistants API ([5b34fcd](https://github.com/openai/openai-node/commit/5b34fcdd1454b8cccbaaf05ace6516afb3b09273))\n* improve publish-npm script --latest tag logic ([6207a2a](https://github.com/openai/openai-node/commit/6207a2a03d3279423de594eed18c5efb4ce321af))\n* **internal:** fix release workflows ([353349d](https://github.com/openai/openai-node/commit/353349de9ee10d32d3243cb5c60a8ae982c49d37))\n\n## 4.103.0 (2025-05-22)\n\nFull Changelog: [v4.102.0...v4.103.0](https://github.com/openai/openai-node/compare/v4.102.0...v4.103.0)\n\n### Features\n\n* **api:** new streaming helpers for background responses ([1ddd6ff](https://github.com/openai/openai-node/commit/1ddd6ff182b09d696954fda4bde50fb82f1d6585))\n\n## 4.102.0 (2025-05-21)\n\nFull Changelog: [v4.101.0...v4.102.0](https://github.com/openai/openai-node/compare/v4.101.0...v4.102.0)\n\n### Features\n\n* **api:** add container endpoint ([e973476](https://github.com/openai/openai-node/commit/e9734764625275c50ef612ff934804be8cb2adff))\n\n## 4.101.0 (2025-05-21)\n\nFull Changelog: [v4.100.0...v4.101.0](https://github.com/openai/openai-node/compare/v4.100.0...v4.101.0)\n\n### Features\n\n* **api:** new API tools ([fb4014f](https://github.com/openai/openai-node/commit/fb4014ffac7b220d37bd03c94fa745386b010bf0))\n\n\n### Chores\n\n* **docs:** grammar improvements ([7761cfb](https://github.com/openai/openai-node/commit/7761cfb0a8a56d056a73c046a6a613f66ada4abe))\n* **internal:** version bump ([b40e830](https://github.com/openai/openai-node/commit/b40e8302ec11683b6a360a050236ad1284afc760))\n\n## 4.100.0 (2025-05-16)\n\nFull Changelog: [v4.99.0...v4.100.0](https://github.com/openai/openai-node/compare/v4.99.0...v4.100.0)\n\n### Features\n\n* **api:** further updates for evals API ([3f6f248](https://github.com/openai/openai-node/commit/3f6f248191b45015924be76fd5154d149c4ed8a0))\n\n\n### Chores\n\n* **internal:** version bump ([5123fe0](https://github.com/openai/openai-node/commit/5123fe08a56f3d0040b1cc67129382f3eacc3cca))\n\n## 4.99.0 (2025-05-16)\n\nFull Changelog: [v4.98.0...v4.99.0](https://github.com/openai/openai-node/compare/v4.98.0...v4.99.0)\n\n### Features\n\n* **api:** manual updates ([75eb804](https://github.com/openai/openai-node/commit/75eb804edd6ad653eaa22d47f8c6d09ee845ebf4))\n* **api:** responses x eval api ([5029f1a](https://github.com/openai/openai-node/commit/5029f1a05eb1e8601ada06e0a5ba49f4c2b83c02))\n* **api:** Updating Assistants and Evals API schemas ([27fd517](https://github.com/openai/openai-node/commit/27fd5173b20f75debe96024ae8f1ce58a8254d26))\n\n## 4.98.0 (2025-05-08)\n\nFull Changelog: [v4.97.0...v4.98.0](https://github.com/openai/openai-node/compare/v4.97.0...v4.98.0)\n\n### Features\n\n* **api:** Add reinforcement fine-tuning api support ([4aa7a79](https://github.com/openai/openai-node/commit/4aa7a7954c63caa26cc1640ace56093fe1cafa04))\n\n\n### Chores\n\n* **ci:** bump node version for release workflows ([2961f63](https://github.com/openai/openai-node/commit/2961f63c4d5b8ae8efdf8ea6581aa83c6b0f722e))\n* **internal:** fix formatting ([91a44fe](https://github.com/openai/openai-node/commit/91a44fe11c0847dc50d48a03a8d409ac4bece37a))\n\n\n### Documentation\n\n* add examples to tsdocs ([7d841b7](https://github.com/openai/openai-node/commit/7d841b7f98eb542a398fb9de12056125e8d6cb22))\n\n## 4.97.0 (2025-05-02)\n\nFull Changelog: [v4.96.2...v4.97.0](https://github.com/openai/openai-node/compare/v4.96.2...v4.97.0)\n\n### Features\n\n* **api:** add image sizes, reasoning encryption ([9c2113a](https://github.com/openai/openai-node/commit/9c2113af7c7ea9a797a0e39d07d9ad8627c96acb))\n\n\n### Chores\n\n* **docs:** add missing deprecation warnings ([253392c](https://github.com/openai/openai-node/commit/253392c93adca88e0ee83f784183b2128ff64a16))\n\n\n### Documentation\n\n* fix \"procesing\" -&gt; \"processing\" in realtime examples ([#1406](https://github.com/openai/openai-node/issues/1406)) ([8717b9f](https://github.com/openai/openai-node/commit/8717b9fce87d03e51d40ee58f5d6259408405e1f))\n* **readme:** fix typo ([cab3478](https://github.com/openai/openai-node/commit/cab3478f195f9de5c21033a1b3684f52ad347ffc))\n\n## 4.96.2 (2025-04-29)\n\nFull Changelog: [v4.96.1...v4.96.2](https://github.com/openai/openai-node/compare/v4.96.1...v4.96.2)\n\n### Bug Fixes\n\n* **types:** export ParseableToolsParams ([#1486](https://github.com/openai/openai-node/issues/1486)) ([3e7c92c](https://github.com/openai/openai-node/commit/3e7c92c8a76c1f747610d63d9d69a88b796ee9fc))\n\n\n### Chores\n\n* **ci:** only use depot for staging repos ([214da39](https://github.com/openai/openai-node/commit/214da398c76f46d40994665f3ca7e10e203e9579))\n* **ci:** run on more branches and use depot runners ([ead76fc](https://github.com/openai/openai-node/commit/ead76fc6429ac52a1c8b008ac5c0afcefaa0bae5))\n\n## 4.96.1 (2025-04-29)\n\nFull Changelog: [v4.96.0...v4.96.1](https://github.com/openai/openai-node/compare/v4.96.0...v4.96.1)\n\n### Bug Fixes\n\n* **types:** export ParseableToolsParams ([#1486](https://github.com/openai/openai-node/issues/1486)) ([eb055b2](https://github.com/openai/openai-node/commit/eb055b26ce90e5fe1b101a95a4390956d519e168))\n\n\n### Chores\n\n* **ci:** only use depot for staging repos ([e80af47](https://github.com/openai/openai-node/commit/e80af47590056baa8f456e8d60c37f0d00ff08c4))\n* **ci:** run on more branches and use depot runners ([b04a801](https://github.com/openai/openai-node/commit/b04a801d0356105eacddbb4d10f4359719585dd6))\n\n## 4.96.0 (2025-04-23)\n\nFull Changelog: [v4.95.1...v4.96.0](https://github.com/openai/openai-node/compare/v4.95.1...v4.96.0)\n\n### Features\n\n* **api:** adding new image model support ([a00d331](https://github.com/openai/openai-node/commit/a00d33190edd08df7d9c088c00ab7b77673f88ba))\n\n\n### Bug Fixes\n\n* **types:** export AssistantStream ([#1472](https://github.com/openai/openai-node/issues/1472)) ([626c844](https://github.com/openai/openai-node/commit/626c844a758a68ffbff48873d4773be2e3868952))\n\n\n### Chores\n\n* **ci:** add timeout thresholds for CI jobs ([e465063](https://github.com/openai/openai-node/commit/e46506351097f1de39c866c28b6ec20fa724fc36))\n\n## 4.95.1 (2025-04-18)\n\nFull Changelog: [v4.95.0...v4.95.1](https://github.com/openai/openai-node/compare/v4.95.0...v4.95.1)\n\n### Bug Fixes\n\n* **zod:** warn on optional field usage ([#1469](https://github.com/openai/openai-node/issues/1469)) ([aea2d12](https://github.com/openai/openai-node/commit/aea2d123d200e6a7eae11e66583127270a8db8bf))\n\n## 4.95.0 (2025-04-16)\n\nFull Changelog: [v4.94.0...v4.95.0](https://github.com/openai/openai-node/compare/v4.94.0...v4.95.0)\n\n### Features\n\n* **api:** add o3 and o4-mini model IDs ([4845cd9](https://github.com/openai/openai-node/commit/4845cd9ac17450022f1632ae01397e41a97f1662))\n\n## 4.94.0 (2025-04-14)\n\nFull Changelog: [v4.93.0...v4.94.0](https://github.com/openai/openai-node/compare/v4.93.0...v4.94.0)\n\n### Features\n\n* **api:** adding gpt-4.1 family of model IDs ([bddcbcf](https://github.com/openai/openai-node/commit/bddcbcffdc409ffc8a078a65bbd302cd50b35ff0))\n* **api:** manual updates ([7532f48](https://github.com/openai/openai-node/commit/7532f48ad25c5125064a59985587c20c47a2cbfb))\n\n\n### Chores\n\n* **client:** minor internal fixes ([d342f17](https://github.com/openai/openai-node/commit/d342f17e2642da5ee83d080b410dc3c4fe153814))\n* **internal:** reduce CI branch coverage ([a49b94a](https://github.com/openai/openai-node/commit/a49b94a9aebd3e30e1802fff633e1b46cfb81942))\n* **internal:** upload builds and expand CI branch coverage ([#1460](https://github.com/openai/openai-node/issues/1460)) ([7e23bb4](https://github.com/openai/openai-node/commit/7e23bb4f4a09303195b612cc5b393cc41c1d855b))\n* workaround build errors ([913eba8](https://github.com/openai/openai-node/commit/913eba828d116f49fa78b219c62274c1e95c6f17))\n\n## 4.93.0 (2025-04-08)\n\nFull Changelog: [v4.92.1...v4.93.0](https://github.com/openai/openai-node/compare/v4.92.1...v4.93.0)\n\n### Features\n\n* **api:** Add evalapi to sdk ([#1456](https://github.com/openai/openai-node/issues/1456)) ([ee917e3](https://github.com/openai/openai-node/commit/ee917e3335fcf44e87a28e54ce8ddfdcdfab1652))\n\n\n### Chores\n\n* **internal:** fix examples ([#1457](https://github.com/openai/openai-node/issues/1457)) ([a3dd0dd](https://github.com/openai/openai-node/commit/a3dd0dde3e8ad9cc7a02cf203d4550f91d31a2ae))\n* **internal:** skip broken test ([#1458](https://github.com/openai/openai-node/issues/1458)) ([4d2f815](https://github.com/openai/openai-node/commit/4d2f815ba5f6c426f9c21f4c3db443166389bbf8))\n* **tests:** improve enum examples ([#1454](https://github.com/openai/openai-node/issues/1454)) ([ecabce2](https://github.com/openai/openai-node/commit/ecabce282a9fb60122310942f3b647dfefae5403))\n\n## 4.92.1 (2025-04-07)\n\nFull Changelog: [v4.92.0...v4.92.1](https://github.com/openai/openai-node/compare/v4.92.0...v4.92.1)\n\n### Chores\n\n* **internal:** only run examples workflow in main repo ([#1450](https://github.com/openai/openai-node/issues/1450)) ([5e49a7a](https://github.com/openai/openai-node/commit/5e49a7a447bb788fa05898c15ae57c6ea9c8fd49))\n\n## 4.92.0 (2025-04-07)\n\nFull Changelog: [v4.91.1...v4.92.0](https://github.com/openai/openai-node/compare/v4.91.1...v4.92.0)\n\n### Features\n\n* **api:** manual updates ([891754d](https://github.com/openai/openai-node/commit/891754d7fa42d71ce4f93288dd043ef0b97fee23))\n* **api:** manual updates ([01e5546](https://github.com/openai/openai-node/commit/01e5546f3f48a1f4d645e09e7581f16b30f25bdd))\n* **api:** manual updates ([f38dbf3](https://github.com/openai/openai-node/commit/f38dbf3b39b0800b3bbef5c603a4fa2b616f25d8))\n* **api:** manual updates ([1f12253](https://github.com/openai/openai-node/commit/1f12253054a5a7e35dc03b17901b4c1f33bf5b3d))\n\n\n### Bug Fixes\n\n* **api:** improve type resolution when importing as a package ([#1444](https://github.com/openai/openai-node/issues/1444)) ([4aa46d6](https://github.com/openai/openai-node/commit/4aa46d6c0da681bcdde31fcbb09e8ba6fdaf764b))\n* **client:** send `X-Stainless-Timeout` in seconds ([#1442](https://github.com/openai/openai-node/issues/1442)) ([aa4206c](https://github.com/openai/openai-node/commit/aa4206c7d93b4e3114a697f5467ffbbf5a64d1a8))\n* **embeddings:** correctly decode base64 data ([#1448](https://github.com/openai/openai-node/issues/1448)) ([58128f7](https://github.com/openai/openai-node/commit/58128f7efde73726da740c42adde7b02cdf60a6a))\n* **mcp:** remove unused tools.ts ([#1445](https://github.com/openai/openai-node/issues/1445)) ([520a8fa](https://github.com/openai/openai-node/commit/520a8fa77a69ce5855dde3481f9bd39339cb7b83))\n\n\n### Chores\n\n* **internal:** add aliases for Record and Array ([#1443](https://github.com/openai/openai-node/issues/1443)) ([b65391b](https://github.com/openai/openai-node/commit/b65391ba10d5063035c3e5c0bcc5a48ffc80f41d))\n\n## 4.91.1 (2025-04-01)\n\nFull Changelog: [v4.91.0...v4.91.1](https://github.com/openai/openai-node/compare/v4.91.0...v4.91.1)\n\n### Bug Fixes\n\n* **docs:** correct docstring on responses.stream ([1c8cd6a](https://github.com/openai/openai-node/commit/1c8cd6a638128b0ff5fac89d6c7db256f0b63a85))\n\n\n### Chores\n\n* Remove deprecated/unused remote spec feature ([ce3dfa8](https://github.com/openai/openai-node/commit/ce3dfa88bd4d395debccc0e6e1aac6d218b07cb8))\n\n## 4.91.0 (2025-03-31)\n\nFull Changelog: [v4.90.0...v4.91.0](https://github.com/openai/openai-node/compare/v4.90.0...v4.91.0)\n\n### Features\n\n* **api:** add `get /responses/{response_id}/input_items` endpoint ([ef0e0ac](https://github.com/openai/openai-node/commit/ef0e0acd469379ae6f2745c83e6c6813ff7b4edc))\n\n\n### Performance Improvements\n\n* **embedding:** default embedding creation to base64 ([#1312](https://github.com/openai/openai-node/issues/1312)) ([e54530e](https://github.com/openai/openai-node/commit/e54530e4f6f00d7d74fc8636bbdb6f6280548750)), closes [#1310](https://github.com/openai/openai-node/issues/1310)\n\n## 4.90.0 (2025-03-27)\n\nFull Changelog: [v4.89.1...v4.90.0](https://github.com/openai/openai-node/compare/v4.89.1...v4.90.0)\n\n### Features\n\n* **api:** add `get /chat/completions` endpoint ([2d6710a](https://github.com/openai/openai-node/commit/2d6710a1f9dd4f768d9c73e9c9f5f93c737cdc66))\n\n\n### Bug Fixes\n\n* **audio:** correctly handle transcription streaming ([2a9b603](https://github.com/openai/openai-node/commit/2a9b60336cd40a4d4fb9b898ece49170ad648fd0))\n* **internal:** work around https://github.com/vercel/next.js/issues/76881 ([#1427](https://github.com/openai/openai-node/issues/1427)) ([b467e94](https://github.com/openai/openai-node/commit/b467e949476621e8e92587a83c9de6fab35b2b9d))\n\n\n### Chores\n\n* add hash of OpenAPI spec/config inputs to .stats.yml ([45db35e](https://github.com/openai/openai-node/commit/45db35e34be560c75bf36224cc153c6d0e6e2a88))\n* **api:** updates to supported Voice IDs ([#1424](https://github.com/openai/openai-node/issues/1424)) ([404f4db](https://github.com/openai/openai-node/commit/404f4db41a2ee651f5bfdaa7b8881e1bf015f058))\n* **client:** expose headers on some streaming errors ([#1423](https://github.com/openai/openai-node/issues/1423)) ([b0783cc](https://github.com/openai/openai-node/commit/b0783cc6221b68f1738e759b393756a7d0e540a3))\n\n## 4.89.1 (2025-03-26)\n\nFull Changelog: [v4.89.0...v4.89.1](https://github.com/openai/openai-node/compare/v4.89.0...v4.89.1)\n\n### Bug Fixes\n\n* avoid type error in certain environments ([#1413](https://github.com/openai/openai-node/issues/1413)) ([d3f6f8f](https://github.com/openai/openai-node/commit/d3f6f8f9c7511a98cc5795756fee49a30e44d485))\n* **client:** remove duplicate types ([#1410](https://github.com/openai/openai-node/issues/1410)) ([338878b](https://github.com/openai/openai-node/commit/338878bf484dac5a4fadf50592b1f8d1045cd4b6))\n* **exports:** add missing type exports ([#1417](https://github.com/openai/openai-node/issues/1417)) ([2d15ada](https://github.com/openai/openai-node/commit/2d15ada0e0d81a4e0d097dddbe99be2222c4c0ef))\n\n\n### Chores\n\n* **internal:** version bump ([#1408](https://github.com/openai/openai-node/issues/1408)) ([9c0949a](https://github.com/openai/openai-node/commit/9c0949a93c3e181d327f820dbc2a4b0ad77258e9))\n\n## 4.89.0 (2025-03-20)\n\nFull Changelog: [v4.88.0...v4.89.0](https://github.com/openai/openai-node/compare/v4.88.0...v4.89.0)\n\n### Features\n\n* add audio helpers ([ea1b6b4](https://github.com/openai/openai-node/commit/ea1b6b4ef38813af568b3662037519da9404b80e))\n* **api:** new models for TTS, STT, + new audio features for Realtime ([#1407](https://github.com/openai/openai-node/issues/1407)) ([142933a](https://github.com/openai/openai-node/commit/142933ae70d06045dbf4661cd72c7fa35ae7903d))\n\n\n### Chores\n\n* **internal:** version bump ([#1400](https://github.com/openai/openai-node/issues/1400)) ([6838ab4](https://github.com/openai/openai-node/commit/6838ab4268c7c0e083e7be21ef1a51bdea0f0b57))\n\n## 4.88.0 (2025-03-19)\n\nFull Changelog: [v4.87.4...v4.88.0](https://github.com/openai/openai-node/compare/v4.87.4...v4.88.0)\n\n### Features\n\n* **api:** o1-pro now available through the API ([#1398](https://github.com/openai/openai-node/issues/1398)) ([616a7e9](https://github.com/openai/openai-node/commit/616a7e90e764882cd749a65af8cc6ae8734fc80d))\n\n\n### Chores\n\n* **exports:** cleaner resource index imports ([#1396](https://github.com/openai/openai-node/issues/1396)) ([26b0856](https://github.com/openai/openai-node/commit/26b0856cd63846c34b75895a1ea42ceec7908c1a))\n* **exports:** stop using path fallbacks ([#1397](https://github.com/openai/openai-node/issues/1397)) ([d1479c2](https://github.com/openai/openai-node/commit/d1479c23aff68dd46c73fd31896dd2298a6bf140))\n* **internal:** version bump ([#1393](https://github.com/openai/openai-node/issues/1393)) ([7f16c3a](https://github.com/openai/openai-node/commit/7f16c3aa7b1ab36541219c5a0f93fc518733d0e3))\n\n## 4.87.4 (2025-03-18)\n\nFull Changelog: [v4.87.3...v4.87.4](https://github.com/openai/openai-node/compare/v4.87.3...v4.87.4)\n\n### Bug Fixes\n\n* **api:** correct some Responses types ([#1391](https://github.com/openai/openai-node/issues/1391)) ([af45876](https://github.com/openai/openai-node/commit/af458766ac721fb6cf18e7d78c458506c8bfc4e1))\n* **types:** ignore missing `id` in responses pagination ([1b9d20e](https://github.com/openai/openai-node/commit/1b9d20e71f5afbd4999f1999fe4810175476c5d2))\n* **types:** improve responses type names ([#1392](https://github.com/openai/openai-node/issues/1392)) ([164f476](https://github.com/openai/openai-node/commit/164f47606b41fd3e2850f8209eb1c6e2996a81ff))\n\n\n### Chores\n\n* add missing type alias exports ([#1390](https://github.com/openai/openai-node/issues/1390)) ([16c5e22](https://github.com/openai/openai-node/commit/16c5e2261c8c1a0ba96c2d5f475e8b1bc67387d7))\n* **internal:** add back release workflow ([dddf29b](https://github.com/openai/openai-node/commit/dddf29bd914a02d4586b239ec06217389a4409f9))\n* **internal:** remove CI condition ([#1381](https://github.com/openai/openai-node/issues/1381)) ([ef17981](https://github.com/openai/openai-node/commit/ef17981a0bd6b3e971986ece829c5d260d7392d4))\n* **internal:** run CI on update-specs branch ([9fc2130](https://github.com/openai/openai-node/commit/9fc2130b74a5919a3bbd41926903bdb310de4446))\n* **internal:** update release workflows ([90b77d0](https://github.com/openai/openai-node/commit/90b77d09c04d21487aa38fe775c79ae632136813))\n\n## 4.87.3 (2025-03-11)\n\nFull Changelog: [v4.87.2...v4.87.3](https://github.com/openai/openai-node/compare/v4.87.2...v4.87.3)\n\n### Bug Fixes\n\n* **responses:** correct reasoning output type ([2abef57](https://github.com/openai/openai-node/commit/2abef57d7645a96a4b9a6b91483861cd568d2d4d))\n\n## 4.87.2 (2025-03-11)\n\nFull Changelog: [v4.87.1...v4.87.2](https://github.com/openai/openai-node/compare/v4.87.1...v4.87.2)\n\n### Bug Fixes\n\n* **responses:** correctly add output_text ([4ceb5cc](https://github.com/openai/openai-node/commit/4ceb5cc516b8c75d46f0042534d7658796a8cd71))\n\n## 4.87.1 (2025-03-11)\n\nFull Changelog: [v4.87.0...v4.87.1](https://github.com/openai/openai-node/compare/v4.87.0...v4.87.1)\n\n### Bug Fixes\n\n* correct imports ([5cdf17c](https://github.com/openai/openai-node/commit/5cdf17cec33da7cf540b8bdbcfa30c0c52842dd1))\n\n## 4.87.0 (2025-03-11)\n\nFull Changelog: [v4.86.2...v4.87.0](https://github.com/openai/openai-node/compare/v4.86.2...v4.87.0)\n\n### Features\n\n* **api:** add /v1/responses and built-in tools ([119b584](https://github.com/openai/openai-node/commit/119b5843a18b8014167c8d2031d75c08dbf400a3))\n\n## 4.86.2 (2025-03-05)\n\nFull Changelog: [v4.86.1...v4.86.2](https://github.com/openai/openai-node/compare/v4.86.1...v4.86.2)\n\n### Chores\n\n* **internal:** run example files in CI ([#1357](https://github.com/openai/openai-node/issues/1357)) ([88d0050](https://github.com/openai/openai-node/commit/88d0050336749deb3810b4cb43473de1f84e42bd))\n\n## 4.86.1 (2025-02-27)\n\nFull Changelog: [v4.86.0...v4.86.1](https://github.com/openai/openai-node/compare/v4.86.0...v4.86.1)\n\n### Documentation\n\n* update URLs from stainlessapi.com to stainless.com ([#1352](https://github.com/openai/openai-node/issues/1352)) ([8294e9e](https://github.com/openai/openai-node/commit/8294e9ef57ed98722105b56d205ebea9d028f671))\n\n## 4.86.0 (2025-02-27)\n\nFull Changelog: [v4.85.4...v4.86.0](https://github.com/openai/openai-node/compare/v4.85.4...v4.86.0)\n\n### Features\n\n* **api:** add gpt-4.5-preview ([#1349](https://github.com/openai/openai-node/issues/1349)) ([2a1d36b](https://github.com/openai/openai-node/commit/2a1d36b560323fca058f98607775642370e90a47))\n\n## 4.85.4 (2025-02-22)\n\nFull Changelog: [v4.85.3...v4.85.4](https://github.com/openai/openai-node/compare/v4.85.3...v4.85.4)\n\n### Chores\n\n* **internal:** fix devcontainers setup ([#1343](https://github.com/openai/openai-node/issues/1343)) ([cb1ec90](https://github.com/openai/openai-node/commit/cb1ec907832e325bc29abe94ae325e0477cb87d1))\n\n## 4.85.3 (2025-02-20)\n\nFull Changelog: [v4.85.2...v4.85.3](https://github.com/openai/openai-node/compare/v4.85.2...v4.85.3)\n\n### Bug Fixes\n\n* **parsing:** remove tool_calls default empty array ([#1341](https://github.com/openai/openai-node/issues/1341)) ([2672160](https://github.com/openai/openai-node/commit/26721608e61949daa9592483e89b79230bb9198a))\n\n## 4.85.2 (2025-02-18)\n\nFull Changelog: [v4.85.1...v4.85.2](https://github.com/openai/openai-node/compare/v4.85.1...v4.85.2)\n\n### Bug Fixes\n\n* 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))\n\n## 4.85.1 (2025-02-14)\n\nFull Changelog: [v4.85.0...v4.85.1](https://github.com/openai/openai-node/compare/v4.85.0...v4.85.1)\n\n### Bug Fixes\n\n* **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))\n* **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))\n\n\n### Chores\n\n* **internal:** add missing return type annotation ([#1334](https://github.com/openai/openai-node/issues/1334)) ([53e0856](https://github.com/openai/openai-node/commit/53e0856ec4d36deee4d71b5aaf436df0a59b9402))\n\n## 4.85.0 (2025-02-13)\n\nFull Changelog: [v4.84.1...v4.85.0](https://github.com/openai/openai-node/compare/v4.84.1...v4.85.0)\n\n### Features\n\n* **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))\n\n\n### Bug Fixes\n\n* **realtime:** call .toString() on WebSocket url ([#1324](https://github.com/openai/openai-node/issues/1324)) ([09bc50d](https://github.com/openai/openai-node/commit/09bc50d439679b6acfd2441e69ee5aa18c00e5d9))\n\n## 4.84.1 (2025-02-13)\n\nFull Changelog: [v4.84.0...v4.84.1](https://github.com/openai/openai-node/compare/v4.84.0...v4.84.1)\n\n### Bug Fixes\n\n* **realtime:** correct websocket type var constraint ([#1321](https://github.com/openai/openai-node/issues/1321)) ([afb17ea](https://github.com/openai/openai-node/commit/afb17ea6497b860ebbe5d8e68e4a97681dd307ff))\n\n## 4.84.0 (2025-02-12)\n\nFull Changelog: [v4.83.0...v4.84.0](https://github.com/openai/openai-node/compare/v4.83.0...v4.84.0)\n\n### Features\n\n* **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))\n\n\n### Bug Fixes\n\n* **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))\n* **assistants:** handle `thread.run.incomplete` event ([7032cc4](https://github.com/openai/openai-node/commit/7032cc40b8aa0a58459cf114bceb8028a8517400))\n* 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))\n\n\n### Chores\n\n* **internal:** remove segfault-handler dependency ([3521ca3](https://github.com/openai/openai-node/commit/3521ca34e7f5bd51542084e27c084a5d7cc5448b))\n\n\n### Documentation\n\n* **readme:** cleanup into multiple files ([da94424](https://github.com/openai/openai-node/commit/da944242e542e9e5e51cb11853c621fc6825ac02))\n\n## 4.83.0 (2025-02-05)\n\nFull Changelog: [v4.82.0...v4.83.0](https://github.com/openai/openai-node/compare/v4.82.0...v4.83.0)\n\n### Features\n\n* **client:** send `X-Stainless-Timeout` header ([#1299](https://github.com/openai/openai-node/issues/1299)) ([ddfc686](https://github.com/openai/openai-node/commit/ddfc686f43a3420c3adf8dec2e82b4d10a121eb8))\n\n\n### Bug Fixes\n\n* **api/types:** correct audio duration & role types ([#1300](https://github.com/openai/openai-node/issues/1300)) ([a955ac2](https://github.com/openai/openai-node/commit/a955ac2bf5bee663d530d0c82b0005bf3ce6fc47))\n* **azure/audio:** use model param for deployments ([#1297](https://github.com/openai/openai-node/issues/1297)) ([85de382](https://github.com/openai/openai-node/commit/85de382db17cbe5f112650e79d0fc1cc841efbb2))\n\n## 4.82.0 (2025-01-31)\n\nFull Changelog: [v4.81.0...v4.82.0](https://github.com/openai/openai-node/compare/v4.81.0...v4.82.0)\n\n### Features\n\n* **api:** add o3-mini ([#1295](https://github.com/openai/openai-node/issues/1295)) ([378e2f7](https://github.com/openai/openai-node/commit/378e2f7af62c570adb4c7644a4d49576b698de41))\n\n\n### Bug Fixes\n\n* **examples/realtime:** remove duplicate `session.update` call ([#1293](https://github.com/openai/openai-node/issues/1293)) ([ad800b4](https://github.com/openai/openai-node/commit/ad800b4f9410c6838994c24a3386ea708717f72b))\n* **types:** correct metadata type + other fixes ([378e2f7](https://github.com/openai/openai-node/commit/378e2f7af62c570adb4c7644a4d49576b698de41))\n\n## 4.81.0 (2025-01-29)\n\nFull Changelog: [v4.80.1...v4.81.0](https://github.com/openai/openai-node/compare/v4.80.1...v4.81.0)\n\n### Features\n\n* **azure:** Realtime API support ([#1287](https://github.com/openai/openai-node/issues/1287)) ([fe090c0](https://github.com/openai/openai-node/commit/fe090c0a57570217eb0b431e2cce40bf61de2b75))\n\n## 4.80.1 (2025-01-24)\n\nFull Changelog: [v4.80.0...v4.80.1](https://github.com/openai/openai-node/compare/v4.80.0...v4.80.1)\n\n### Bug Fixes\n\n* **azure:** include retry count header ([3e0ba40](https://github.com/openai/openai-node/commit/3e0ba409e57ce276fb1f95cd11c801e4ccaad572))\n\n\n### Documentation\n\n* fix typo, \"zodFunctionTool\" -&gt; \"zodFunction\" ([#1128](https://github.com/openai/openai-node/issues/1128)) ([b7ab6bb](https://github.com/openai/openai-node/commit/b7ab6bb304973ade94830f37eb646e800226d5ef))\n* **helpers:** fix type annotation ([fc019df](https://github.com/openai/openai-node/commit/fc019df1d9cc276e8f8e689742853a09aa94991a))\n* **readme:** fix realtime errors docs link ([#1286](https://github.com/openai/openai-node/issues/1286)) ([d1d50c8](https://github.com/openai/openai-node/commit/d1d50c897c18cefea964e8057fe1acfd766ae2bf))\n\n## 4.80.0 (2025-01-22)\n\nFull Changelog: [v4.79.4...v4.80.0](https://github.com/openai/openai-node/compare/v4.79.4...v4.80.0)\n\n### Features\n\n* **api:** update enum values, comments, and examples ([#1280](https://github.com/openai/openai-node/issues/1280)) ([d38f2c2](https://github.com/openai/openai-node/commit/d38f2c2648b6990f217c3c7d83ca31f3739641d3))\n\n## 4.79.4 (2025-01-21)\n\nFull Changelog: [v4.79.3...v4.79.4](https://github.com/openai/openai-node/compare/v4.79.3...v4.79.4)\n\n### Bug Fixes\n\n* **jsr:** correct zod config ([e45fa5f](https://github.com/openai/openai-node/commit/e45fa5f535ca74789636001e60e33edcad4db83c))\n\n\n### Chores\n\n* **internal:** minor restructuring ([#1278](https://github.com/openai/openai-node/issues/1278)) ([58ea92a](https://github.com/openai/openai-node/commit/58ea92a7464a04223f24ba31dbc0f7d0cf99cc19))\n\n\n### Documentation\n\n* update deprecation messages ([#1275](https://github.com/openai/openai-node/issues/1275)) ([1c6599e](https://github.com/openai/openai-node/commit/1c6599e47ef75a71cb309a1e14d97bc97bd036d0))\n\n## 4.79.3 (2025-01-21)\n\nFull Changelog: [v4.79.2...v4.79.3](https://github.com/openai/openai-node/compare/v4.79.2...v4.79.3)\n\n### Bug Fixes\n\n* **jsr:** export zod helpers ([9dc55b6](https://github.com/openai/openai-node/commit/9dc55b62b564ad5ad1d4a60fe520b68235d05296))\n\n## 4.79.2 (2025-01-21)\n\nFull Changelog: [v4.79.1...v4.79.2](https://github.com/openai/openai-node/compare/v4.79.1...v4.79.2)\n\n### Chores\n\n* **internal:** add test ([#1270](https://github.com/openai/openai-node/issues/1270)) ([b7c2d3d](https://github.com/openai/openai-node/commit/b7c2d3d9abd315f1452a578b0fd0d82e6ac4ff60))\n\n\n### Documentation\n\n* **readme:** fix Realtime API example link ([#1272](https://github.com/openai/openai-node/issues/1272)) ([d0653c7](https://github.com/openai/openai-node/commit/d0653c7fef48360d137a7411dfdfb95d477cdbc5))\n\n## 4.79.1 (2025-01-17)\n\nFull Changelog: [v4.79.0...v4.79.1](https://github.com/openai/openai-node/compare/v4.79.0...v4.79.1)\n\n### Bug Fixes\n\n* **realtime:** correct import syntax ([#1267](https://github.com/openai/openai-node/issues/1267)) ([74702a7](https://github.com/openai/openai-node/commit/74702a739f566810d2b6c4e0832cfa17a1d1e272))\n\n## 4.79.0 (2025-01-17)\n\nFull Changelog: [v4.78.1...v4.79.0](https://github.com/openai/openai-node/compare/v4.78.1...v4.79.0)\n\n### Features\n\n* **client:** add Realtime API support ([#1266](https://github.com/openai/openai-node/issues/1266)) ([7160ebe](https://github.com/openai/openai-node/commit/7160ebe647769fbf48a600c9961d1a6f86dc9622))\n\n\n### Bug Fixes\n\n* **logs/azure:** redact sensitive header when DEBUG is set ([#1218](https://github.com/openai/openai-node/issues/1218)) ([6a72fd7](https://github.com/openai/openai-node/commit/6a72fd736733db19504a829bf203b39d5b9e3644))\n\n\n### Chores\n\n* fix streaming ([379c743](https://github.com/openai/openai-node/commit/379c7435ed5d508458e9cdc22386039b84fcec5e))\n* **internal:** streaming refactors ([#1261](https://github.com/openai/openai-node/issues/1261)) ([dd4af93](https://github.com/openai/openai-node/commit/dd4af939792583854a313367c5fe2f98eea2f3c8))\n* **types:** add `| undefined` to client options properties ([#1264](https://github.com/openai/openai-node/issues/1264)) ([5e56979](https://github.com/openai/openai-node/commit/5e569799b9ac8f915b16de90d91d38b568c1edce))\n* **types:** rename vector store chunking strategy ([#1263](https://github.com/openai/openai-node/issues/1263)) ([d31acee](https://github.com/openai/openai-node/commit/d31acee860c80ba945d4e70b956c7ed75f5f849a))\n\n## 4.78.1 (2025-01-10)\n\nFull Changelog: [v4.78.0...v4.78.1](https://github.com/openai/openai-node/compare/v4.78.0...v4.78.1)\n\n### Bug Fixes\n\n* send correct Accept header for certain endpoints ([#1257](https://github.com/openai/openai-node/issues/1257)) ([8756693](https://github.com/openai/openai-node/commit/8756693c5690b16045cdd8d33636fe7643d45f3a))\n\n## 4.78.0 (2025-01-09)\n\nFull Changelog: [v4.77.4...v4.78.0](https://github.com/openai/openai-node/compare/v4.77.4...v4.78.0)\n\n### Features\n\n* **client:** add realtime types ([#1254](https://github.com/openai/openai-node/issues/1254)) ([7130995](https://github.com/openai/openai-node/commit/71309957a9a0883cac84b8b57697b796a9df3503))\n\n## 4.77.4 (2025-01-08)\n\nFull Changelog: [v4.77.3...v4.77.4](https://github.com/openai/openai-node/compare/v4.77.3...v4.77.4)\n\n### Documentation\n\n* **readme:** fix misplaced period ([#1252](https://github.com/openai/openai-node/issues/1252)) ([c2fe465](https://github.com/openai/openai-node/commit/c2fe46522d59d1611ba8bb2b7e070f9be7264df0))\n\n## 4.77.3 (2025-01-03)\n\nFull Changelog: [v4.77.2...v4.77.3](https://github.com/openai/openai-node/compare/v4.77.2...v4.77.3)\n\n### Chores\n\n* **api:** bump spec version ([#1248](https://github.com/openai/openai-node/issues/1248)) ([37b3df9](https://github.com/openai/openai-node/commit/37b3df9ac6af76fea6eace8307aab9f0565e5660))\n\n## 4.77.2 (2025-01-02)\n\nFull Changelog: [v4.77.1...v4.77.2](https://github.com/openai/openai-node/compare/v4.77.1...v4.77.2)\n\n### Chores\n\n* bump license year ([#1246](https://github.com/openai/openai-node/issues/1246)) ([13197c1](https://github.com/openai/openai-node/commit/13197c1698f492529bd00b62d95f83c039ef0ac7))\n\n## 4.77.1 (2024-12-21)\n\nFull Changelog: [v4.77.0...v4.77.1](https://github.com/openai/openai-node/compare/v4.77.0...v4.77.1)\n\n### Bug Fixes\n\n* **client:** normalize method ([#1235](https://github.com/openai/openai-node/issues/1235)) ([4a213da](https://github.com/openai/openai-node/commit/4a213dad6f2104dc02a75724acc62134d25db472))\n\n\n### Chores\n\n* **internal:** spec update ([#1231](https://github.com/openai/openai-node/issues/1231)) ([a97ea73](https://github.com/openai/openai-node/commit/a97ea73cafcb56e94be7ff691c4022da575cf60e))\n\n\n### Documentation\n\n* minor formatting changes ([#1236](https://github.com/openai/openai-node/issues/1236)) ([6387968](https://github.com/openai/openai-node/commit/63879681ccaca3dc1e17b27464e2f830b8f63b4f))\n* **readme:** add alpha callout ([f2eff37](https://github.com/openai/openai-node/commit/f2eff3780e1216f7f420f7b86d47f4e21986b10e))\n\n## 4.77.0 (2024-12-17)\n\nFull Changelog: [v4.76.3...v4.77.0](https://github.com/openai/openai-node/compare/v4.76.3...v4.77.0)\n\n### Features\n\n* **api:** new o1 and GPT-4o models + preference fine-tuning ([#1229](https://github.com/openai/openai-node/issues/1229)) ([2e872d4](https://github.com/openai/openai-node/commit/2e872d4ac3717ab8f61741efffb7a31acd798338))\n\n\n### Chores\n\n* **internal:** fix some typos ([#1227](https://github.com/openai/openai-node/issues/1227)) ([d51fcfe](https://github.com/openai/openai-node/commit/d51fcfe3a66550a684eeeb0e6f17e1d9825cdf78))\n* **internal:** spec update ([#1230](https://github.com/openai/openai-node/issues/1230)) ([ed2b61d](https://github.com/openai/openai-node/commit/ed2b61d32703b64d9f91223bc02627a607f60483))\n\n## 4.76.3 (2024-12-13)\n\nFull Changelog: [v4.76.2...v4.76.3](https://github.com/openai/openai-node/compare/v4.76.2...v4.76.3)\n\n### Chores\n\n* **internal:** better ecosystem test debugging ([86fc0a8](https://github.com/openai/openai-node/commit/86fc0a81ede2780d3fcebaabff3d9fa9a36cc9c0))\n\n\n### Documentation\n\n* **README:** fix helpers section links ([#1224](https://github.com/openai/openai-node/issues/1224)) ([efbe30a](https://github.com/openai/openai-node/commit/efbe30a156cec1836d3db28f663066b33be57ba2))\n\n## 4.76.2 (2024-12-12)\n\nFull Changelog: [v4.76.1...v4.76.2](https://github.com/openai/openai-node/compare/v4.76.1...v4.76.2)\n\n### Chores\n\n* **internal:** update isAbsoluteURL ([#1223](https://github.com/openai/openai-node/issues/1223)) ([e908ed7](https://github.com/openai/openai-node/commit/e908ed759996fb7706baf46d094fc77419423971))\n* **types:** nicer error class types + jsdocs ([#1219](https://github.com/openai/openai-node/issues/1219)) ([576d24c](https://github.com/openai/openai-node/commit/576d24cc4b3d766dfe28a6031bdc24ac1b711655))\n\n## 4.76.1 (2024-12-10)\n\nFull Changelog: [v4.76.0...v4.76.1](https://github.com/openai/openai-node/compare/v4.76.0...v4.76.1)\n\n### Chores\n\n* **internal:** bump cross-spawn to v7.0.6 ([#1217](https://github.com/openai/openai-node/issues/1217)) ([c07ad29](https://github.com/openai/openai-node/commit/c07ad298d58e5aeaf816ee3de65fd59bf3fc8b66))\n* **internal:** remove unnecessary getRequestClient function ([#1215](https://github.com/openai/openai-node/issues/1215)) ([bef3925](https://github.com/openai/openai-node/commit/bef392526cd339f45c574bc476649c77be36c612))\n\n## 4.76.0 (2024-12-05)\n\nFull Changelog: [v4.75.0...v4.76.0](https://github.com/openai/openai-node/compare/v4.75.0...v4.76.0)\n\n### Features\n\n* **api:** updates ([#1212](https://github.com/openai/openai-node/issues/1212)) ([e0fedf2](https://github.com/openai/openai-node/commit/e0fedf2c5a91d0c03d8dad6854b366f77eab4923))\n\n\n### Chores\n\n* bump openapi url ([#1210](https://github.com/openai/openai-node/issues/1210)) ([3fa95a4](https://github.com/openai/openai-node/commit/3fa95a429d4b2adecce35a7b96b73f6d5e88eeeb))\n\n## 4.75.0 (2024-12-03)\n\nFull Changelog: [v4.74.0...v4.75.0](https://github.com/openai/openai-node/compare/v4.74.0...v4.75.0)\n\n### Features\n\n* improve docs for jsr README.md ([#1208](https://github.com/openai/openai-node/issues/1208)) ([338527e](https://github.com/openai/openai-node/commit/338527e40361e2de899a63f280d4ec2db5e87f3c))\n\n## 4.74.0 (2024-12-02)\n\nFull Changelog: [v4.73.1...v4.74.0](https://github.com/openai/openai-node/compare/v4.73.1...v4.74.0)\n\n### Features\n\n* **internal:** make git install file structure match npm ([#1204](https://github.com/openai/openai-node/issues/1204)) ([e7c4c6d](https://github.com/openai/openai-node/commit/e7c4c6d23adbe52300053a8d35db6e341c438703))\n\n## 4.73.1 (2024-11-25)\n\nFull Changelog: [v4.73.0...v4.73.1](https://github.com/openai/openai-node/compare/v4.73.0...v4.73.1)\n\n### Documentation\n\n* **readme:** mention `.withResponse()` for streaming request ID ([#1202](https://github.com/openai/openai-node/issues/1202)) ([b6800d4](https://github.com/openai/openai-node/commit/b6800d4dea2729fe3b0864171ce8fb3b2cc1b21c))\n\n## 4.73.0 (2024-11-20)\n\nFull Changelog: [v4.72.0...v4.73.0](https://github.com/openai/openai-node/compare/v4.72.0...v4.73.0)\n\n### Features\n\n* **api:** add gpt-4o-2024-11-20 model ([#1201](https://github.com/openai/openai-node/issues/1201)) ([0feeafd](https://github.com/openai/openai-node/commit/0feeafd21ba4b6281cc3b9dafa2919b1e2e4d1c3))\n* bump model in all example snippets to gpt-4o ([6961c37](https://github.com/openai/openai-node/commit/6961c37f2e581bcc12ec2bbe77df2b9b260fe297))\n\n\n### Bug Fixes\n\n* **docs:** add missing await to pagination example ([#1190](https://github.com/openai/openai-node/issues/1190)) ([524b9e8](https://github.com/openai/openai-node/commit/524b9e82ae13a3b5093dcfbfd1169a798cf99ab4))\n\n\n### Chores\n\n* **client:** drop unused devDependency ([#1191](https://github.com/openai/openai-node/issues/1191)) ([8ee6c03](https://github.com/openai/openai-node/commit/8ee6c0335673f2ecf84ea11bdfc990adab607e20))\n* **internal:** spec update ([#1195](https://github.com/openai/openai-node/issues/1195)) ([12f9334](https://github.com/openai/openai-node/commit/12f93346857196b93f94865cc3744d769e5e519c))\n* **internal:** use reexports not destructuring ([#1181](https://github.com/openai/openai-node/issues/1181)) ([f555dd6](https://github.com/openai/openai-node/commit/f555dd6503bc4ccd4d13f4e1a1d36fbbfd51c369))\n\n\n### Documentation\n\n* bump models in example snippets to gpt-4o ([#1184](https://github.com/openai/openai-node/issues/1184)) ([4ec4027](https://github.com/openai/openai-node/commit/4ec402790cf3cfbccbf3ef9b61d577b0118977e8))\n* change readme title ([#1198](https://github.com/openai/openai-node/issues/1198)) ([e34981c](https://github.com/openai/openai-node/commit/e34981c00f2f0360baffe870bcc38786030671bf))\n* improve jsr documentation ([#1197](https://github.com/openai/openai-node/issues/1197)) ([ebdb4f7](https://github.com/openai/openai-node/commit/ebdb4f72cc01afbee649aca009fdaf413e61c507))\n* **readme:** fix incorrect fileBatches.uploadAndPoll params ([#1200](https://github.com/openai/openai-node/issues/1200)) ([3968ef1](https://github.com/openai/openai-node/commit/3968ef1c4fa860ff246e0e803808752b261c18ce))\n\n## 4.72.0 (2024-11-12)\n\nFull Changelog: [v4.71.1...v4.72.0](https://github.com/openai/openai-node/compare/v4.71.1...v4.72.0)\n\n### Features\n\n* add back deno runtime testing without type checks ([1626cf5](https://github.com/openai/openai-node/commit/1626cf57e94706e1fc8b2f9ff4f173fe486d5150))\n\n\n### Chores\n\n* **ecosystem-tests:** bump wrangler version ([#1178](https://github.com/openai/openai-node/issues/1178)) ([4dfb0c6](https://github.com/openai/openai-node/commit/4dfb0c6aa7c4530665bc7d6beebcd04aa1490e27))\n\n## 4.71.1 (2024-11-06)\n\nFull Changelog: [v4.71.0...v4.71.1](https://github.com/openai/openai-node/compare/v4.71.0...v4.71.1)\n\n### Bug Fixes\n\n* change release please configuration for jsr.json ([#1174](https://github.com/openai/openai-node/issues/1174)) ([c39efba](https://github.com/openai/openai-node/commit/c39efba812209c8906315596cc0a56e54ae8590a))\n\n## 4.71.0 (2024-11-04)\n\nFull Changelog: [v4.70.3...v4.71.0](https://github.com/openai/openai-node/compare/v4.70.3...v4.71.0)\n\n### Features\n\n* **api:** add support for predicted outputs ([#1172](https://github.com/openai/openai-node/issues/1172)) ([08a7bb4](https://github.com/openai/openai-node/commit/08a7bb4d4b751aeed9655bfcb9fa27fc79a767c4))\n\n## 4.70.3 (2024-11-04)\n\nFull Changelog: [v4.70.2...v4.70.3](https://github.com/openai/openai-node/compare/v4.70.2...v4.70.3)\n\n### Bug Fixes\n\n* change streaming helper imports to be relative ([e73b7cf](https://github.com/openai/openai-node/commit/e73b7cf84272bd02a39a67795d49db23db2d970f))\n\n## 4.70.2 (2024-11-01)\n\nFull Changelog: [v4.70.1...v4.70.2](https://github.com/openai/openai-node/compare/v4.70.1...v4.70.2)\n\n### Bug Fixes\n\n* add permissions to github workflow ([ee75e00](https://github.com/openai/openai-node/commit/ee75e00b0fbf82553b219ee8948a8077e9c26a24))\n* skip deno ecosystem test ([5b181b0](https://github.com/openai/openai-node/commit/5b181b01b62139f8da35d426914c82b8425af141))\n\n## 4.70.1 (2024-11-01)\n\nFull Changelog: [v4.70.0...v4.70.1](https://github.com/openai/openai-node/compare/v4.70.0...v4.70.1)\n\n### Bug Fixes\n\n* don't require deno to run build-deno ([#1167](https://github.com/openai/openai-node/issues/1167)) ([9d857bc](https://github.com/openai/openai-node/commit/9d857bc531a0bb3939f7660e49b31ccc38f60dd3))\n\n## 4.70.0 (2024-11-01)\n\nFull Changelog: [v4.69.0...v4.70.0](https://github.com/openai/openai-node/compare/v4.69.0...v4.70.0)\n\n### Features\n\n* publish to jsr ([#1165](https://github.com/openai/openai-node/issues/1165)) ([5aa93a7](https://github.com/openai/openai-node/commit/5aa93a7fe704ef1ad077787852db38dc29104534))\n\n\n### Chores\n\n* **internal:** fix isolated modules exports ([9cd1958](https://github.com/openai/openai-node/commit/9cd19584dcc6f4004ea1adcee917aa88a37d5f1c))\n\n\n### Refactors\n\n* use type imports for type-only imports ([#1159](https://github.com/openai/openai-node/issues/1159)) ([07bbaf6](https://github.com/openai/openai-node/commit/07bbaf6ecac9a5e36471a35488020853ddf9214f))\n\n## 4.69.0 (2024-10-30)\n\nFull Changelog: [v4.68.4...v4.69.0](https://github.com/openai/openai-node/compare/v4.68.4...v4.69.0)\n\n### Features\n\n* **api:** add new, expressive voices for Realtime and Audio in Chat Completions ([#1157](https://github.com/openai/openai-node/issues/1157)) ([12e501c](https://github.com/openai/openai-node/commit/12e501c8a215a2af29b9b8fceedc5935b6f2feef))\n\n\n### Bug Fixes\n\n* **internal:** support pnpm git installs ([#1156](https://github.com/openai/openai-node/issues/1156)) ([b744c5b](https://github.com/openai/openai-node/commit/b744c5b609533e9a6694d6cae0425fe9cd37e26c))\n\n\n### Documentation\n\n* **readme:** minor typo fixes ([#1154](https://github.com/openai/openai-node/issues/1154)) ([c6c9f9a](https://github.com/openai/openai-node/commit/c6c9f9aaf75f643016ad73574a7e24a228b5c60f))\n\n## 4.68.4 (2024-10-23)\n\nFull Changelog: [v4.68.3...v4.68.4](https://github.com/openai/openai-node/compare/v4.68.3...v4.68.4)\n\n### Chores\n\n* **internal:** update spec version ([#1146](https://github.com/openai/openai-node/issues/1146)) ([0165a8d](https://github.com/openai/openai-node/commit/0165a8d79340ede49557e05fd00d6fff9d69d930))\n\n## 4.68.3 (2024-10-23)\n\nFull Changelog: [v4.68.2...v4.68.3](https://github.com/openai/openai-node/compare/v4.68.2...v4.68.3)\n\n### Chores\n\n* **internal:** bumps eslint and related dependencies ([#1143](https://github.com/openai/openai-node/issues/1143)) ([2643f42](https://github.com/openai/openai-node/commit/2643f42a36208c36daf23470ffcd227a891284eb))\n\n## 4.68.2 (2024-10-22)\n\nFull Changelog: [v4.68.1...v4.68.2](https://github.com/openai/openai-node/compare/v4.68.1...v4.68.2)\n\n### Chores\n\n* **internal:** update spec version ([#1141](https://github.com/openai/openai-node/issues/1141)) ([2ccb3e3](https://github.com/openai/openai-node/commit/2ccb3e357aa2f3eb0fa32c619d8336c3b94cc882))\n\n## 4.68.1 (2024-10-18)\n\nFull Changelog: [v4.68.0...v4.68.1](https://github.com/openai/openai-node/compare/v4.68.0...v4.68.1)\n\n### Bug Fixes\n\n* **client:** respect x-stainless-retry-count default headers ([#1138](https://github.com/openai/openai-node/issues/1138)) ([266717b](https://github.com/openai/openai-node/commit/266717b3301828c7df735064a380a055576183bc))\n\n## 4.68.0 (2024-10-17)\n\nFull Changelog: [v4.67.3...v4.68.0](https://github.com/openai/openai-node/compare/v4.67.3...v4.68.0)\n\n### Features\n\n* **api:** add gpt-4o-audio-preview model for chat completions ([#1135](https://github.com/openai/openai-node/issues/1135)) ([17a623f](https://github.com/openai/openai-node/commit/17a623f70050bca4538ad2939055cd9d9b165f89))\n\n## 4.67.3 (2024-10-08)\n\nFull Changelog: [v4.67.2...v4.67.3](https://github.com/openai/openai-node/compare/v4.67.2...v4.67.3)\n\n### Chores\n\n* **internal:** pass props through internal parser ([#1125](https://github.com/openai/openai-node/issues/1125)) ([5ef8aa8](https://github.com/openai/openai-node/commit/5ef8aa8d308f7374dd01d8079cd76e0d96999ec2))\n\n## 4.67.2 (2024-10-07)\n\nFull Changelog: [v4.67.1...v4.67.2](https://github.com/openai/openai-node/compare/v4.67.1...v4.67.2)\n\n### Chores\n\n* **internal:** move LineDecoder to a separate file ([#1120](https://github.com/openai/openai-node/issues/1120)) ([0a4be65](https://github.com/openai/openai-node/commit/0a4be6506bf26d2b9552ff3fd13a22c04b53ea18))\n\n## 4.67.1 (2024-10-02)\n\nFull Changelog: [v4.67.0...v4.67.1](https://github.com/openai/openai-node/compare/v4.67.0...v4.67.1)\n\n### Documentation\n\n* improve and reference contributing documentation ([#1115](https://github.com/openai/openai-node/issues/1115)) ([7fa30b3](https://github.com/openai/openai-node/commit/7fa30b3ebf276556141df95ba8e824a0276b61f8))\n\n## 4.67.0 (2024-10-01)\n\nFull Changelog: [v4.66.1...v4.67.0](https://github.com/openai/openai-node/compare/v4.66.1...v4.67.0)\n\n### Features\n\n* **api:** support storing chat completions, enabling evals and model distillation in the dashboard ([#1112](https://github.com/openai/openai-node/issues/1112)) ([6424924](https://github.com/openai/openai-node/commit/6424924b6361e54f07c04fce9075ab16fcb712fb))\n\n## 4.66.1 (2024-09-30)\n\nFull Changelog: [v4.66.0...v4.66.1](https://github.com/openai/openai-node/compare/v4.66.0...v4.66.1)\n\n### Bug Fixes\n\n* **audio:** add fallback overload types ([0c00a13](https://github.com/openai/openai-node/commit/0c00a13dd864b974d3376c905647209e4a79f244))\n* **audio:** use export type ([1519100](https://github.com/openai/openai-node/commit/1519100e530e08e7683549d0bcdd919b9c2d1654))\n\n## 4.66.0 (2024-09-27)\n\nFull Changelog: [v4.65.0...v4.66.0](https://github.com/openai/openai-node/compare/v4.65.0...v4.66.0)\n\n### Features\n\n* **client:** add request_id to `.withResponse()` ([#1095](https://github.com/openai/openai-node/issues/1095)) ([2d0f565](https://github.com/openai/openai-node/commit/2d0f565f124a8862bc24214cc3ddce9db0ba75bc))\n\n\n### Bug Fixes\n\n* **audio:** correct types for transcriptions / translations ([#1104](https://github.com/openai/openai-node/issues/1104)) ([96e86c2](https://github.com/openai/openai-node/commit/96e86c214ba79d50035b61e5daa3489f082512c4))\n* **client:** correct types for transcriptions / translations ([#1105](https://github.com/openai/openai-node/issues/1105)) ([fa16ebb](https://github.com/openai/openai-node/commit/fa16ebbb314ebc7c274d27f0148d248edf48e055))\n\n## 4.65.0 (2024-09-26)\n\nFull Changelog: [v4.64.0...v4.65.0](https://github.com/openai/openai-node/compare/v4.64.0...v4.65.0)\n\n### Features\n\n* **api:** add omni-moderation model ([#1100](https://github.com/openai/openai-node/issues/1100)) ([66c0f21](https://github.com/openai/openai-node/commit/66c0f21fad3be9c57b810c4a7eebb71eb6ccbcc1))\n\n## 4.64.0 (2024-09-25)\n\nFull Changelog: [v4.63.0...v4.64.0](https://github.com/openai/openai-node/compare/v4.63.0...v4.64.0)\n\n### Features\n\n* **client:** allow overriding retry count header ([#1098](https://github.com/openai/openai-node/issues/1098)) ([a466ff7](https://github.com/openai/openai-node/commit/a466ff78a436db82d79a8f53066a85a3b1dbe039))\n\n\n### Bug Fixes\n\n* **audio:** correct response_format translations type ([#1097](https://github.com/openai/openai-node/issues/1097)) ([9a5f461](https://github.com/openai/openai-node/commit/9a5f461306e84b62ce1ed8aedbfee90798def5fb))\n\n\n### Chores\n\n* **internal:** fix ecosystem tests error output ([#1096](https://github.com/openai/openai-node/issues/1096)) ([ecdb4e9](https://github.com/openai/openai-node/commit/ecdb4e923f94e828d8758559aea78c82417b8f12))\n* **internal:** fix slow ecosystem test ([#1093](https://github.com/openai/openai-node/issues/1093)) ([80ed9ec](https://github.com/openai/openai-node/commit/80ed9ecbd60129164cb407e46dddbc06ef1c54ab))\n\n## 4.63.0 (2024-09-20)\n\nFull Changelog: [v4.62.1...v4.63.0](https://github.com/openai/openai-node/compare/v4.62.1...v4.63.0)\n\n### Features\n\n* **client:** send retry count header ([#1087](https://github.com/openai/openai-node/issues/1087)) ([7bcebc0](https://github.com/openai/openai-node/commit/7bcebc0e3965c2decd1dffb1e67f5197260ca89e))\n\n\n### Chores\n\n* **types:** improve type name for embedding models ([#1089](https://github.com/openai/openai-node/issues/1089)) ([d6966d9](https://github.com/openai/openai-node/commit/d6966d9872a14b7fbee85a7bb1fae697852b8ce0))\n\n## 4.62.1 (2024-09-18)\n\nFull Changelog: [v4.62.0...v4.62.1](https://github.com/openai/openai-node/compare/v4.62.0...v4.62.1)\n\n### Bug Fixes\n\n* **types:** remove leftover polyfill usage ([#1084](https://github.com/openai/openai-node/issues/1084)) ([b7c9538](https://github.com/openai/openai-node/commit/b7c9538981a11005fb0a00774683d979d3ca663a))\n\n## 4.62.0 (2024-09-17)\n\nFull Changelog: [v4.61.1...v4.62.0](https://github.com/openai/openai-node/compare/v4.61.1...v4.62.0)\n\n### Features\n\n* **client:** add ._request_id property to object responses ([#1078](https://github.com/openai/openai-node/issues/1078)) ([d5c2131](https://github.com/openai/openai-node/commit/d5c21314449091dd1c668c7358b25e041466f588))\n\n\n### Chores\n\n* **internal:** add ecosystem test for qs reproduction ([0199dd8](https://github.com/openai/openai-node/commit/0199dd85981497fac2b60f786acc00ea30683897))\n* **internal:** add query string encoder ([#1079](https://github.com/openai/openai-node/issues/1079)) ([f870682](https://github.com/openai/openai-node/commit/f870682d5c490182547c428b0b5c75da0e34d15a))\n* **internal:** fix some types ([#1082](https://github.com/openai/openai-node/issues/1082)) ([1ec41a7](https://github.com/openai/openai-node/commit/1ec41a7d768502a31abb33bf86b0539e5b4b6541))\n* **tests:** add query string tests to ecosystem tests ([36be724](https://github.com/openai/openai-node/commit/36be724384401bb697d8b07b0a1965be721cfa51))\n\n## 4.61.1 (2024-09-16)\n\nFull Changelog: [v4.61.0...v4.61.1](https://github.com/openai/openai-node/compare/v4.61.0...v4.61.1)\n\n### Bug Fixes\n\n* **runTools:** correct request options type ([#1073](https://github.com/openai/openai-node/issues/1073)) ([399f971](https://github.com/openai/openai-node/commit/399f9710f9a1406fe2dd048a1d26418c0de7ff0c))\n\n\n### Chores\n\n* **internal:** update spec link ([#1076](https://github.com/openai/openai-node/issues/1076)) ([20f1bcc](https://github.com/openai/openai-node/commit/20f1bcce2b5d03c5185989212a5c5271a8d4209c))\n\n## 4.61.0 (2024-09-13)\n\nFull Changelog: [v4.60.1...v4.61.0](https://github.com/openai/openai-node/compare/v4.60.1...v4.61.0)\n\n### Bug Fixes\n\n* **client:** partial parsing update to handle strings ([46e8eb6](https://github.com/openai/openai-node/commit/46e8eb6a9a45b11f9e4c97474ed6c02b1faa43af))\n* **examples:** handle usage chunk in tool call streaming ([#1068](https://github.com/openai/openai-node/issues/1068)) ([e4188c4](https://github.com/openai/openai-node/commit/e4188c4ba443a21d1ef94658df5366f80f0e573b))\n\n\n### Chores\n\n* **examples:** add a small delay to tool-calls example streaming ([a3fc659](https://github.com/openai/openai-node/commit/a3fc65928af7085d1d8d785ad4765fedc3955641))\n\n\n### Documentation\n\n* update CONTRIBUTING.md ([#1071](https://github.com/openai/openai-node/issues/1071)) ([5de81c9](https://github.com/openai/openai-node/commit/5de81c95d7326602865e007715a76d5595824fd9))\n\n## 4.60.1 (2024-09-13)\n\nFull Changelog: [v4.60.0...v4.60.1](https://github.com/openai/openai-node/compare/v4.60.0...v4.60.1)\n\n### Bug Fixes\n\n* **zod:** correctly add $ref definitions for transformed schemas ([#1065](https://github.com/openai/openai-node/issues/1065)) ([9b93b24](https://github.com/openai/openai-node/commit/9b93b24b8ae267fe403fb9cd4876d9772f40878b))\n\n## 4.60.0 (2024-09-12)\n\nFull Changelog: [v4.59.0...v4.60.0](https://github.com/openai/openai-node/compare/v4.59.0...v4.60.0)\n\n### Features\n\n* **api:** add o1 models ([#1061](https://github.com/openai/openai-node/issues/1061)) ([224cc04](https://github.com/openai/openai-node/commit/224cc045200cd1ce1517b4376c505de9b9a74ccc))\n\n## 4.59.0 (2024-09-11)\n\nFull Changelog: [v4.58.2...v4.59.0](https://github.com/openai/openai-node/compare/v4.58.2...v4.59.0)\n\n### Features\n\n* **structured outputs:** support accessing raw responses ([#1058](https://github.com/openai/openai-node/issues/1058)) ([af17697](https://github.com/openai/openai-node/commit/af176979894ee95a51e09abc239a8fd3a639dcde))\n\n\n### Documentation\n\n* **azure:** example for custom base URL ([#1055](https://github.com/openai/openai-node/issues/1055)) ([20defc8](https://github.com/openai/openai-node/commit/20defc80801e1f1f489a07bd1264be71c56c586f))\n* **azure:** remove locale from docs link ([#1054](https://github.com/openai/openai-node/issues/1054)) ([f9b7eac](https://github.com/openai/openai-node/commit/f9b7eac58020cff0e367a15b9a2ca4e7c95cbb89))\n\n## 4.58.2 (2024-09-09)\n\nFull Changelog: [v4.58.1...v4.58.2](https://github.com/openai/openai-node/compare/v4.58.1...v4.58.2)\n\n### Bug Fixes\n\n* **errors:** pass message through to APIConnectionError ([#1050](https://github.com/openai/openai-node/issues/1050)) ([5a34316](https://github.com/openai/openai-node/commit/5a3431672e200a6bc161d39873e914434557801e))\n\n\n### Chores\n\n* better object fallback behaviour for casting errors ([#1053](https://github.com/openai/openai-node/issues/1053)) ([b7d4619](https://github.com/openai/openai-node/commit/b7d46190d2bb775145a9a3de6408c38abacfa055))\n\n## 4.58.1 (2024-09-06)\n\nFull Changelog: [v4.58.0...v4.58.1](https://github.com/openai/openai-node/compare/v4.58.0...v4.58.1)\n\n### Chores\n\n* **docs:** update browser support information ([#1045](https://github.com/openai/openai-node/issues/1045)) ([d326cc5](https://github.com/openai/openai-node/commit/d326cc54a77c450672fbf07d736cec80a9ba72fb))\n\n## 4.58.0 (2024-09-05)\n\nFull Changelog: [v4.57.3...v4.58.0](https://github.com/openai/openai-node/compare/v4.57.3...v4.58.0)\n\n### Features\n\n* **vector store:** improve chunking strategy type names ([#1041](https://github.com/openai/openai-node/issues/1041)) ([471cec3](https://github.com/openai/openai-node/commit/471cec3228886253f07c13a362827a31e9ec7b63))\n\n\n### Bug Fixes\n\n* **uploads:** avoid making redundant memory copies ([#1043](https://github.com/openai/openai-node/issues/1043)) ([271297b](https://github.com/openai/openai-node/commit/271297bd32393d4c5663023adf82f8fb19dc3d25))\n\n## 4.57.3 (2024-09-04)\n\nFull Changelog: [v4.57.2...v4.57.3](https://github.com/openai/openai-node/compare/v4.57.2...v4.57.3)\n\n### Bug Fixes\n\n* **helpers/zod:** avoid import issue in certain environments ([#1039](https://github.com/openai/openai-node/issues/1039)) ([e238daa](https://github.com/openai/openai-node/commit/e238daa7c12f3fb13369f58b9d405365f5efcc8f))\n\n\n### Chores\n\n* **internal:** minor bump qs version ([#1037](https://github.com/openai/openai-node/issues/1037)) ([8ec218e](https://github.com/openai/openai-node/commit/8ec218e9efb657927b3c0346822a96872aeaf137))\n\n## 4.57.2 (2024-09-04)\n\nFull Changelog: [v4.57.1...v4.57.2](https://github.com/openai/openai-node/compare/v4.57.1...v4.57.2)\n\n### Chores\n\n* **internal:** dependency updates ([#1035](https://github.com/openai/openai-node/issues/1035)) ([e815fb6](https://github.com/openai/openai-node/commit/e815fb6dee75219563d3a7776774ba1c2984560e))\n\n## 4.57.1 (2024-09-03)\n\nFull Changelog: [v4.57.0...v4.57.1](https://github.com/openai/openai-node/compare/v4.57.0...v4.57.1)\n\n### Bug Fixes\n\n* **assistants:** correctly accumulate tool calls when streaming ([#1031](https://github.com/openai/openai-node/issues/1031)) ([d935ad3](https://github.com/openai/openai-node/commit/d935ad3fa37b2701f4c9f6e433ada6074280a871))\n* **client:** correct File construction from node-fetch Responses ([#1029](https://github.com/openai/openai-node/issues/1029)) ([22ebdc2](https://github.com/openai/openai-node/commit/22ebdc2ca7d98e0f266110c4cf827e53a0a22026))\n* runTools without stream should not emit user message events ([#1005](https://github.com/openai/openai-node/issues/1005)) ([22ded4d](https://github.com/openai/openai-node/commit/22ded4d549a157482a8de2faf65e92c5be07fa95))\n\n\n### Chores\n\n* **internal/tests:** workaround bug in recent types/node release ([3c7bdfd](https://github.com/openai/openai-node/commit/3c7bdfdb373bff77db0e3fecd5d49ddfa4284cd9))\n\n## 4.57.0 (2024-08-29)\n\nFull Changelog: [v4.56.2...v4.57.0](https://github.com/openai/openai-node/compare/v4.56.2...v4.57.0)\n\n### Features\n\n* **api:** add file search result details to run steps ([#1023](https://github.com/openai/openai-node/issues/1023)) ([d9acd0a](https://github.com/openai/openai-node/commit/d9acd0a2c52b27983f8db6a8de6a776078b1d41b))\n\n\n### Bug Fixes\n\n* install examples deps as part of bootstrap script ([#1022](https://github.com/openai/openai-node/issues/1022)) ([eae8e36](https://github.com/openai/openai-node/commit/eae8e36fd5514eb60773646ec775badde50e783c))\n\n## 4.56.2 (2024-08-29)\n\nFull Changelog: [v4.56.1...v4.56.2](https://github.com/openai/openai-node/compare/v4.56.1...v4.56.2)\n\n### Chores\n\n* run tsc as part of lint script ([#1020](https://github.com/openai/openai-node/issues/1020)) ([4942347](https://github.com/openai/openai-node/commit/49423472f2b0a0b63961174bedfc00bfd99d47f9))\n\n## 4.56.1 (2024-08-27)\n\nFull Changelog: [v4.56.0...v4.56.1](https://github.com/openai/openai-node/compare/v4.56.0...v4.56.1)\n\n### Chores\n\n* **ci:** check for build errors ([#1013](https://github.com/openai/openai-node/issues/1013)) ([7ff2127](https://github.com/openai/openai-node/commit/7ff21273091a605e05173502654cfb9c90a4382e))\n\n## 4.56.0 (2024-08-16)\n\nFull Changelog: [v4.55.9...v4.56.0](https://github.com/openai/openai-node/compare/v4.55.9...v4.56.0)\n\n### Features\n\n* **api:** add chatgpt-4o-latest model ([edc4398](https://github.com/openai/openai-node/commit/edc43986ba96a0fda48f7eea368efe706f68dcac))\n\n## 4.55.9 (2024-08-16)\n\nFull Changelog: [v4.55.8...v4.55.9](https://github.com/openai/openai-node/compare/v4.55.8...v4.55.9)\n\n### Bug Fixes\n\n* **azure/tts:** avoid stripping model param ([#999](https://github.com/openai/openai-node/issues/999)) ([c3a7ccd](https://github.com/openai/openai-node/commit/c3a7ccdbd6d9a2576509c2dc6c1605bc73c6dde7))\n\n## 4.55.8 (2024-08-15)\n\nFull Changelog: [v4.55.7...v4.55.8](https://github.com/openai/openai-node/compare/v4.55.7...v4.55.8)\n\n### Chores\n\n* **types:** define FilePurpose enum ([#997](https://github.com/openai/openai-node/issues/997)) ([19b941b](https://github.com/openai/openai-node/commit/19b941be4ff3e4fa7e67b820a5aac51e5c8d4f60))\n\n## 4.55.7 (2024-08-13)\n\nFull Changelog: [v4.55.6...v4.55.7](https://github.com/openai/openai-node/compare/v4.55.6...v4.55.7)\n\n### Bug Fixes\n\n* **json-schema:** correct handling of nested recursive schemas ([#992](https://github.com/openai/openai-node/issues/992)) ([ac309ab](https://github.com/openai/openai-node/commit/ac309abee3419594f45680c7d0ab11e13ce28c5b))\n\n## 4.55.6 (2024-08-13)\n\nFull Changelog: [v4.55.5...v4.55.6](https://github.com/openai/openai-node/compare/v4.55.5...v4.55.6)\n\n### Bug Fixes\n\n* **zod-to-json-schema:** correct licensing ([#986](https://github.com/openai/openai-node/issues/986)) ([bd2051e](https://github.com/openai/openai-node/commit/bd2051e501e2ceafcd095f82205c2e668e1d68d7))\n\n## 4.55.5 (2024-08-12)\n\nFull Changelog: [v4.55.4...v4.55.5](https://github.com/openai/openai-node/compare/v4.55.4...v4.55.5)\n\n### Chores\n\n* **examples:** minor formatting changes ([#987](https://github.com/openai/openai-node/issues/987)) ([8e6b615](https://github.com/openai/openai-node/commit/8e6b615ada09fa4e50dc8e0b5decf662eed19856))\n* sync openapi url ([#989](https://github.com/openai/openai-node/issues/989)) ([02ff1c5](https://github.com/openai/openai-node/commit/02ff1c55b5eefd8b6193ba2bf10dd5515945bd7a))\n\n## 4.55.4 (2024-08-09)\n\nFull Changelog: [v4.55.3...v4.55.4](https://github.com/openai/openai-node/compare/v4.55.3...v4.55.4)\n\n### Bug Fixes\n\n* **helpers/zod:** nested union schema extraction ([#979](https://github.com/openai/openai-node/issues/979)) ([31b05aa](https://github.com/openai/openai-node/commit/31b05aa6fa0445141ae17a1b1eff533b83735f3a))\n\n\n### Chores\n\n* **ci:** bump prism mock server version ([#982](https://github.com/openai/openai-node/issues/982)) ([7442643](https://github.com/openai/openai-node/commit/7442643e8445eea15da54843a7c9d7580a402979))\n* **ci:** codeowners file ([#980](https://github.com/openai/openai-node/issues/980)) ([17a42b2](https://github.com/openai/openai-node/commit/17a42b2f6e2de2dce338358a48f6d7d4ed723f6f))\n\n## 4.55.3 (2024-08-08)\n\nFull Changelog: [v4.55.2...v4.55.3](https://github.com/openai/openai-node/compare/v4.55.2...v4.55.3)\n\n### Chores\n\n* **internal:** updates ([#975](https://github.com/openai/openai-node/issues/975)) ([313a190](https://github.com/openai/openai-node/commit/313a19059a61893887ac0b57bb488c24bc40f099))\n\n## 4.55.2 (2024-08-08)\n\nFull Changelog: [v4.55.1...v4.55.2](https://github.com/openai/openai-node/compare/v4.55.1...v4.55.2)\n\n### Bug Fixes\n\n* **helpers/zod:** add `extract-to-root` ref strategy ([ef3c73c](https://github.com/openai/openai-node/commit/ef3c73cfdf1a8e45346417812168e476fea65690))\n* **helpers/zod:** add `nullableStrategy` option ([ad89892](https://github.com/openai/openai-node/commit/ad89892f4ac0daba161ce97267a165a12f67c341))\n* **helpers/zod:** correct logic for adding root schema to definitions ([e4a247a](https://github.com/openai/openai-node/commit/e4a247a2a87b4d3bde55891b31e07413d3a9f00d))\n\n\n### Chores\n\n* **internal:** add README for vendored zod-to-json-schema ([d8a80a9](https://github.com/openai/openai-node/commit/d8a80a915dfe723a59f512e7128aecf857324388))\n* **tests:** add more API request tests ([04c1590](https://github.com/openai/openai-node/commit/04c1590a64127c43898c3c88bcbdd624d54008f6))\n\n## 4.55.1 (2024-08-07)\n\nFull Changelog: [v4.55.0...v4.55.1](https://github.com/openai/openai-node/compare/v4.55.0...v4.55.1)\n\n### Bug Fixes\n\n* **helpers/zod:** correct schema generation for recursive schemas ([cb54d93](https://github.com/openai/openai-node/commit/cb54d93162c86ecfd476733805a431aab25d86d6))\n\n\n### Chores\n\n* **api:** remove old `AssistantResponseFormat` type ([#967](https://github.com/openai/openai-node/issues/967)) ([9fd94bf](https://github.com/openai/openai-node/commit/9fd94bfc35128d3bc45fbf0a65e6a8d2ea4562d5))\n* **internal:** update test snapshots ([bceea60](https://github.com/openai/openai-node/commit/bceea60e461c40a9e59d52772122dd612a2ff1c4))\n* **vendor/zodJsonSchema:** add option to duplicate top-level ref ([84b8a38](https://github.com/openai/openai-node/commit/84b8a3820b0ce1c78bfd3db468d8d2962875b4ab))\n\n\n### Documentation\n\n* **examples:** add UI generation example script ([c75c017](https://github.com/openai/openai-node/commit/c75c017c16cbfe3fc60ea4ee5779782005e64463))\n\n## 4.55.0 (2024-08-06)\n\nFull Changelog: [v4.54.0...v4.55.0](https://github.com/openai/openai-node/compare/v4.54.0...v4.55.0)\n\n### Features\n\n* **api:** add structured outputs support ([573787c](https://github.com/openai/openai-node/commit/573787cf3ea8eea593eeeb5e24a9256951e2cc35))\n\n## 4.54.0 (2024-08-02)\n\nFull Changelog: [v4.53.2...v4.54.0](https://github.com/openai/openai-node/compare/v4.53.2...v4.54.0)\n\n### Features\n\n* extract out `ImageModel`, `AudioModel`, `SpeechModel` ([#964](https://github.com/openai/openai-node/issues/964)) ([1edf957](https://github.com/openai/openai-node/commit/1edf957e1cb86c2a7b2d29e28f2b8f428ea0cd7d))\n* make enums not nominal ([#965](https://github.com/openai/openai-node/issues/965)) ([0dd0cd1](https://github.com/openai/openai-node/commit/0dd0cd158d6765c3a04ac983aad03c2ecad14502))\n\n\n### Chores\n\n* **ci:** correctly tag pre-release npm packages ([#963](https://github.com/openai/openai-node/issues/963)) ([f1a4a68](https://github.com/openai/openai-node/commit/f1a4a686bbf4a38919b8597f008d895d1b99d8df))\n* **internal:** add constant for default timeout ([#960](https://github.com/openai/openai-node/issues/960)) ([55c01f4](https://github.com/openai/openai-node/commit/55c01f4dc5d132c21713f9e8606b95abc76fcd44))\n* **internal:** cleanup event stream helpers ([#950](https://github.com/openai/openai-node/issues/950)) ([8f49956](https://github.com/openai/openai-node/commit/8f499566c47bd7d4799a8cbe0d980553348b8f48))\n\n\n### Documentation\n\n* **README:** link Lifecycle in Polling Helpers section ([#962](https://github.com/openai/openai-node/issues/962)) ([c610c81](https://github.com/openai/openai-node/commit/c610c813e8d7f96b5b8315ae194e0a9ff565f43d))\n\n## 4.53.2 (2024-07-26)\n\nFull Changelog: [v4.53.1...v4.53.2](https://github.com/openai/openai-node/compare/v4.53.1...v4.53.2)\n\n### Chores\n\n* **docs:** fix incorrect client var names ([#955](https://github.com/openai/openai-node/issues/955)) ([cc91be8](https://github.com/openai/openai-node/commit/cc91be867bf7042abb2ee6c6d5ef69082ac64280))\n\n## 4.53.1 (2024-07-25)\n\nFull Changelog: [v4.53.0...v4.53.1](https://github.com/openai/openai-node/compare/v4.53.0...v4.53.1)\n\n### Bug Fixes\n\n* **compat:** remove ReadableStream polyfill redundant since node v16 ([#954](https://github.com/openai/openai-node/issues/954)) ([78b2a83](https://github.com/openai/openai-node/commit/78b2a83f085bb7ddf6a5f429636de1e3eef20f9d))\n\n\n### Chores\n\n* **tests:** update prism version ([#948](https://github.com/openai/openai-node/issues/948)) ([9202c91](https://github.com/openai/openai-node/commit/9202c91d697a116eb1b834e01f4073d254438149))\n\n## 4.53.0 (2024-07-22)\n\nFull Changelog: [v4.52.7...v4.53.0](https://github.com/openai/openai-node/compare/v4.52.7...v4.53.0)\n\n### Features\n\n* **api:** add new gpt-4o-mini models ([#942](https://github.com/openai/openai-node/issues/942)) ([7ac10dd](https://github.com/openai/openai-node/commit/7ac10ddbb87e9eb0e8e34d58a13a4775cbba1c24))\n* **api:** add uploads endpoints ([#946](https://github.com/openai/openai-node/issues/946)) ([8709ceb](https://github.com/openai/openai-node/commit/8709ceb0e01c5a1f96704c998f35ca1117ecadac))\n\n\n### Chores\n\n* **docs:** mention support of web browser runtimes ([#938](https://github.com/openai/openai-node/issues/938)) ([123d19d](https://github.com/openai/openai-node/commit/123d19d5a157110c8ada556c107caf0eb8b2ccc6))\n* **docs:** use client instead of package name in Node examples ([#941](https://github.com/openai/openai-node/issues/941)) ([8b5db1f](https://github.com/openai/openai-node/commit/8b5db1f53e66ce4b6e554f40a8dd2fd474085027))\n\n## 4.52.7 (2024-07-11)\n\nFull Changelog: [v4.52.6...v4.52.7](https://github.com/openai/openai-node/compare/v4.52.6...v4.52.7)\n\n### Documentation\n\n* **examples:** update example values ([#933](https://github.com/openai/openai-node/issues/933)) ([92512ab](https://github.com/openai/openai-node/commit/92512abcd7ab5d7c452dfae007c3a25041062656))\n\n## 4.52.6 (2024-07-11)\n\nFull Changelog: [v4.52.5...v4.52.6](https://github.com/openai/openai-node/compare/v4.52.5...v4.52.6)\n\n### Chores\n\n* **ci:** also run workflows for PRs targeting `next` ([#931](https://github.com/openai/openai-node/issues/931)) ([e3f979a](https://github.com/openai/openai-node/commit/e3f979ae94b2252b9552d1e03de5b92d398a3e28))\n\n## 4.52.5 (2024-07-10)\n\nFull Changelog: [v4.52.4...v4.52.5](https://github.com/openai/openai-node/compare/v4.52.4...v4.52.5)\n\n### Bug Fixes\n\n* **vectorStores:** correctly handle missing `files` in `uploadAndPoll()` ([#926](https://github.com/openai/openai-node/issues/926)) ([945fca6](https://github.com/openai/openai-node/commit/945fca646b02b52bbc9163cb51f5d87e7db8afd6))\n\n## 4.52.4 (2024-07-08)\n\nFull Changelog: [v4.52.3...v4.52.4](https://github.com/openai/openai-node/compare/v4.52.3...v4.52.4)\n\n### Refactors\n\n* **examples:** removedduplicated 'messageDelta' streaming event. ([#909](https://github.com/openai/openai-node/issues/909)) ([7b0b3d2](https://github.com/openai/openai-node/commit/7b0b3d2e228532fca19f49390a2831a1abac72a4))\n\n## 4.52.3 (2024-07-02)\n\nFull Changelog: [v4.52.2...v4.52.3](https://github.com/openai/openai-node/compare/v4.52.2...v4.52.3)\n\n### Chores\n\n* minor change to tests ([#916](https://github.com/openai/openai-node/issues/916)) ([b8a33e3](https://github.com/openai/openai-node/commit/b8a33e31697b52d733f28d9380e0c02a2d179474))\n\n## 4.52.2 (2024-06-28)\n\nFull Changelog: [v4.52.1...v4.52.2](https://github.com/openai/openai-node/compare/v4.52.1...v4.52.2)\n\n### Chores\n\n* gitignore test server logs ([#914](https://github.com/openai/openai-node/issues/914)) ([6316720](https://github.com/openai/openai-node/commit/6316720c3fdd0422965ae3890275062bc0fe3c2b))\n\n## 4.52.1 (2024-06-25)\n\nFull Changelog: [v4.52.0...v4.52.1](https://github.com/openai/openai-node/compare/v4.52.0...v4.52.1)\n\n### Chores\n\n* **doc:** clarify service tier default value ([#908](https://github.com/openai/openai-node/issues/908)) ([e4c8100](https://github.com/openai/openai-node/commit/e4c8100c7732bdc336b52a48d09945782c0fa2a3))\n* **internal:** minor reformatting ([#911](https://github.com/openai/openai-node/issues/911)) ([78c9377](https://github.com/openai/openai-node/commit/78c9377fcd563645081629a89f3fda2c1ff4e175))\n* **internal:** re-order some imports ([#904](https://github.com/openai/openai-node/issues/904)) ([dbd5c40](https://github.com/openai/openai-node/commit/dbd5c4053ba2f255dfc56676ced5b30381843c75))\n\n## 4.52.0 (2024-06-18)\n\nFull Changelog: [v4.51.0...v4.52.0](https://github.com/openai/openai-node/compare/v4.51.0...v4.52.0)\n\n### Features\n\n* **api:** add service tier argument for chat completions ([#900](https://github.com/openai/openai-node/issues/900)) ([91e6651](https://github.com/openai/openai-node/commit/91e66514037a8d6f9c39d3c96cd5769885925a4b))\n\n## 4.51.0 (2024-06-12)\n\nFull Changelog: [v4.50.0...v4.51.0](https://github.com/openai/openai-node/compare/v4.50.0...v4.51.0)\n\n### Features\n\n* **api:** updates ([#894](https://github.com/openai/openai-node/issues/894)) ([b58f5a1](https://github.com/openai/openai-node/commit/b58f5a1344f631dac0fb8ecfa4fbae49af070189))\n\n## 4.50.0 (2024-06-10)\n\nFull Changelog: [v4.49.1...v4.50.0](https://github.com/openai/openai-node/compare/v4.49.1...v4.50.0)\n\n### Features\n\n* support `application/octet-stream` request bodies ([#892](https://github.com/openai/openai-node/issues/892)) ([51661c8](https://github.com/openai/openai-node/commit/51661c8068d4990df6916becb6bb85353b54ef4d))\n\n## 4.49.1 (2024-06-07)\n\nFull Changelog: [v4.49.0...v4.49.1](https://github.com/openai/openai-node/compare/v4.49.0...v4.49.1)\n\n### Bug Fixes\n\n* remove erroneous thread create argument ([#889](https://github.com/openai/openai-node/issues/889)) ([a9f898e](https://github.com/openai/openai-node/commit/a9f898ee109a0b35a672e41c6497f3a75eff7734))\n\n## 4.49.0 (2024-06-06)\n\nFull Changelog: [v4.48.3...v4.49.0](https://github.com/openai/openai-node/compare/v4.48.3...v4.49.0)\n\n### Features\n\n* **api:** updates ([#887](https://github.com/openai/openai-node/issues/887)) ([359eeb3](https://github.com/openai/openai-node/commit/359eeb33b08b371451f216d1e21dd3334ec15f36))\n\n## 4.48.3 (2024-06-06)\n\nFull Changelog: [v4.48.2...v4.48.3](https://github.com/openai/openai-node/compare/v4.48.2...v4.48.3)\n\n### Chores\n\n* **internal:** minor refactor of tests ([#884](https://github.com/openai/openai-node/issues/884)) ([0b71f2b](https://github.com/openai/openai-node/commit/0b71f2b2cb67e5714476b6f63b4ef93a0140bff2))\n\n## 4.48.2 (2024-06-05)\n\nFull Changelog: [v4.48.1...v4.48.2](https://github.com/openai/openai-node/compare/v4.48.1...v4.48.2)\n\n### Chores\n\n* **internal:** minor change to tests ([#881](https://github.com/openai/openai-node/issues/881)) ([5e2d608](https://github.com/openai/openai-node/commit/5e2d608ca9a2bcb3f261ad13c848d327b60b6fb1))\n\n## 4.48.1 (2024-06-04)\n\nFull Changelog: [v4.48.0...v4.48.1](https://github.com/openai/openai-node/compare/v4.48.0...v4.48.1)\n\n### Bug Fixes\n\n* resolve typescript issue ([1129707](https://github.com/openai/openai-node/commit/11297073b1a370fc9c8676446f939a48071999b2))\n\n## 4.48.0 (2024-06-03)\n\nFull Changelog: [v4.47.3...v4.48.0](https://github.com/openai/openai-node/compare/v4.47.3...v4.48.0)\n\n### Features\n\n* **api:** updates ([#874](https://github.com/openai/openai-node/issues/874)) ([295c248](https://github.com/openai/openai-node/commit/295c2486005f6f1eb81cbbd6994b4382801d0707))\n\n## 4.47.3 (2024-05-31)\n\nFull Changelog: [v4.47.2...v4.47.3](https://github.com/openai/openai-node/compare/v4.47.2...v4.47.3)\n\n### Bug Fixes\n\n* allow git imports for pnpm ([#873](https://github.com/openai/openai-node/issues/873)) ([9da9809](https://github.com/openai/openai-node/commit/9da98090e80cbe988a3d695e4c9b57439080ec3e))\n\n\n### Documentation\n\n* **azure:** update example and readme to use Entra ID ([#857](https://github.com/openai/openai-node/issues/857)) ([722eff1](https://github.com/openai/openai-node/commit/722eff1a7aeaa2ce3c40301709db61258c9afa16))\n\n## 4.47.2 (2024-05-28)\n\nFull Changelog: [v4.47.1...v4.47.2](https://github.com/openai/openai-node/compare/v4.47.1...v4.47.2)\n\n### Documentation\n\n* **readme:** add bundle size badge ([#869](https://github.com/openai/openai-node/issues/869)) ([e252132](https://github.com/openai/openai-node/commit/e2521327b7b4f5abe97e4c58c417b37d00079ef8))\n\n## 4.47.1 (2024-05-14)\n\nFull Changelog: [v4.47.0...v4.47.1](https://github.com/openai/openai-node/compare/v4.47.0...v4.47.1)\n\n### Chores\n\n* **internal:** add slightly better logging to scripts ([#848](https://github.com/openai/openai-node/issues/848)) ([139e690](https://github.com/openai/openai-node/commit/139e690546775b3568934dd990dd329fce2fbc2f))\n\n## 4.47.0 (2024-05-14)\n\nFull Changelog: [v4.46.1...v4.47.0](https://github.com/openai/openai-node/compare/v4.46.1...v4.47.0)\n\n### Features\n\n* **api:** add incomplete state ([#846](https://github.com/openai/openai-node/issues/846)) ([5f663a1](https://github.com/openai/openai-node/commit/5f663a167361b905c6d0c1242e8a78037a7e4a57))\n\n## 4.46.1 (2024-05-13)\n\nFull Changelog: [v4.46.0...v4.46.1](https://github.com/openai/openai-node/compare/v4.46.0...v4.46.1)\n\n### Refactors\n\n* change import paths to be relative ([#843](https://github.com/openai/openai-node/issues/843)) ([7913574](https://github.com/openai/openai-node/commit/7913574bdb6fcbcf68e56e8def351add6c43310a))\n\n## 4.46.0 (2024-05-13)\n\nFull Changelog: [v4.45.0...v4.46.0](https://github.com/openai/openai-node/compare/v4.45.0...v4.46.0)\n\n### Features\n\n* **api:** add gpt-4o model ([#841](https://github.com/openai/openai-node/issues/841)) ([c818ed1](https://github.com/openai/openai-node/commit/c818ed139bfba81af6ca3c4eda08d52366758529))\n\n## 4.45.0 (2024-05-11)\n\nFull Changelog: [v4.44.0...v4.45.0](https://github.com/openai/openai-node/compare/v4.44.0...v4.45.0)\n\n### Features\n\n* **azure:** batch api ([#839](https://github.com/openai/openai-node/issues/839)) ([e279f8c](https://github.com/openai/openai-node/commit/e279f8c51aa80cb913ccb6df647407bea1f2f071))\n\n\n### Chores\n\n* **dependency:** bumped Next.js version ([#836](https://github.com/openai/openai-node/issues/836)) ([babb140](https://github.com/openai/openai-node/commit/babb1404751059bdd171b792d03fd21272dd8f8b))\n* **docs:** add SECURITY.md ([#838](https://github.com/openai/openai-node/issues/838)) ([6e556d9](https://github.com/openai/openai-node/commit/6e556d9e12341155cc13fe226ab110d63858370e))\n\n## 4.44.0 (2024-05-09)\n\nFull Changelog: [v4.43.0...v4.44.0](https://github.com/openai/openai-node/compare/v4.43.0...v4.44.0)\n\n### Features\n\n* **api:** add message image content ([#834](https://github.com/openai/openai-node/issues/834)) ([7757b3e](https://github.com/openai/openai-node/commit/7757b3ea54a2c5cc251f55af0b676952ba12e8a6))\n\n## 4.43.0 (2024-05-08)\n\nFull Changelog: [v4.42.0...v4.43.0](https://github.com/openai/openai-node/compare/v4.42.0...v4.43.0)\n\n### Features\n\n* **api:** adding file purposes ([#831](https://github.com/openai/openai-node/issues/831)) ([a62b877](https://github.com/openai/openai-node/commit/a62b8779ff7261cdd6aa7bf72fb6407cc7e3fd21))\n\n## 4.42.0 (2024-05-06)\n\nFull Changelog: [v4.41.1...v4.42.0](https://github.com/openai/openai-node/compare/v4.41.1...v4.42.0)\n\n### Features\n\n* **api:** add usage metadata when streaming ([#829](https://github.com/openai/openai-node/issues/829)) ([6707f11](https://github.com/openai/openai-node/commit/6707f119a191ad98d634ad208be852f9f39c6c0e))\n\n\n### Bug Fixes\n\n* **example:** fix fine tuning example ([#827](https://github.com/openai/openai-node/issues/827)) ([6480a50](https://github.com/openai/openai-node/commit/6480a506c096a2664bd2ad296481e51017ff4185))\n\n## 4.41.1 (2024-05-06)\n\nFull Changelog: [v4.41.0...v4.41.1](https://github.com/openai/openai-node/compare/v4.41.0...v4.41.1)\n\n### Bug Fixes\n\n* **azure:** update build script ([#825](https://github.com/openai/openai-node/issues/825)) ([8afc6e7](https://github.com/openai/openai-node/commit/8afc6e7b49507b3be0228e93913d51b4c3211add))\n\n## 4.41.0 (2024-05-05)\n\nFull Changelog: [v4.40.2...v4.41.0](https://github.com/openai/openai-node/compare/v4.40.2...v4.41.0)\n\n### Features\n\n* **client:** add Azure client ([#822](https://github.com/openai/openai-node/issues/822)) ([92f9049](https://github.com/openai/openai-node/commit/92f90499f0bbee79ba9c8342c8d58dbcaf88bdd1))\n\n## 4.40.2 (2024-05-03)\n\nFull Changelog: [v4.40.1...v4.40.2](https://github.com/openai/openai-node/compare/v4.40.1...v4.40.2)\n\n### Bug Fixes\n\n* **package:** revert recent client file change ([#819](https://github.com/openai/openai-node/issues/819)) ([fa722c9](https://github.com/openai/openai-node/commit/fa722c97859e55a0e766332c3a2f0cb3673128a2))\n* **vectorStores:** correct uploadAndPoll method ([#817](https://github.com/openai/openai-node/issues/817)) ([d63f22c](https://github.com/openai/openai-node/commit/d63f22c303761710e6eac7ef883c45e34d223df1))\n\n## 4.40.1 (2024-05-02)\n\nFull Changelog: [v4.40.0...v4.40.1](https://github.com/openai/openai-node/compare/v4.40.0...v4.40.1)\n\n### Chores\n\n* **internal:** bump prism version ([#813](https://github.com/openai/openai-node/issues/813)) ([81a6c28](https://github.com/openai/openai-node/commit/81a6c28c4773a0245ce9c505fc5b98d43df21beb))\n* **internal:** move client class to separate file ([#815](https://github.com/openai/openai-node/issues/815)) ([d0b915a](https://github.com/openai/openai-node/commit/d0b915a7514eda5b23d7d1e4420d1d1485ed8d0f))\n\n## 4.40.0 (2024-05-01)\n\nFull Changelog: [v4.39.1...v4.40.0](https://github.com/openai/openai-node/compare/v4.39.1...v4.40.0)\n\n### Features\n\n* **api:** delete messages ([#811](https://github.com/openai/openai-node/issues/811)) ([9e37dbd](https://github.com/openai/openai-node/commit/9e37dbd554e4ca48fda1577b1aad612e9d30534d))\n\n## 4.39.1 (2024-04-30)\n\nFull Changelog: [v4.39.0...v4.39.1](https://github.com/openai/openai-node/compare/v4.39.0...v4.39.1)\n\n### Chores\n\n* **internal:** add link to openapi spec ([#810](https://github.com/openai/openai-node/issues/810)) ([61b5b83](https://github.com/openai/openai-node/commit/61b5b83e82dd723e9584232f3b805ed13e58e13d))\n* **internal:** fix release please for deno ([#808](https://github.com/openai/openai-node/issues/808)) ([ecc2eae](https://github.com/openai/openai-node/commit/ecc2eaec602eb9fe518f011920d8500e01fde01b))\n* **internal:** refactor scripts ([#806](https://github.com/openai/openai-node/issues/806)) ([9283519](https://github.com/openai/openai-node/commit/928351928054feb56f8797587c70f74d06c2737c))\n\n## 4.39.0 (2024-04-29)\n\nFull Changelog: [v4.38.5...v4.39.0](https://github.com/openai/openai-node/compare/v4.38.5...v4.39.0)\n\n### Features\n\n* **api:** add required tool_choice ([#803](https://github.com/openai/openai-node/issues/803)) ([99693e6](https://github.com/openai/openai-node/commit/99693e61debc67327a45dffb2c10c113341bffd6))\n\n\n### Chores\n\n* **internal:** add scripts/test and scripts/mock ([#801](https://github.com/openai/openai-node/issues/801)) ([6656105](https://github.com/openai/openai-node/commit/6656105fa1346a91d17e2b7a5e075f3091310c2f))\n\n## 4.38.5 (2024-04-24)\n\nFull Changelog: [v4.38.4...v4.38.5](https://github.com/openai/openai-node/compare/v4.38.4...v4.38.5)\n\n### Chores\n\n* **internal:** use actions/checkout@v4 for codeflow ([#799](https://github.com/openai/openai-node/issues/799)) ([5ab7780](https://github.com/openai/openai-node/commit/5ab7780ea8889818f403a9a89ab19585a7e8972e))\n\n## 4.38.4 (2024-04-24)\n\nFull Changelog: [v4.38.3...v4.38.4](https://github.com/openai/openai-node/compare/v4.38.3...v4.38.4)\n\n### Bug Fixes\n\n* **api:** change timestamps to unix integers ([#798](https://github.com/openai/openai-node/issues/798)) ([7271a6c](https://github.com/openai/openai-node/commit/7271a6cdc7d37151d2cae18fdd20b87d97624a84))\n* **docs:** doc improvements ([#796](https://github.com/openai/openai-node/issues/796)) ([49fcc86](https://github.com/openai/openai-node/commit/49fcc86b44958795a6f5e0901f369653dfbcc637))\n\n## 4.38.3 (2024-04-22)\n\nFull Changelog: [v4.38.2...v4.38.3](https://github.com/openai/openai-node/compare/v4.38.2...v4.38.3)\n\n### Chores\n\n* **internal:** use @swc/jest for running tests ([#793](https://github.com/openai/openai-node/issues/793)) ([8947f19](https://github.com/openai/openai-node/commit/8947f195b2dfab7ceebe1e0bb5c886e229cd541f))\n\n## 4.38.2 (2024-04-19)\n\nFull Changelog: [v4.38.1...v4.38.2](https://github.com/openai/openai-node/compare/v4.38.1...v4.38.2)\n\n### Bug Fixes\n\n* **api:** correct types for message attachment tools ([#787](https://github.com/openai/openai-node/issues/787)) ([8626884](https://github.com/openai/openai-node/commit/8626884abd2494aa081db9e50a2f268b6cebc5df))\n\n## 4.38.1 (2024-04-18)\n\nFull Changelog: [v4.38.0...v4.38.1](https://github.com/openai/openai-node/compare/v4.38.0...v4.38.1)\n\n### Bug Fixes\n\n* **api:** correct types for attachments ([#783](https://github.com/openai/openai-node/issues/783)) ([6893631](https://github.com/openai/openai-node/commit/6893631334f75e232ba130f5dd67f1230b1e5fa0))\n\n## 4.38.0 (2024-04-18)\n\nFull Changelog: [v4.37.1...v4.38.0](https://github.com/openai/openai-node/compare/v4.37.1...v4.38.0)\n\n### Features\n\n* **api:** batch list endpoint ([#781](https://github.com/openai/openai-node/issues/781)) ([d226759](https://github.com/openai/openai-node/commit/d226759164fbed33198d8bdc315c98e1052dade8))\n\n## 4.37.1 (2024-04-17)\n\nFull Changelog: [v4.37.0...v4.37.1](https://github.com/openai/openai-node/compare/v4.37.0...v4.37.1)\n\n### Chores\n\n* **api:** docs and response_format response property ([#778](https://github.com/openai/openai-node/issues/778)) ([78f5c35](https://github.com/openai/openai-node/commit/78f5c3568d95d8e854c04049dc7d5643aa49e93f))\n\n## 4.37.0 (2024-04-17)\n\nFull Changelog: [v4.36.0...v4.37.0](https://github.com/openai/openai-node/compare/v4.36.0...v4.37.0)\n\n### Features\n\n* **api:** add vector stores ([#776](https://github.com/openai/openai-node/issues/776)) ([8bb929b](https://github.com/openai/openai-node/commit/8bb929b2ee91c1bec0a00347bf4f7628652d1be3))\n\n## 4.36.0 (2024-04-16)\n\nFull Changelog: [v4.35.0...v4.36.0](https://github.com/openai/openai-node/compare/v4.35.0...v4.36.0)\n\n### Features\n\n* **client:** add header OpenAI-Project ([#772](https://github.com/openai/openai-node/issues/772)) ([bb4df37](https://github.com/openai/openai-node/commit/bb4df3722082fb44b7d4feb7a47df796149150a2))\n* extract chat models to a named enum ([#775](https://github.com/openai/openai-node/issues/775)) ([141d2ed](https://github.com/openai/openai-node/commit/141d2ed308141dc751869353208e4d0632d3650c))\n\n\n### Build System\n\n* configure UTF-8 locale in devcontainer ([#774](https://github.com/openai/openai-node/issues/774)) ([bebf4f0](https://github.com/openai/openai-node/commit/bebf4f0ca1f884f8747caff0f0e065aafffde096))\n\n## 4.35.0 (2024-04-15)\n\nFull Changelog: [v4.34.0...v4.35.0](https://github.com/openai/openai-node/compare/v4.34.0...v4.35.0)\n\n### Features\n\n* **errors:** add request_id property ([#769](https://github.com/openai/openai-node/issues/769)) ([43aa6a1](https://github.com/openai/openai-node/commit/43aa6a19cfb1448903dfaddc4da3def2eda9cbab))\n\n## 4.34.0 (2024-04-15)\n\nFull Changelog: [v4.33.1...v4.34.0](https://github.com/openai/openai-node/compare/v4.33.1...v4.34.0)\n\n### Features\n\n* **api:** add batch API ([#768](https://github.com/openai/openai-node/issues/768)) ([7fe34f2](https://github.com/openai/openai-node/commit/7fe34f2d0bda9c1cb116a593f02bd0cc15a52e12))\n* **api:** updates ([#766](https://github.com/openai/openai-node/issues/766)) ([52bcc47](https://github.com/openai/openai-node/commit/52bcc47043e4c3ffe15ae9e7ac0fa87e2493aad9))\n\n## 4.33.1 (2024-04-12)\n\nFull Changelog: [v4.33.0...v4.33.1](https://github.com/openai/openai-node/compare/v4.33.0...v4.33.1)\n\n### Chores\n\n* **internal:** formatting ([#763](https://github.com/openai/openai-node/issues/763)) ([b6acf54](https://github.com/openai/openai-node/commit/b6acf54baab7e6cbf6ce3ad1d6c70197cc0181d0))\n* **internal:** improve ecosystem tests ([#761](https://github.com/openai/openai-node/issues/761)) ([fcf748d](https://github.com/openai/openai-node/commit/fcf748dbbd23f972ff9fd81a8b2a35232a2d6e5c))\n\n## 4.33.0 (2024-04-05)\n\nFull Changelog: [v4.32.2...v4.33.0](https://github.com/openai/openai-node/compare/v4.32.2...v4.33.0)\n\n### Features\n\n* **api:** add additional messages when creating thread run ([#759](https://github.com/openai/openai-node/issues/759)) ([f1fdb41](https://github.com/openai/openai-node/commit/f1fdb410e087f9b94faeda0558de573ec1118601))\n\n## 4.32.2 (2024-04-04)\n\nFull Changelog: [v4.32.1...v4.32.2](https://github.com/openai/openai-node/compare/v4.32.1...v4.32.2)\n\n### Bug Fixes\n\n* **streaming:** handle special line characters and fix multi-byte character decoding ([#757](https://github.com/openai/openai-node/issues/757)) ([8dcdda2](https://github.com/openai/openai-node/commit/8dcdda2b0d1d86486eea5fd47d24a8d26fde4c19))\n* **tests:** update wrangler to v3.19.0 (CVE-2023-7080) ([#755](https://github.com/openai/openai-node/issues/755)) ([47ca41d](https://github.com/openai/openai-node/commit/47ca41da9a739b2e04b721cb1fe843e5dd152465))\n\n\n### Chores\n\n* **tests:** bump ecosystem tests dependencies ([#753](https://github.com/openai/openai-node/issues/753)) ([3f86ea2](https://github.com/openai/openai-node/commit/3f86ea2205c90e05bcbe582491a4bed01075a5b1))\n\n## 4.32.1 (2024-04-02)\n\nFull Changelog: [v4.32.0...v4.32.1](https://github.com/openai/openai-node/compare/v4.32.0...v4.32.1)\n\n### Chores\n\n* **deps:** bump yarn to v1.22.22 ([#751](https://github.com/openai/openai-node/issues/751)) ([5b41d10](https://github.com/openai/openai-node/commit/5b41d1077f219b8feb7557cfab98caf7b5de560d))\n\n## 4.32.0 (2024-04-01)\n\nFull Changelog: [v4.31.0...v4.32.0](https://github.com/openai/openai-node/compare/v4.31.0...v4.32.0)\n\n### Features\n\n* **api:** add support for filtering messages by run_id ([#747](https://github.com/openai/openai-node/issues/747)) ([9a397ac](https://github.com/openai/openai-node/commit/9a397acffa9f10c3f48e86e3bdb3851770f87b42))\n* **api:** run polling helpers ([#749](https://github.com/openai/openai-node/issues/749)) ([02920ae](https://github.com/openai/openai-node/commit/02920ae082480fc7a7ffe9fa583d053a40dc7120))\n\n\n### Chores\n\n* **deps:** remove unused dependency digest-fetch ([#748](https://github.com/openai/openai-node/issues/748)) ([5376837](https://github.com/openai/openai-node/commit/537683734d39dd956a7dcef4339c1167ce6fe13c))\n\n\n### Documentation\n\n* **readme:** change undocumented params wording ([#744](https://github.com/openai/openai-node/issues/744)) ([8796691](https://github.com/openai/openai-node/commit/87966911045275db86844dfdcde59653edaef264))\n\n\n### Refactors\n\n* rename createAndStream to stream ([02920ae](https://github.com/openai/openai-node/commit/02920ae082480fc7a7ffe9fa583d053a40dc7120))\n\n## 4.31.0 (2024-03-30)\n\nFull Changelog: [v4.30.0...v4.31.0](https://github.com/openai/openai-node/compare/v4.30.0...v4.31.0)\n\n### Features\n\n* **api:** adding temperature parameter ([#742](https://github.com/openai/openai-node/issues/742)) ([b173b05](https://github.com/openai/openai-node/commit/b173b05eb52266d8f2c835ec4ed71cba8cdc609b))\n\n\n### Bug Fixes\n\n* **streaming:** trigger all event handlers with fromReadableStream ([#741](https://github.com/openai/openai-node/issues/741)) ([7b1e593](https://github.com/openai/openai-node/commit/7b1e5937d97b309ed51928b4388dcde74abda8dc))\n\n## 4.30.0 (2024-03-28)\n\nFull Changelog: [v4.29.2...v4.30.0](https://github.com/openai/openai-node/compare/v4.29.2...v4.30.0)\n\n### Features\n\n* assistant fromReadableStream ([#738](https://github.com/openai/openai-node/issues/738)) ([8f4ba18](https://github.com/openai/openai-node/commit/8f4ba18268797d6c54c393d701b13c7ff2aa71bc))\n\n\n### Bug Fixes\n\n* **client:** correctly send deno version header ([#736](https://github.com/openai/openai-node/issues/736)) ([b7ea175](https://github.com/openai/openai-node/commit/b7ea175b2854909de77b920dd25613f1d2daefd6))\n* **example:** correcting example ([#739](https://github.com/openai/openai-node/issues/739)) ([a819551](https://github.com/openai/openai-node/commit/a81955175da24e196490a38850bbf6f9b6779ea8))\n* handle process.env being undefined in debug func ([#733](https://github.com/openai/openai-node/issues/733)) ([2baa149](https://github.com/openai/openai-node/commit/2baa1491f7834f779ca49c3027d2344ead412dd2))\n* **internal:** make toFile use input file's options ([#727](https://github.com/openai/openai-node/issues/727)) ([15880d7](https://github.com/openai/openai-node/commit/15880d77b6c1cf58a6b9cfdbf7ae4442cdbddbd6))\n\n\n### Chores\n\n* **internal:** add type ([#737](https://github.com/openai/openai-node/issues/737)) ([18c1989](https://github.com/openai/openai-node/commit/18c19891f783019517d7961fe03c4d98de0fcf93))\n\n\n### Documentation\n\n* **readme:** consistent use of sentence case in headings ([#729](https://github.com/openai/openai-node/issues/729)) ([7e515fd](https://github.com/openai/openai-node/commit/7e515fde433ebfb7871d75d53915eef05a08a916))\n* **readme:** document how to make undocumented requests ([#730](https://github.com/openai/openai-node/issues/730)) ([a06d861](https://github.com/openai/openai-node/commit/a06d861a015eeee411fa2c6ed9bf3000313cfc03))\n\n## 4.29.2 (2024-03-19)\n\nFull Changelog: [v4.29.1...v4.29.2](https://github.com/openai/openai-node/compare/v4.29.1...v4.29.2)\n\n### Chores\n\n* **internal:** update generated pragma comment ([#724](https://github.com/openai/openai-node/issues/724)) ([139e205](https://github.com/openai/openai-node/commit/139e205ed1ed30cb1df982d852a093dcea945aba))\n\n\n### Documentation\n\n* assistant improvements ([#725](https://github.com/openai/openai-node/issues/725)) ([6a2c41b](https://github.com/openai/openai-node/commit/6a2c41b0ce833eba0cdea6a7d221697f3be26abb))\n* fix typo in CONTRIBUTING.md ([#722](https://github.com/openai/openai-node/issues/722)) ([05ff8f7](https://github.com/openai/openai-node/commit/05ff8f7671fe6ce5d9517034f76a166a0bd27803))\n\n## 4.29.1 (2024-03-15)\n\nFull Changelog: [v4.29.0...v4.29.1](https://github.com/openai/openai-node/compare/v4.29.0...v4.29.1)\n\n### Documentation\n\n* **readme:** assistant streaming ([#719](https://github.com/openai/openai-node/issues/719)) ([bc9a1ca](https://github.com/openai/openai-node/commit/bc9a1ca308020a88c29d409edc06cdfca8cbf8f5))\n\n## 4.29.0 (2024-03-13)\n\nFull Changelog: [v4.28.5...v4.29.0](https://github.com/openai/openai-node/compare/v4.28.5...v4.29.0)\n\n### Features\n\n* **assistants:** add support for streaming ([#714](https://github.com/openai/openai-node/issues/714)) ([7d27d28](https://github.com/openai/openai-node/commit/7d27d286876d0a575d91a4752f401126fe93d2a3))\n\n## 4.28.5 (2024-03-13)\n\nFull Changelog: [v4.28.4...v4.28.5](https://github.com/openai/openai-node/compare/v4.28.4...v4.28.5)\n\n### Bug Fixes\n\n* **ChatCompletionStream:** abort on async iterator break and handle errors ([#699](https://github.com/openai/openai-node/issues/699)) ([ac417a2](https://github.com/openai/openai-node/commit/ac417a2db31919d2b52f2eb2e38f9c67a8f73254))\n* **streaming:** correctly handle trailing new lines in byte chunks ([#708](https://github.com/openai/openai-node/issues/708)) ([4753be2](https://github.com/openai/openai-node/commit/4753be272b1d1dade7a769cf350b829fc639f36e))\n\n\n### Chores\n\n* **api:** update docs ([#703](https://github.com/openai/openai-node/issues/703)) ([e1db98b](https://github.com/openai/openai-node/commit/e1db98bef29d200e2e401e3f5d7b2db6839c7836))\n* **docs:** mention install from git repo ([#700](https://github.com/openai/openai-node/issues/700)) ([c081bdb](https://github.com/openai/openai-node/commit/c081bdbb55585e63370496d324dc6f94d86424d1))\n* fix error handler in readme ([#704](https://github.com/openai/openai-node/issues/704)) ([4ff790a](https://github.com/openai/openai-node/commit/4ff790a67cf876191e04ad0e369e447e080b78a7))\n* **internal:** add explicit type annotation to decoder ([#712](https://github.com/openai/openai-node/issues/712)) ([d728e99](https://github.com/openai/openai-node/commit/d728e9923554e4c72c9efa3bd528561400d50ad8))\n* **types:** fix accidental exposure of Buffer type to cloudflare ([#709](https://github.com/openai/openai-node/issues/709)) ([0323ecb](https://github.com/openai/openai-node/commit/0323ecb98ddbd8910fc5719c8bab5175b945d2ab))\n\n\n### Documentation\n\n* **contributing:** improve wording ([#696](https://github.com/openai/openai-node/issues/696)) ([940d569](https://github.com/openai/openai-node/commit/940d5695f4cacddbb58e3bfc50fec28c468c7e63))\n* **readme:** fix https proxy example ([#705](https://github.com/openai/openai-node/issues/705)) ([d144789](https://github.com/openai/openai-node/commit/d1447890a556d37928b628f6449bb80de224d207))\n* **readme:** fix typo in custom fetch implementation ([#698](https://github.com/openai/openai-node/issues/698)) ([64041fd](https://github.com/openai/openai-node/commit/64041fd33da569eccae64afe4e50ee803017b20b))\n* remove extraneous --save and yarn install instructions ([#710](https://github.com/openai/openai-node/issues/710)) ([8ec216d](https://github.com/openai/openai-node/commit/8ec216d6b72ee4d67e26786f06c93af18d042117))\n* use [@deprecated](https://github.com/deprecated) decorator for deprecated params ([#711](https://github.com/openai/openai-node/issues/711)) ([4688ef4](https://github.com/openai/openai-node/commit/4688ef4b36e9f383a3abf6cdb31d498163a7bb9e))\n\n## 4.28.4 (2024-02-28)\n\nFull Changelog: [v4.28.3...v4.28.4](https://github.com/openai/openai-node/compare/v4.28.3...v4.28.4)\n\n### Features\n\n* **api:** add wav and pcm to response_format ([#691](https://github.com/openai/openai-node/issues/691)) ([b1c6171](https://github.com/openai/openai-node/commit/b1c61711961a62a4d7b47909a68ecd65231a66af))\n\n\n### Chores\n\n* **ci:** update actions/setup-node action to v4 ([#685](https://github.com/openai/openai-node/issues/685)) ([f2704d5](https://github.com/openai/openai-node/commit/f2704d5f1580c0f1d31584ef88702cde8f6804d4))\n* **internal:** fix ecosystem tests ([#693](https://github.com/openai/openai-node/issues/693)) ([616624d](https://github.com/openai/openai-node/commit/616624d3d9fd10ce254ce0d435b2b73ed11679f2))\n* **types:** extract run status to a named type ([#686](https://github.com/openai/openai-node/issues/686)) ([b3b3b8e](https://github.com/openai/openai-node/commit/b3b3b8ea20e0f311d3bd53dfd22ccc04f5dce5f7))\n* update @types/react to 18.2.58, @types/react-dom to 18.2.19 ([#688](https://github.com/openai/openai-node/issues/688)) ([2a0d0b1](https://github.com/openai/openai-node/commit/2a0d0b1cb197eef25e42bbba88ee90c37d623f24))\n* update dependency @types/node to v20.11.20 ([#690](https://github.com/openai/openai-node/issues/690)) ([4ca005b](https://github.com/openai/openai-node/commit/4ca005be082d6c50fe95da6148896b62080bfe07))\n* update dependency @types/ws to v8.5.10 ([#683](https://github.com/openai/openai-node/issues/683)) ([a617268](https://github.com/openai/openai-node/commit/a6172683a3390422984ad282ac4940781493e772))\n* update dependency next to v13.5.6 ([#689](https://github.com/openai/openai-node/issues/689)) ([abb3b66](https://github.com/openai/openai-node/commit/abb3b6674b8f9f8ff9c2cc61629a31883ae4d8c8))\n\n## 4.28.3 (2024-02-20)\n\nFull Changelog: [v4.28.2...v4.28.3](https://github.com/openai/openai-node/compare/v4.28.2...v4.28.3)\n\n### Bug Fixes\n\n* **ci:** revert \"move github release logic to github app\" ([#680](https://github.com/openai/openai-node/issues/680)) ([8b4009a](https://github.com/openai/openai-node/commit/8b4009af05a2e0824f99d3cf8cd9063f234ae470))\n\n## 4.28.2 (2024-02-19)\n\nFull Changelog: [v4.28.1...v4.28.2](https://github.com/openai/openai-node/compare/v4.28.1...v4.28.2)\n\n### Bug Fixes\n\n* **api:** remove non-GA instance_id param ([#677](https://github.com/openai/openai-node/issues/677)) ([4d0d4da](https://github.com/openai/openai-node/commit/4d0d4daf3bfca0089c5258a136542513e6b372e6))\n\n## 4.28.1 (2024-02-19)\n\nFull Changelog: [v4.28.0...v4.28.1](https://github.com/openai/openai-node/compare/v4.28.0...v4.28.1)\n\n### Chores\n\n* **ci:** move github release logic to github app ([#671](https://github.com/openai/openai-node/issues/671)) ([ecca6bc](https://github.com/openai/openai-node/commit/ecca6bc2eea391ee53f1a1d6cac9665199447ae0))\n* **internal:** refactor release environment script ([#674](https://github.com/openai/openai-node/issues/674)) ([27d3770](https://github.com/openai/openai-node/commit/27d37705d17e05c3761ccefcf09c4e2018eb5772))\n\n## 4.28.0 (2024-02-13)\n\nFull Changelog: [v4.27.1...v4.28.0](https://github.com/openai/openai-node/compare/v4.27.1...v4.28.0)\n\n### Features\n\n* **api:** updates ([#669](https://github.com/openai/openai-node/issues/669)) ([e1900f9](https://github.com/openai/openai-node/commit/e1900f97ee3f4758d47a7eb4659e30abe3750c99))\n\n## 4.27.1 (2024-02-12)\n\nFull Changelog: [v4.27.0...v4.27.1](https://github.com/openai/openai-node/compare/v4.27.0...v4.27.1)\n\n## 4.27.0 (2024-02-08)\n\nFull Changelog: [v4.26.1...v4.27.0](https://github.com/openai/openai-node/compare/v4.26.1...v4.27.0)\n\n### Features\n\n* **api:** add `timestamp_granularities`, add `gpt-3.5-turbo-0125` model ([#661](https://github.com/openai/openai-node/issues/661)) ([5016806](https://github.com/openai/openai-node/commit/50168066862f66b529bae29f4564741300303246))\n\n\n### Chores\n\n* **internal:** fix retry mechanism for ecosystem-test ([#663](https://github.com/openai/openai-node/issues/663)) ([0eb7ed5](https://github.com/openai/openai-node/commit/0eb7ed5ca3f7c7b29c316fc7d725d834cee73989))\n* respect `application/vnd.api+json` content-type header ([#664](https://github.com/openai/openai-node/issues/664)) ([f4fad54](https://github.com/openai/openai-node/commit/f4fad549c5c366d8dd8b936b7699639b895e82a1))\n\n## 4.26.1 (2024-02-05)\n\nFull Changelog: [v4.26.0...v4.26.1](https://github.com/openai/openai-node/compare/v4.26.0...v4.26.1)\n\n### Chores\n\n* **internal:** enable building when git installed ([#657](https://github.com/openai/openai-node/issues/657)) ([8c80a7d](https://github.com/openai/openai-node/commit/8c80a7d6d36155901a19d1f9cd1fec17b89e261e))\n* **internal:** re-order pagination import ([#656](https://github.com/openai/openai-node/issues/656)) ([21ae54e](https://github.com/openai/openai-node/commit/21ae54ea2cc2779e440909782a6ac8b70f88ec1f))\n* **internal:** support pre-release versioning ([#653](https://github.com/openai/openai-node/issues/653)) ([0c3859f](https://github.com/openai/openai-node/commit/0c3859f88164ae3eb6ec8c29e8889a50861cb35b))\n* **test:** add delay between ecosystem tests retry ([#651](https://github.com/openai/openai-node/issues/651)) ([6a4cc5c](https://github.com/openai/openai-node/commit/6a4cc5cea36ae408c8c1eb2ea0ea02f96ffb77b7))\n\n\n### Documentation\n\n* add a CONTRIBUTING.md ([#659](https://github.com/openai/openai-node/issues/659)) ([8ea58b0](https://github.com/openai/openai-node/commit/8ea58b0b9e7382a3b3af852a9a3a288a485ad33a))\n\n## 4.26.0 (2024-01-25)\n\nFull Changelog: [v4.25.0...v4.26.0](https://github.com/openai/openai-node/compare/v4.25.0...v4.26.0)\n\n### Features\n\n* **api:** add text embeddings dimensions param ([#650](https://github.com/openai/openai-node/issues/650)) ([1b5a977](https://github.com/openai/openai-node/commit/1b5a977d0eef7f5cf97daf27333cbbeb6bb479f3))\n\n\n### Chores\n\n* **internal:** add internal helpers & improve build scripts ([#643](https://github.com/openai/openai-node/issues/643)) ([9392f50](https://github.com/openai/openai-node/commit/9392f50e47f26b16632c9eb12187ea7f8a565e09))\n* **internal:** adjust ecosystem-tests logging in CI ([#646](https://github.com/openai/openai-node/issues/646)) ([156084b](https://github.com/openai/openai-node/commit/156084b8734194a5856612378115b948c82ec6e4))\n* **internal:** don't re-export streaming type ([#648](https://github.com/openai/openai-node/issues/648)) ([4c4be94](https://github.com/openai/openai-node/commit/4c4be945fa3f54036183e2d0877060db47ea564b))\n* **internal:** fix binary files ([#645](https://github.com/openai/openai-node/issues/645)) ([e1fbc39](https://github.com/openai/openai-node/commit/e1fbc396f4d1dd8ba980c25ba03b670dfed887a0))\n* **internal:** minor streaming updates ([#647](https://github.com/openai/openai-node/issues/647)) ([2f073e4](https://github.com/openai/openai-node/commit/2f073e4e6c9cd0ff3ad434907da710704765a005))\n* **internal:** pin deno version ([#649](https://github.com/openai/openai-node/issues/649)) ([7e4b903](https://github.com/openai/openai-node/commit/7e4b9039320e4ccbafb45f57dce273bedc9b7cb3))\n\n## 4.25.0 (2024-01-21)\n\nFull Changelog: [v4.24.7...v4.25.0](https://github.com/openai/openai-node/compare/v4.24.7...v4.25.0)\n\n### Features\n\n* **api:** add usage to runs and run steps ([#640](https://github.com/openai/openai-node/issues/640)) ([3caa416](https://github.com/openai/openai-node/commit/3caa4166b8abb5bffb4c8be1495834b7f16af32d))\n\n\n### Bug Fixes\n\n* allow body type in RequestOptions to be null ([#637](https://github.com/openai/openai-node/issues/637)) ([c4f8a36](https://github.com/openai/openai-node/commit/c4f8a3698dc1d80439131c5097975d6a5db1b4e2))\n* handle system_fingerprint in streaming helpers ([#636](https://github.com/openai/openai-node/issues/636)) ([f273530](https://github.com/openai/openai-node/commit/f273530ac491300842aef463852821a1a27805fb))\n* **types:** accept undefined for optional client options ([#635](https://github.com/openai/openai-node/issues/635)) ([e48cd57](https://github.com/openai/openai-node/commit/e48cd57931cd0e81a77b55653cb1f663111dd733))\n\n\n### Chores\n\n* **internal:** debug logging for retries; speculative retry-after-ms support ([#633](https://github.com/openai/openai-node/issues/633)) ([fd64971](https://github.com/openai/openai-node/commit/fd64971612d1d7fcbd8a63885d333485bff68ab1))\n* **internal:** update comment ([#631](https://github.com/openai/openai-node/issues/631)) ([e109d40](https://github.com/openai/openai-node/commit/e109d40a5c02c5bf4586e54d92bf0e355d254c1b))\n\n## 4.24.7 (2024-01-13)\n\nFull Changelog: [v4.24.6...v4.24.7](https://github.com/openai/openai-node/compare/v4.24.6...v4.24.7)\n\n### Chores\n\n* **ecosystem-tests:** fix flaky vercel-edge, cloudflare-worker, and deno tests ([#626](https://github.com/openai/openai-node/issues/626)) ([ae412a5](https://github.com/openai/openai-node/commit/ae412a5f12e701e07e71bd9791c55a56858e8383))\n* **ecosystem-tests:** fix typo in deno test ([#628](https://github.com/openai/openai-node/issues/628)) ([048ec94](https://github.com/openai/openai-node/commit/048ec943f8d12acba9829c35ebf0b2d3f24930c8))\n\n## 4.24.6 (2024-01-12)\n\nFull Changelog: [v4.24.5...v4.24.6](https://github.com/openai/openai-node/compare/v4.24.5...v4.24.6)\n\n### Chores\n\n* **ecosystem-tests:** fix flaky tests and remove fine tuning calls ([#623](https://github.com/openai/openai-node/issues/623)) ([258d79f](https://github.com/openai/openai-node/commit/258d79f52bb31f4f3723f6f4b97ebe8f3fa187bd))\n* **ecosystem-tests:** fix flaky tests and remove fine tuning calls ([#625](https://github.com/openai/openai-node/issues/625)) ([58e5fd8](https://github.com/openai/openai-node/commit/58e5fd8f27052be6ac9587256b161f4bf3a3805f))\n\n## 4.24.5 (2024-01-12)\n\nFull Changelog: [v4.24.4...v4.24.5](https://github.com/openai/openai-node/compare/v4.24.4...v4.24.5)\n\n### Refactors\n\n* **api:** remove deprecated endpoints ([#621](https://github.com/openai/openai-node/issues/621)) ([2054d71](https://github.com/openai/openai-node/commit/2054d71e6b0d407229a4c5aecd75e38c336c2c02))\n\n## 4.24.4 (2024-01-11)\n\nFull Changelog: [v4.24.3...v4.24.4](https://github.com/openai/openai-node/compare/v4.24.3...v4.24.4)\n\n### Chores\n\n* **internal:** narrow type into stringifyQuery ([#619](https://github.com/openai/openai-node/issues/619)) ([88fb9cd](https://github.com/openai/openai-node/commit/88fb9cd1bb415850b0b4868944617282d0b92e2a))\n\n## 4.24.3 (2024-01-10)\n\nFull Changelog: [v4.24.2...v4.24.3](https://github.com/openai/openai-node/compare/v4.24.2...v4.24.3)\n\n### Bug Fixes\n\n* use default base url if BASE_URL env var is blank ([#615](https://github.com/openai/openai-node/issues/615)) ([a27ad3d](https://github.com/openai/openai-node/commit/a27ad3d4e06f2202daa169668d0e7d89e87a38a7))\n\n## 4.24.2 (2024-01-08)\n\nFull Changelog: [v4.24.1...v4.24.2](https://github.com/openai/openai-node/compare/v4.24.1...v4.24.2)\n\n### Bug Fixes\n\n* **headers:** always send lowercase headers and strip undefined (BREAKING in rare cases) ([#608](https://github.com/openai/openai-node/issues/608)) ([4ea159f](https://github.com/openai/openai-node/commit/4ea159f0aa9a1f4c365c74ee726714fe692ddf9f))\n\n\n### Chores\n\n* add .keep files for examples and custom code directories ([#612](https://github.com/openai/openai-node/issues/612)) ([5e0f733](https://github.com/openai/openai-node/commit/5e0f733d3cd3c8e6d41659141168cd0708e017a3))\n* **internal:** bump license ([#605](https://github.com/openai/openai-node/issues/605)) ([045ee74](https://github.com/openai/openai-node/commit/045ee74fd3ffba9e6d1301fe1ffd8bd3c63720a2))\n* **internal:** improve type signatures ([#609](https://github.com/openai/openai-node/issues/609)) ([e1ccc82](https://github.com/openai/openai-node/commit/e1ccc82e4991262a631dcffa4d09bdc553e50fbb))\n\n\n### Documentation\n\n* fix docstring typos ([#600](https://github.com/openai/openai-node/issues/600)) ([1934fa1](https://github.com/openai/openai-node/commit/1934fa15f654ea89e226457f76febe6015616f6c))\n* improve audio example to show how to stream to a file ([#598](https://github.com/openai/openai-node/issues/598)) ([e950ad9](https://github.com/openai/openai-node/commit/e950ad969e845d608ed71bd3e3095cd6c941d93d))\n\n## 4.24.1 (2023-12-22)\n\nFull Changelog: [v4.24.0...v4.24.1](https://github.com/openai/openai-node/compare/v4.24.0...v4.24.1)\n\n### Bug Fixes\n\n* **pagination:** correct type annotation object field ([#590](https://github.com/openai/openai-node/issues/590)) ([4066eda](https://github.com/openai/openai-node/commit/4066edad4b5305e82e610f44f4720843f2b69d39))\n\n\n### Documentation\n\n* **messages:** improvements to helpers reference + typos ([#595](https://github.com/openai/openai-node/issues/595)) ([96a59b9](https://github.com/openai/openai-node/commit/96a59b91c424db67b8a5bdb7cab5da68c57282d4))\n* reformat README.md ([#592](https://github.com/openai/openai-node/issues/592)) ([8ffc7f8](https://github.com/openai/openai-node/commit/8ffc7f876cc8f4b7afaf68a37f94f826ef22a6b8))\n\n\n### Refactors\n\n* write jest config in typescript ([#588](https://github.com/openai/openai-node/issues/588)) ([eb6ceeb](https://github.com/openai/openai-node/commit/eb6ceebf90ba45ec5b803f32b9b080829f6a973a))\n\n## 4.24.0 (2023-12-19)\n\nFull Changelog: [v4.23.0...v4.24.0](https://github.com/openai/openai-node/compare/v4.23.0...v4.24.0)\n\n### Features\n\n* **api:** add additional instructions for runs ([#586](https://github.com/openai/openai-node/issues/586)) ([401d93e](https://github.com/openai/openai-node/commit/401d93ea39fe0e90088799858299322035c0a7e8))\n\n\n### Chores\n\n* **deps:** update dependency start-server-and-test to v2.0.3 ([#580](https://github.com/openai/openai-node/issues/580)) ([8e1aca1](https://github.com/openai/openai-node/commit/8e1aca1f8be6e583483919ed9ef9b04fab076066))\n* **deps:** update dependency ts-jest to v29.1.1 ([#578](https://github.com/openai/openai-node/issues/578)) ([a6edb7b](https://github.com/openai/openai-node/commit/a6edb7bc3cfc447d0c55ae23cc1c2219105d3666))\n* **deps:** update jest ([#582](https://github.com/openai/openai-node/issues/582)) ([e49e471](https://github.com/openai/openai-node/commit/e49e471ec7a136f2cbaf82551ccaaea366c87a91))\n* **internal:** bump deps ([#583](https://github.com/openai/openai-node/issues/583)) ([2e07b4c](https://github.com/openai/openai-node/commit/2e07b4c66ab1fdbb353fdd00994e293f93e981db))\n* **internal:** update deps ([#581](https://github.com/openai/openai-node/issues/581)) ([7b690dc](https://github.com/openai/openai-node/commit/7b690dca67ee8c3b0a89caf7f786ede5dc612a76))\n\n\n### Documentation\n\n* upgrade models in examples to latest version ([#585](https://github.com/openai/openai-node/issues/585)) ([60101a4](https://github.com/openai/openai-node/commit/60101a4117b1a8223d09fb9fe21d89af32431939))\n\n## 4.23.0 (2023-12-17)\n\nFull Changelog: [v4.22.1...v4.23.0](https://github.com/openai/openai-node/compare/v4.22.1...v4.23.0)\n\n### Features\n\n* **api:** add token logprobs to chat completions ([#576](https://github.com/openai/openai-node/issues/576)) ([8d4292e](https://github.com/openai/openai-node/commit/8d4292e6358920b2c9d8df49c6a154231c468512))\n\n\n### Chores\n\n* **ci:** run release workflow once per day ([#574](https://github.com/openai/openai-node/issues/574)) ([529f09f](https://github.com/openai/openai-node/commit/529f09f827a675d6e851590acff4e6f4f2af2d26))\n\n## 4.22.1 (2023-12-15)\n\nFull Changelog: [v4.22.0...v4.22.1](https://github.com/openai/openai-node/compare/v4.22.0...v4.22.1)\n\n### Chores\n\n* update dependencies ([#572](https://github.com/openai/openai-node/issues/572)) ([a51e620](https://github.com/openai/openai-node/commit/a51e62065224a516b17dd850ae564f5436d8db52))\n\n\n### Documentation\n\n* replace runFunctions with runTools in readme ([#570](https://github.com/openai/openai-node/issues/570)) ([c3b9ad5](https://github.com/openai/openai-node/commit/c3b9ad58e5f74d3339889aeb1d758c8c18f54de7))\n\n## 4.22.0 (2023-12-15)\n\nFull Changelog: [v4.21.0...v4.22.0](https://github.com/openai/openai-node/compare/v4.21.0...v4.22.0)\n\n### Features\n\n* **api:** add optional `name` argument + improve docs ([#569](https://github.com/openai/openai-node/issues/569)) ([3b68ace](https://github.com/openai/openai-node/commit/3b68ace533976aedbf642d9b018d0de8d9a8bb88))\n\n\n### Chores\n\n* update prettier ([#567](https://github.com/openai/openai-node/issues/567)) ([83dec2a](https://github.com/openai/openai-node/commit/83dec2af62c481d7de16d8a3644aa239ded9e30c))\n\n## 4.21.0 (2023-12-11)\n\nFull Changelog: [v4.20.1...v4.21.0](https://github.com/openai/openai-node/compare/v4.20.1...v4.21.0)\n\n### Features\n\n* **client:** support reading the base url from an env variable ([#547](https://github.com/openai/openai-node/issues/547)) ([06fb68d](https://github.com/openai/openai-node/commit/06fb68de1ff80983e349b6715d1037e2072c8dd4))\n\n\n### Bug Fixes\n\n* correct some runTools behavior and deprecate runFunctions ([#562](https://github.com/openai/openai-node/issues/562)) ([f5cdd0f](https://github.com/openai/openai-node/commit/f5cdd0f704d3d075cdfc5bc2df1f7a8bae5cd9f1))\n* prevent 400 when using runTools/runFunctions with Azure OpenAI API ([#544](https://github.com/openai/openai-node/issues/544)) ([735d9b8](https://github.com/openai/openai-node/commit/735d9b86acdc067e1ee6ebe1ea50de2955431050))\n\n\n### Documentation\n\n* **readme:** update example snippets ([#546](https://github.com/openai/openai-node/issues/546)) ([566d290](https://github.com/openai/openai-node/commit/566d290006920f536788bb77f4d24a6906e2971f))\n\n\n### Build System\n\n* specify `packageManager: yarn` ([#561](https://github.com/openai/openai-node/issues/561)) ([935b898](https://github.com/openai/openai-node/commit/935b8983c74f7b03b67d22f4d194989838f963f3))\n\n## 4.20.1 (2023-11-24)\n\nFull Changelog: [v4.20.0...v4.20.1](https://github.com/openai/openai-node/compare/v4.20.0...v4.20.1)\n\n### Chores\n\n* **internal:** remove file import and conditionally run prepare ([#533](https://github.com/openai/openai-node/issues/533)) ([48cb729](https://github.com/openai/openai-node/commit/48cb729bfc484ce3d04273be417b307a0d20644f))\n\n\n### Documentation\n\n* **readme:** fix typo and add examples link ([#529](https://github.com/openai/openai-node/issues/529)) ([cf959b1](https://github.com/openai/openai-node/commit/cf959b17db0a4f8dd7eb59add333c4a461b02459))\n\n## 4.20.0 (2023-11-22)\n\nFull Changelog: [v4.19.1...v4.20.0](https://github.com/openai/openai-node/compare/v4.19.1...v4.20.0)\n\n### Features\n\n* allow installing package directly from github ([#522](https://github.com/openai/openai-node/issues/522)) ([51926d7](https://github.com/openai/openai-node/commit/51926d7a0092744e49de39f4988feddf313adafa))\n\n\n### Chores\n\n* **internal:** don't call prepare in dist ([#525](https://github.com/openai/openai-node/issues/525)) ([d09411e](https://github.com/openai/openai-node/commit/d09411ebaa28d6610e1b880d03339d520b4a1833))\n\n## 4.19.1 (2023-11-20)\n\nFull Changelog: [v4.19.0...v4.19.1](https://github.com/openai/openai-node/compare/v4.19.0...v4.19.1)\n\n## 4.19.0 (2023-11-15)\n\nFull Changelog: [v4.18.0...v4.19.0](https://github.com/openai/openai-node/compare/v4.18.0...v4.19.0)\n\n### Features\n\n* **api:** updates ([#501](https://github.com/openai/openai-node/issues/501)) ([944d58e](https://github.com/openai/openai-node/commit/944d58e5fc46f1a0671aaa2b809d28e67edf6023))\n\n## 4.18.0 (2023-11-14)\n\nFull Changelog: [v4.17.5...v4.18.0](https://github.com/openai/openai-node/compare/v4.17.5...v4.18.0)\n\n### Features\n\n* **api:** add gpt-3.5-turbo-1106 ([#496](https://github.com/openai/openai-node/issues/496)) ([45f7672](https://github.com/openai/openai-node/commit/45f7672ccf4856ac309b08c6c96f0e73ab48b525))\n\n## 4.17.5 (2023-11-13)\n\nFull Changelog: [v4.17.4...v4.17.5](https://github.com/openai/openai-node/compare/v4.17.4...v4.17.5)\n\n### Chores\n\n* fix typo in docs and add request header for function calls ([#494](https://github.com/openai/openai-node/issues/494)) ([22ce244](https://github.com/openai/openai-node/commit/22ce2443a77f10988b3215bd81ba17d4eda4b10e))\n\n## 4.17.4 (2023-11-10)\n\nFull Changelog: [v4.17.3...v4.17.4](https://github.com/openai/openai-node/compare/v4.17.3...v4.17.4)\n\n### Chores\n\n* **internal:** update jest config ([#482](https://github.com/openai/openai-node/issues/482)) ([3013e8c](https://github.com/openai/openai-node/commit/3013e8c73a61a397a418ca75b996f0a7dd03a744))\n\n## 4.17.3 (2023-11-09)\n\nFull Changelog: [v4.17.2...v4.17.3](https://github.com/openai/openai-node/compare/v4.17.2...v4.17.3)\n\n## 4.17.2 (2023-11-09)\n\nFull Changelog: [v4.17.1...v4.17.2](https://github.com/openai/openai-node/compare/v4.17.1...v4.17.2)\n\n### Chores\n\n* **internal:** bump deno version number ([#478](https://github.com/openai/openai-node/issues/478)) ([69913f3](https://github.com/openai/openai-node/commit/69913f3a4b0123394029759375445dae7b4f15ab))\n\n## 4.17.1 (2023-11-09)\n\nFull Changelog: [v4.17.0...v4.17.1](https://github.com/openai/openai-node/compare/v4.17.0...v4.17.1)\n\n### Refactors\n\n* **client:** deprecate files.retrieveContent in favour of files.content ([#474](https://github.com/openai/openai-node/issues/474)) ([7c7bfc2](https://github.com/openai/openai-node/commit/7c7bfc2fad5a786c9172110e90c9566a943e49f9))\n\n## 4.17.0 (2023-11-08)\n\nFull Changelog: [v4.16.2...v4.17.0](https://github.com/openai/openai-node/compare/v4.16.2...v4.17.0)\n\n### Features\n\n* **api:** unify function types ([#467](https://github.com/openai/openai-node/issues/467)) ([d51cd94](https://github.com/openai/openai-node/commit/d51cd94b3103219789447e2e9afc4762ae672e5a))\n\n\n### Refactors\n\n* **api:** rename FunctionObject to FunctionDefinition ([#470](https://github.com/openai/openai-node/issues/470)) ([f3990c7](https://github.com/openai/openai-node/commit/f3990c779e596309b62f41d7a1253d8629aca3bf))\n\n## 4.16.2 (2023-11-08)\n\nFull Changelog: [v4.16.1...v4.16.2](https://github.com/openai/openai-node/compare/v4.16.1...v4.16.2)\n\n### Bug Fixes\n\n* **api:** accidentally required params, add new models & other fixes ([#463](https://github.com/openai/openai-node/issues/463)) ([1cb403e](https://github.com/openai/openai-node/commit/1cb403e4ccde61bb1613d362f6bdbca8b1681e00))\n* **api:** update embedding response object type ([#466](https://github.com/openai/openai-node/issues/466)) ([53b7e25](https://github.com/openai/openai-node/commit/53b7e2539cca0b272be96136c123d2b33745e7f6))\n* asssitant_deleted -&gt; assistant_deleted ([#452](https://github.com/openai/openai-node/issues/452)) ([ef89bd7](https://github.com/openai/openai-node/commit/ef89bd74d85c833bf7de500eecd1b092a0ad3f37))\n* **types:** ensure all code paths return a value ([#458](https://github.com/openai/openai-node/issues/458)) ([19402c3](https://github.com/openai/openai-node/commit/19402c365572a99cbee58bcd34a9942e741269bf))\n\n\n### Chores\n\n* **docs:** fix github links ([#457](https://github.com/openai/openai-node/issues/457)) ([6b9b94e](https://github.com/openai/openai-node/commit/6b9b94e4e123349a908b708cd574ff107f40a8e1))\n* **internal:** fix typo in comment ([#456](https://github.com/openai/openai-node/issues/456)) ([fe24342](https://github.com/openai/openai-node/commit/fe2434284a91d424510873a18079b8870469c672))\n\n\n### Documentation\n\n* update deno deploy link to include v ([#441](https://github.com/openai/openai-node/issues/441)) ([47b13aa](https://github.com/openai/openai-node/commit/47b13aaa6fac86fffabee1f752ee6d2efc3def9b))\n\n## 4.16.1 (2023-11-06)\n\nFull Changelog: [v4.16.0...v4.16.1](https://github.com/openai/openai-node/compare/v4.16.0...v4.16.1)\n\n### Bug Fixes\n\n* **api:** retreival -&gt; retrieval ([#437](https://github.com/openai/openai-node/issues/437)) ([b4bd3ee](https://github.com/openai/openai-node/commit/b4bd3eefdd3903abcc57c431382cc2124d39307b))\n\n\n### Documentation\n\n* **api:** improve docstrings ([#435](https://github.com/openai/openai-node/issues/435)) ([ee8b24c](https://github.com/openai/openai-node/commit/ee8b24c70a5ccb944e02ff2201668d6bc2b597b3))\n\n## 4.16.0 (2023-11-06)\n\nFull Changelog: [v4.15.4...v4.16.0](https://github.com/openai/openai-node/compare/v4.15.4...v4.16.0)\n\n### Features\n\n* **api:** releases from DevDay; assistants, multimodality, tools, dall-e-3, tts, and more ([#433](https://github.com/openai/openai-node/issues/433)) ([fb92f5e](https://github.com/openai/openai-node/commit/fb92f5e6e3b6e7969b3d91f4ccdaef87e5fea0a4))\n\n\n### Bug Fixes\n\n* improve deno readme ([#429](https://github.com/openai/openai-node/issues/429)) ([871ceac](https://github.com/openai/openai-node/commit/871ceac2b37f53f7fc7c0163454115c709cd7ced))\n\n\n### Documentation\n\n* deno version ([#432](https://github.com/openai/openai-node/issues/432)) ([74bf336](https://github.com/openai/openai-node/commit/74bf3364379fd23252fde01401c44b2fa796cba4))\n* update deno link in more places ([#431](https://github.com/openai/openai-node/issues/431)) ([5da63d4](https://github.com/openai/openai-node/commit/5da63d4a9143c0ab493b742f7fde22b01a372844))\n\n## 4.15.4 (2023-11-05)\n\nFull Changelog: [v4.15.3...v4.15.4](https://github.com/openai/openai-node/compare/v4.15.3...v4.15.4)\n\n### Documentation\n\n* **readme:** remove redundant whitespace ([#427](https://github.com/openai/openai-node/issues/427)) ([aa3a178](https://github.com/openai/openai-node/commit/aa3a1782914a4a285263e4d070bca73e72ed47ec))\n\n## 4.15.3 (2023-11-04)\n\nFull Changelog: [v4.15.2...v4.15.3](https://github.com/openai/openai-node/compare/v4.15.2...v4.15.3)\n\n### Bug Fixes\n\n* improve deno releases ([#425](https://github.com/openai/openai-node/issues/425)) ([19469f2](https://github.com/openai/openai-node/commit/19469f266ff69a4e549402188d9f6ad87f5a7778))\n\n## 4.15.2 (2023-11-04)\n\nFull Changelog: [v4.15.1...v4.15.2](https://github.com/openai/openai-node/compare/v4.15.1...v4.15.2)\n\n### Documentation\n\n* fix deno.land import ([#423](https://github.com/openai/openai-node/issues/423)) ([e5415a2](https://github.com/openai/openai-node/commit/e5415a29ab447ced8535fafda7928b0a6748c8d1))\n\n## 4.15.1 (2023-11-04)\n\nFull Changelog: [v4.15.0...v4.15.1](https://github.com/openai/openai-node/compare/v4.15.0...v4.15.1)\n\n### Documentation\n\n* document customizing fetch ([#420](https://github.com/openai/openai-node/issues/420)) ([1ca982f](https://github.com/openai/openai-node/commit/1ca982f192daf49e33b7acb5505ed26c9d891255))\n\n## 4.15.0 (2023-11-03)\n\nFull Changelog: [v4.14.2...v4.15.0](https://github.com/openai/openai-node/compare/v4.14.2...v4.15.0)\n\n### Features\n\n* **beta:** add streaming and function calling helpers ([#409](https://github.com/openai/openai-node/issues/409)) ([510c1f3](https://github.com/openai/openai-node/commit/510c1f325ee55197b4c2f434475128c265500746))\n* **client:** allow binary returns ([#416](https://github.com/openai/openai-node/issues/416)) ([02f7ad7](https://github.com/openai/openai-node/commit/02f7ad7f736751e0e7687e6744bae464d4e40b79))\n* **github:** include a devcontainer setup ([#413](https://github.com/openai/openai-node/issues/413)) ([fb2996f](https://github.com/openai/openai-node/commit/fb2996f0d291210878145aacf9b952f8133d9414))\n* streaming improvements ([#411](https://github.com/openai/openai-node/issues/411)) ([37b622c](https://github.com/openai/openai-node/commit/37b622c79ddbd6c286b730e740403c82b542e796))\n\n## 4.14.2 (2023-10-30)\n\nFull Changelog: [v4.14.1...v4.14.2](https://github.com/openai/openai-node/compare/v4.14.1...v4.14.2)\n\n### Chores\n\n* **docs:** update deno link ([#407](https://github.com/openai/openai-node/issues/407)) ([0328882](https://github.com/openai/openai-node/commit/0328882cccb3e5386283ffa5eb9cd8ad9442f3a0))\n\n## 4.14.1 (2023-10-27)\n\nFull Changelog: [v4.14.0...v4.14.1](https://github.com/openai/openai-node/compare/v4.14.0...v4.14.1)\n\n### Bug Fixes\n\n* deploy deno in a github workflow instead of postpublish step ([#405](https://github.com/openai/openai-node/issues/405)) ([3a6dba0](https://github.com/openai/openai-node/commit/3a6dba074258274bffcfe3a4260ca1b95bcd6bdc))\n* typo in build script ([#403](https://github.com/openai/openai-node/issues/403)) ([76c5c96](https://github.com/openai/openai-node/commit/76c5c96a359f750f58ea38b5d32365db7e34409a))\n\n\n### Chores\n\n* **internal:** update gitignore ([#406](https://github.com/openai/openai-node/issues/406)) ([986b0bb](https://github.com/openai/openai-node/commit/986b0bbac9f5ca43a0df6f29f2a468dd4223e053))\n\n## 4.14.0 (2023-10-25)\n\nFull Changelog: [v4.13.0...v4.14.0](https://github.com/openai/openai-node/compare/v4.13.0...v4.14.0)\n\n### Features\n\n* **client:** adjust retry behavior to be exponential backoff ([#400](https://github.com/openai/openai-node/issues/400)) ([2bc14ce](https://github.com/openai/openai-node/commit/2bc14ce300ef020bc045199fe3d76dd352d78ef9))\n\n\n### Chores\n\n* **docs:** update deno version ([#399](https://github.com/openai/openai-node/issues/399)) ([cdee077](https://github.com/openai/openai-node/commit/cdee0770690d4b66b357d970827e9ba1597ffb89))\n\n## 4.13.0 (2023-10-22)\n\nFull Changelog: [v4.12.4...v4.13.0](https://github.com/openai/openai-node/compare/v4.12.4...v4.13.0)\n\n### Features\n\n* **api:** add embeddings encoding_format ([#390](https://github.com/openai/openai-node/issues/390)) ([cf70dea](https://github.com/openai/openai-node/commit/cf70deaba1426786aba9b938d280c61aeb516e34))\n* handle 204 No Content gracefully ([#391](https://github.com/openai/openai-node/issues/391)) ([2dd005c](https://github.com/openai/openai-node/commit/2dd005c1c497605036d3524f19d130b3fc5f8d8b))\n\n## 4.12.4 (2023-10-17)\n\nFull Changelog: [v4.12.3...v4.12.4](https://github.com/openai/openai-node/compare/v4.12.3...v4.12.4)\n\n### Bug Fixes\n\n* import web-streams-polyfill without overriding globals ([#385](https://github.com/openai/openai-node/issues/385)) ([be8e18b](https://github.com/openai/openai-node/commit/be8e18ba4c6a16e7b6413c77246f83230e0b8fc2))\n\n## 4.12.3 (2023-10-16)\n\nFull Changelog: [v4.12.2...v4.12.3](https://github.com/openai/openai-node/compare/v4.12.2...v4.12.3)\n\n### Documentation\n\n* organisation -&gt; organization (UK to US English) ([#382](https://github.com/openai/openai-node/issues/382)) ([516f0ad](https://github.com/openai/openai-node/commit/516f0ade1ec1fd8fc4c78999ee0f656cc2b5ae58))\n\n## 4.12.2 (2023-10-16)\n\nFull Changelog: [v4.12.1...v4.12.2](https://github.com/openai/openai-node/compare/v4.12.1...v4.12.2)\n\n### Bug Fixes\n\n* **client:** correctly handle errors during streaming ([#377](https://github.com/openai/openai-node/issues/377)) ([09233b1](https://github.com/openai/openai-node/commit/09233b1ccc80ee900be19050f438cc8aa9dbb513))\n* **client:** correctly handle errors during streaming ([#379](https://github.com/openai/openai-node/issues/379)) ([9ced580](https://github.com/openai/openai-node/commit/9ced5804777a5857d6775a49ddf30ed9cc016fab))\n* improve status code in error messages ([#381](https://github.com/openai/openai-node/issues/381)) ([68dfb17](https://github.com/openai/openai-node/commit/68dfb17cce300ade8d29afc854d616833b3283ca))\n\n\n### Chores\n\n* add case insensitive get header function ([#373](https://github.com/openai/openai-node/issues/373)) ([b088998](https://github.com/openai/openai-node/commit/b088998ae610de54bb8700eefd6b664eb9a2fcc3))\n* **internal:** add debug logs for stream responses ([#380](https://github.com/openai/openai-node/issues/380)) ([689db0b](https://github.com/openai/openai-node/commit/689db0b8058527ae5c3af5e457c962d8a6635297))\n* show deprecation notice on re-export ([#368](https://github.com/openai/openai-node/issues/368)) ([b176703](https://github.com/openai/openai-node/commit/b176703102998f0e9d8ca2ed93ccd495fd10a6ee))\n* update comment ([#376](https://github.com/openai/openai-node/issues/376)) ([a06c685](https://github.com/openai/openai-node/commit/a06c6850bfdd756dc8f07dd1f70218be610faa30))\n* update comment ([#378](https://github.com/openai/openai-node/issues/378)) ([b04031d](https://github.com/openai/openai-node/commit/b04031d19210a66f82c7d233a50f7bc427a1bf92))\n\n\n### Refactors\n\n* **streaming:** change Stream constructor signature ([#370](https://github.com/openai/openai-node/issues/370)) ([71984ed](https://github.com/openai/openai-node/commit/71984edc3141ba99ffa1327bab6a182b4452209f))\n* **test:** refactor authentication tests ([#371](https://github.com/openai/openai-node/issues/371)) ([e0d459f](https://github.com/openai/openai-node/commit/e0d459f958451a99e15a11a0e5ea6471abbe1ac1))\n\n## 4.12.1 (2023-10-11)\n\nFull Changelog: [v4.12.0...v4.12.1](https://github.com/openai/openai-node/compare/v4.12.0...v4.12.1)\n\n### Bug Fixes\n\n* fix namespace exports regression ([#366](https://github.com/openai/openai-node/issues/366)) ([b2b1d85](https://github.com/openai/openai-node/commit/b2b1d85d90eef51e689ca75c0ca2f35bb63cccc0))\n\n## 4.12.0 (2023-10-11)\n\nFull Changelog: [v4.11.1...v4.12.0](https://github.com/openai/openai-node/compare/v4.11.1...v4.12.0)\n\n### Features\n\n* **api:** remove `content_filter` stop_reason and update documentation ([#352](https://github.com/openai/openai-node/issues/352)) ([a4b401e](https://github.com/openai/openai-node/commit/a4b401e91a0b3fbf55aedfb6ed6d93396377bf27))\n* re-export chat completion types at the top level, and work around webpack limitations ([#365](https://github.com/openai/openai-node/issues/365)) ([bb815d0](https://github.com/openai/openai-node/commit/bb815d0373ae33f58329e34e8983f5b3881db22d))\n\n\n### Bug Fixes\n\n* prevent ReferenceError, update compatibility to ES2020 and Node 18+ ([#356](https://github.com/openai/openai-node/issues/356)) ([fc71a4b](https://github.com/openai/openai-node/commit/fc71a4b6b73208ff3e8f0c8792a9a03e3790d26b))\n\n\n### Chores\n\n* **internal:** minor formatting improvement ([#354](https://github.com/openai/openai-node/issues/354)) ([3799863](https://github.com/openai/openai-node/commit/3799863da4ff2a27940ef0b7e57360c72e44d986))\n\n## 4.11.1 (2023-10-03)\n\nFull Changelog: [v4.11.0...v4.11.1](https://github.com/openai/openai-node/compare/v4.11.0...v4.11.1)\n\n## 4.11.0 (2023-09-29)\n\nFull Changelog: [v4.10.0...v4.11.0](https://github.com/openai/openai-node/compare/v4.10.0...v4.11.0)\n\n### Features\n\n* **client:** handle retry-after with a date ([#340](https://github.com/openai/openai-node/issues/340)) ([b6dd384](https://github.com/openai/openai-node/commit/b6dd38488ea7cc4c22495f16d027b7ffdb87da53))\n* **package:** export a root error type ([#338](https://github.com/openai/openai-node/issues/338)) ([462bcda](https://github.com/openai/openai-node/commit/462bcda7140611afa20bc25de4aec6d4b205b37d))\n\n\n### Bug Fixes\n\n* **api:** add content_filter to chat completion finish reason ([#344](https://github.com/openai/openai-node/issues/344)) ([f10c757](https://github.com/openai/openai-node/commit/f10c757d831d90407ba47b4659d9cd34b1a35b1d))\n\n\n### Chores\n\n* **internal:** bump lock file ([#334](https://github.com/openai/openai-node/issues/334)) ([fd2337b](https://github.com/openai/openai-node/commit/fd2337b018ab2f31bcea8f9feda0ddaf755390c7))\n* **internal:** update lock file ([#339](https://github.com/openai/openai-node/issues/339)) ([1bf84b6](https://github.com/openai/openai-node/commit/1bf84b672c386f8ca46bb8fc120eb8d8d48b3a82))\n* **internal:** update lock file ([#342](https://github.com/openai/openai-node/issues/342)) ([0001f06](https://github.com/openai/openai-node/commit/0001f062728b0e2047d2bf03b9d947a4be0c7206))\n* **internal:** update lock file ([#343](https://github.com/openai/openai-node/issues/343)) ([a02ac8e](https://github.com/openai/openai-node/commit/a02ac8e7f881551527a3cbcadad53b7e424650e8))\n\n## 4.10.0 (2023-09-21)\n\nFull Changelog: [v4.9.1...v4.10.0](https://github.com/openai/openai-node/compare/v4.9.1...v4.10.0)\n\n### Features\n\n* **api:** add 'gpt-3.5-turbo-instruct', fine-tune error objects, update documentation ([#329](https://github.com/openai/openai-node/issues/329)) ([e5f3852](https://github.com/openai/openai-node/commit/e5f385233737002b4bb47a94cba33da7fedfe64d))\n\n## 4.10.0 (2023-09-21)\n\nFull Changelog: [v4.9.1...v4.10.0](https://github.com/openai/openai-node/compare/v4.9.1...v4.10.0)\n\n### Features\n\n* **api:** add 'gpt-3.5-turbo-instruct', fine-tune error objects, update documentation ([#329](https://github.com/openai/openai-node/issues/329)) ([e5f3852](https://github.com/openai/openai-node/commit/e5f385233737002b4bb47a94cba33da7fedfe64d))\n\n## 4.9.1 (2023-09-21)\n\nFull Changelog: [v4.9.0...v4.9.1](https://github.com/openai/openai-node/compare/v4.9.0...v4.9.1)\n\n### Documentation\n\n* **README:** fix variable names in some examples ([#327](https://github.com/openai/openai-node/issues/327)) ([5e05b31](https://github.com/openai/openai-node/commit/5e05b31c132545ce166cea92c5f3e4410fd40711))\n\n## 4.9.0 (2023-09-20)\n\nFull Changelog: [v4.8.0...v4.9.0](https://github.com/openai/openai-node/compare/v4.8.0...v4.9.0)\n\n### Features\n\n* **client:** support importing node or web shims manually ([#325](https://github.com/openai/openai-node/issues/325)) ([628f293](https://github.com/openai/openai-node/commit/628f2935a8791625685f68f73db8f3759b8f4f91))\n\n## 4.8.0 (2023-09-15)\n\nFull Changelog: [v4.7.1...v4.8.0](https://github.com/openai/openai-node/compare/v4.7.1...v4.8.0)\n\n### Features\n\n* **errors:** add status code to error message ([#315](https://github.com/openai/openai-node/issues/315)) ([9341219](https://github.com/openai/openai-node/commit/93412197c67cb3fb203f35e3ae0a7c3fb173453e))\n\n## 4.7.1 (2023-09-15)\n\nFull Changelog: [v4.7.0...v4.7.1](https://github.com/openai/openai-node/compare/v4.7.0...v4.7.1)\n\n### Documentation\n\n* declare Bun 1.0 officially supported ([#314](https://github.com/openai/openai-node/issues/314)) ([a16e268](https://github.com/openai/openai-node/commit/a16e26863390235cb43e2fe0e569298a4f84c32f))\n\n## 4.7.0 (2023-09-14)\n\nFull Changelog: [v4.6.0...v4.7.0](https://github.com/openai/openai-node/compare/v4.6.0...v4.7.0)\n\n### Features\n\n* **client:** retry on 408 Request Timeout ([#310](https://github.com/openai/openai-node/issues/310)) ([1f98eac](https://github.com/openai/openai-node/commit/1f98eac5be956e56d75ef5456115165b45a4763c))\n* make docs urls in comments absolute ([#306](https://github.com/openai/openai-node/issues/306)) ([9db3819](https://github.com/openai/openai-node/commit/9db381961e38d2280b0602447e7d91691b327bde))\n\n## 4.6.0 (2023-09-08)\n\nFull Changelog: [v4.5.0...v4.6.0](https://github.com/openai/openai-node/compare/v4.5.0...v4.6.0)\n\n### Features\n\n* **types:** extract ChatCompletionRole enum to its own type ([#298](https://github.com/openai/openai-node/issues/298)) ([5893e37](https://github.com/openai/openai-node/commit/5893e37406ff85331c85a3baa519ca3051a28e00))\n\n\n### Bug Fixes\n\n* fix module not found errors in Vercel edge ([#300](https://github.com/openai/openai-node/issues/300)) ([47c79fe](https://github.com/openai/openai-node/commit/47c79fee0fa715ad04410e73530829602736d85f))\n\n## 4.5.0 (2023-09-06)\n\nFull Changelog: [v4.4.0...v4.5.0](https://github.com/openai/openai-node/compare/v4.4.0...v4.5.0)\n\n### Features\n\n* **client:** add files.waitForProcessing() method ([#292](https://github.com/openai/openai-node/issues/292)) ([ef59010](https://github.com/openai/openai-node/commit/ef59010cab0c666fa8a437ec6e27800789aa8705))\n* fixes tests where an array has to have unique enum values ([#290](https://github.com/openai/openai-node/issues/290)) ([a10b895](https://github.com/openai/openai-node/commit/a10b8956b3eaae7cdcb90329a8386a41219ca021))\n* make docs more readable by eliminating unnecessary escape sequences ([#287](https://github.com/openai/openai-node/issues/287)) ([a068043](https://github.com/openai/openai-node/commit/a06804314d4815d420c97f6f965c926ea70d56df))\n\n\n### Bug Fixes\n\n* **client:** fix TS errors that appear when users Go to Source in VSCode ([#281](https://github.com/openai/openai-node/issues/281)) ([8dc59bc](https://github.com/openai/openai-node/commit/8dc59bcf924cc991747ca475c714d915e04c6012)), closes [#249](https://github.com/openai/openai-node/issues/249)\n* **client:** handle case where the client is instantiated with a undefined baseURL ([#285](https://github.com/openai/openai-node/issues/285)) ([5095cf3](https://github.com/openai/openai-node/commit/5095cf340743e4627b4f0ad2f055ebe332824d23))\n* **client:** use explicit file extensions in _shims imports ([#276](https://github.com/openai/openai-node/issues/276)) ([16fe929](https://github.com/openai/openai-node/commit/16fe929688d35c2ebe52c8cf1c1570bafda5f97e))\n\n\n### Documentation\n\n* **api:** update docstrings ([#286](https://github.com/openai/openai-node/issues/286)) ([664e953](https://github.com/openai/openai-node/commit/664e9532c8acfbf981e9a788ab40c111ebe2fda0))\n* **readme:** add link to api.md ([#291](https://github.com/openai/openai-node/issues/291)) ([0d1cce2](https://github.com/openai/openai-node/commit/0d1cce26cdc6567c10c8d72bbc72a788ffb8f2be))\n\n## 4.4.0 (2023-09-01)\n\nFull Changelog: [v4.3.1...v4.4.0](https://github.com/openai/openai-node/compare/v4.3.1...v4.4.0)\n\n### Features\n\n* **package:** add Bun export map ([#269](https://github.com/openai/openai-node/issues/269)) ([16f239c](https://github.com/openai/openai-node/commit/16f239c6b4e8526371b01c511d2e0ebba4c5c8c6))\n* re-export chat completion types at the top level ([#268](https://github.com/openai/openai-node/issues/268)) ([1a71a39](https://github.com/openai/openai-node/commit/1a71a39421828fdde7b8605094363a5047d2fdc9))\n* **tests:** unskip multipart form data tests ([#275](https://github.com/openai/openai-node/issues/275)) ([47d3e18](https://github.com/openai/openai-node/commit/47d3e18a3ee987d04b958dad1a51821ad5472d54))\n* **types:** fix ambiguous auto-import for chat completions params ([#266](https://github.com/openai/openai-node/issues/266)) ([19c99fb](https://github.com/openai/openai-node/commit/19c99fb268d6d6c7fc7aaa66475c35f45d12b4bd))\n\n\n### Bug Fixes\n\n* revert import change which triggered circular import bug in webpack ([#274](https://github.com/openai/openai-node/issues/274)) ([6534e36](https://github.com/openai/openai-node/commit/6534e3620d7e2983e98b42cf95fa966deab1ab1d))\n\n## 4.3.1 (2023-08-29)\n\nFull Changelog: [v4.3.0...v4.3.1](https://github.com/openai/openai-node/compare/v4.3.0...v4.3.1)\n\n### Bug Fixes\n\n* **types:** improve getNextPage() return type ([#262](https://github.com/openai/openai-node/issues/262)) ([245a984](https://github.com/openai/openai-node/commit/245a9847d1ba5bbe5262bc06b2f7bb7385cd3a9a))\n\n\n### Chores\n\n* **ci:** setup workflows to create releases and release PRs ([#259](https://github.com/openai/openai-node/issues/259)) ([290908c](https://github.com/openai/openai-node/commit/290908ce24dc6c31df18b2eb7808d5b495387454))\n\n## [4.3.0](https://github.com/openai/openai-node/compare/v4.2.0...v4.3.0) (2023-08-27)\n\n\n### Features\n\n* **client:** add auto-pagination to fine tuning list endpoints ([#254](https://github.com/openai/openai-node/issues/254)) ([5f89c5e](https://github.com/openai/openai-node/commit/5f89c5e6b9088cc2e86405a32b60cae91c078ce1))\n* **cli:** rewrite in JS for better compatibility ([#244](https://github.com/openai/openai-node/issues/244)) ([d8d7c05](https://github.com/openai/openai-node/commit/d8d7c0592bfad89669cd2f174e6207370cd7d3fb))\n\n\n### Bug Fixes\n\n* **stream:** declare Stream.controller as public ([#252](https://github.com/openai/openai-node/issues/252)) ([81e5de7](https://github.com/openai/openai-node/commit/81e5de7ba94c992cafa3d08e2697c8122382497a))\n\n\n### Documentation\n\n* **readme:** mention Azure support ([#253](https://github.com/openai/openai-node/issues/253)) ([294727a](https://github.com/openai/openai-node/commit/294727ad3543d91ef59df285ce1616c442d369db))\n\n\n### Chores\n\n* **internal:** add helper method ([#255](https://github.com/openai/openai-node/issues/255)) ([6d8cff0](https://github.com/openai/openai-node/commit/6d8cff00164c0f65ed40b941486f2e0d752feb1e))\n\n## [4.2.0](https://github.com/openai/openai-node/compare/v4.1.0...v4.2.0) (2023-08-23)\n\n\n### Features\n\n* **types:** export RequestOptions type ([#240](https://github.com/openai/openai-node/issues/240)) ([ecf3bce](https://github.com/openai/openai-node/commit/ecf3bcee3c64a80a3cd901aa32d3db78d1364645))\n\n\n### Chores\n\n* **internal:** export HeadersInit type shim ([#241](https://github.com/openai/openai-node/issues/241)) ([cf9f672](https://github.com/openai/openai-node/commit/cf9f6729b5b232a37841c33db33b2519b54f19b2))\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "## Setting up the environment\n\nThis repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install).\nOther package managers may work but are not officially supported for development.\n\nTo set up the repository, run:\n\n```sh\n$ yarn\n$ yarn build\n```\n\nThis will install all the required dependencies and build output files to `dist/`.\n\n## Modifying/Adding code\n\nMost of the SDK is generated code. Modifications to code will be persisted between generations, but may\nresult in merge conflicts between manual patches and changes from the generator. The generator will never\nmodify the contents of the `src/lib/` and `examples/` directories.\n\n## Adding and running examples\n\nAll files in the `examples/` directory are not modified by the generator and can be freely edited or added to.\n\n```ts\n// add an example to examples/<your-example>.ts\n\n#!/usr/bin/env -S npm run tsn -T\n…\n```\n\n```sh\n$ chmod +x examples/<your-example>.ts\n# run the example against your api\n$ yarn tsn -T examples/<your-example>.ts\n```\n\n## Using the repository from source\n\nIf you’d like to use the repository from source, you can either install from git or link to a cloned repository:\n\nTo install via git:\n\n```sh\n$ npm install git+ssh://git@github.com:openai/openai-node.git\n```\n\nAlternatively, to link a local copy of the repo:\n\n```sh\n# Clone\n$ git clone https://www.github.com/openai/openai-node\n$ cd openai-node\n\n# With yarn\n$ yarn link\n$ cd ../my-package\n$ yarn link openai\n\n# With pnpm\n$ pnpm link --global\n$ cd ../my-package\n$ pnpm link --global openai\n```\n\n## Running tests\n\nMost tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.\n\n```sh\n$ ./scripts/mock\n```\n\n```sh\n$ yarn run test\n```\n\n## Linting and formatting\n\nThis repository uses [prettier](https://www.npmjs.com/package/prettier) and\n[eslint](https://www.npmjs.com/package/eslint) to format the code in the repository.\n\nTo lint:\n\n```sh\n$ yarn lint\n```\n\nTo format and fix all lint issues automatically:\n\n```sh\n$ yarn fix\n```\n\n## Publishing and releases\n\nChanges made to this repository via the automated release PR pipeline should publish to npm automatically. If\nthe changes aren't made through the automated pipeline, you may want to make releases manually.\n\n### Publish with a GitHub workflow\n\nYou can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/openai/openai-node/actions/workflows/publish-npm.yml). This requires a setup organization or repository secret to be set up.\n\n### Publish manually\n\nIf you need to manually release a package, you can run the `bin/publish-npm` script with an `NPM_TOKEN` set on\nthe environment.\n"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright 2026 OpenAI\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "MIGRATION.md",
    "content": "# Migration guide\n\nThis guide outlines the changes and steps needed to migrate your codebase to the latest version of the OpenAI TypeScript and JavaScript SDK.\n\nThe main changes are that the SDK now relies on the [builtin Web fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) instead of `node-fetch` and has zero dependencies.\n\n## Migration CLI\n\nMost programs will only need minimal changes, but to assist there is a migration tool that will automatically update your code for the new version.\nTo use it, upgrade the `openai` package, then run `./node_modules/.bin/openai migrate ./your/src/folders` to update your code.\nTo preview the changes without writing them to disk, run the tool with `--dry`.\n\n## Environment requirements\n\nThe minimum supported runtime and tooling versions are now:\n\n- Node.js 20 LTS (Most recent non-EOL Node version)\n- TypeScript 4.9\n- Jest 28\n\n## Breaking changes\n\n### Web types for `withResponse`, `asResponse`, and `APIError.headers`\n\nBecause we now use the builtin Web fetch API on all platforms, if you wrote code that used `withResponse` or `asResponse` and then accessed `node-fetch`-specific properties on the result, you will need to switch to standardized alternatives.\nFor example, `body` is now a [Web `ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) rather than a [node `Readable`](https://nodejs.org/api/stream.html#readable-streams).\n\n```ts\n// Before:\nconst res = await client.example.retrieve('string/with/slash').asResponse();\nres.body.pipe(process.stdout);\n\n// After:\nimport { Readable } from 'node:stream';\nconst res = await client.example.retrieve('string/with/slash').asResponse();\nReadable.fromWeb(res.body).pipe(process.stdout);\n```\n\nAdditionally, the `headers` property on `APIError` objects is now an instance of the Web [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) class. It was previously defined as `Record<string, string | null | undefined>`.\n\n### Named path parameters\n\nMethods that take multiple path parameters typically now use named instead of positional arguments for better clarity and to prevent a footgun where it was easy to accidentally pass arguments in the incorrect order.\n\nFor example, for a method that would call an endpoint at `/v1/parents/{parent_id}/children/{child_id}`, only the _last_ path parameter is positional and the rest must be passed as named arguments.\n\n```ts\n// Before\nclient.parents.children.retrieve('p_123', 'c_456');\n\n// After\nclient.parents.children.retrieve('c_456', { parent_id: 'p_123' });\n```\n\n<details>\n\n<summary>This affects the following methods</summary>\n\n- `client.fineTuning.checkpoints.permissions.delete()`\n- `client.vectorStores.files.retrieve()`\n- `client.vectorStores.files.update()`\n- `client.vectorStores.files.delete()`\n- `client.vectorStores.files.content()`\n- `client.vectorStores.fileBatches.retrieve()`\n- `client.vectorStores.fileBatches.cancel()`\n- `client.vectorStores.fileBatches.listFiles()`\n- `client.beta.threads.runs.retrieve()`\n- `client.beta.threads.runs.update()`\n- `client.beta.threads.runs.cancel()`\n- `client.beta.threads.runs.submitToolOutputs()`\n- `client.beta.threads.runs.steps.retrieve()`\n- `client.beta.threads.runs.steps.list()`\n- `client.beta.threads.messages.retrieve()`\n- `client.beta.threads.messages.update()`\n- `client.beta.threads.messages.delete()`\n- `client.conversations.items.retrieve()`\n- `client.conversations.items.delete()`\n- `client.evals.runs.retrieve()`\n- `client.evals.runs.delete()`\n- `client.evals.runs.cancel()`\n- `client.evals.runs.outputItems.retrieve()`\n- `client.evals.runs.outputItems.list()`\n- `client.containers.files.retrieve()`\n- `client.containers.files.delete()`\n- `client.containers.files.content.retrieve()`\n- `client.skills.versions.retrieve()`\n- `client.skills.versions.delete()`\n- `client.skills.versions.content.retrieve()`\n\n</details>\n\n### URI encoded path parameters\n\nPath params are now properly encoded by default. If you were manually encoding path parameters before giving them to the SDK, you must now stop doing that and pass the\nparam without any encoding applied.\n\nFor example:\n\n```diff\n- client.example.retrieve(encodeURIComponent('string/with/slash'))\n+ client.example.retrieve('string/with/slash') // retrieves /example/string%2Fwith%2Fslash\n```\n\nPreviously without the `encodeURIComponent()` call we would have used the path `/example/string/with/slash`; now we'll use `/example/string%2Fwith%2Fslash`.\n\n### Removed request options overloads\n\nWhen making requests with no required body, query or header parameters, you must now explicitly pass `null`, `undefined` or an empty object `{}` to the params argument in order to customise request options.\n\n```diff\nclient.example.list();\nclient.example.list({}, { headers: { ... } });\nclient.example.list(null, { headers: { ... } });\nclient.example.list(undefined, { headers: { ... } });\n- client.example.list({ headers: { ... } });\n+ client.example.list({}, { headers: { ... } });\n```\n\n<details>\n\n<summary>This affects the following methods</summary>\n\n- `client.chat.completions.list()`\n- `client.chat.completions.messages.list()`\n- `client.files.list()`\n- `client.fineTuning.jobs.list()`\n- `client.fineTuning.jobs.listEvents()`\n- `client.fineTuning.jobs.checkpoints.list()`\n- `client.fineTuning.checkpoints.permissions.retrieve()`\n- `client.fineTuning.checkpoints.permissions.list()`\n- `client.vectorStores.list()`\n- `client.vectorStores.files.list()`\n- `client.beta.chatkit.threads.list()`\n- `client.beta.chatkit.threads.listItems()`\n- `client.beta.assistants.list()`\n- `client.beta.threads.create()`\n- `client.beta.threads.runs.list()`\n- `client.beta.threads.messages.list()`\n- `client.batches.list()`\n- `client.responses.retrieve()`\n- `client.responses.inputItems.list()`\n- `client.responses.inputTokens.count()`\n- `client.realtime.calls.reject()`\n- `client.conversations.create()`\n- `client.conversations.items.list()`\n- `client.evals.list()`\n- `client.evals.runs.list()`\n- `client.containers.list()`\n- `client.containers.files.list()`\n- `client.skills.create()`\n- `client.skills.list()`\n- `client.skills.versions.create()`\n- `client.skills.versions.list()`\n- `client.videos.list()`\n- `client.videos.downloadContent()`\n\n### HTTP method naming\n\nPreviously some methods could not be named intuitively due to an internal naming conflict. This has been fixed and the affected methods are now correctly named.\n\n```ts\n// Before\nclient.chat.completions.del();\nclient.files.del();\nclient.models.del();\nclient.fineTuning.checkpoints.permissions.del();\nclient.vectorStores.del();\nclient.vectorStores.files.del();\nclient.beta.assistants.del();\nclient.beta.threads.del();\nclient.beta.threads.messages.del();\nclient.responses.del();\nclient.evals.del();\nclient.evals.runs.del();\nclient.containers.del();\nclient.containers.files.del();\n\n// After\nclient.chat.completions.delete();\nclient.files.delete();\nclient.models.delete();\nclient.fineTuning.checkpoints.permissions.delete();\nclient.vectorStores.delete();\nclient.vectorStores.files.delete();\nclient.beta.assistants.delete();\nclient.beta.threads.delete();\nclient.beta.threads.messages.delete();\nclient.responses.delete();\nclient.evals.delete();\nclient.evals.runs.delete();\nclient.containers.delete();\nclient.containers.files.delete();\n```\n\n### Removed `httpAgent` in favor of `fetchOptions`\n\nThe `httpAgent` client option has been removed in favor of a [platform-specific `fetchOptions` property](https://github.com/openai/openai-node#fetch-options).\nThis change was made as `httpAgent` relied on `node:http` agents which are not supported by any runtime's builtin fetch implementation.\n\nIf you were using `httpAgent` for proxy support, check out the [new proxy documentation](https://github.com/openai/openai-node#configuring-proxies).\n\nBefore:\n\n```ts\nimport OpenAI from 'openai';\nimport http from 'http';\nimport { HttpsProxyAgent } from 'https-proxy-agent';\n\n// Configure the default for all requests:\nconst client = new OpenAI({\n  httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),\n});\n```\n\nAfter:\n\n```ts\nimport OpenAI from 'openai';\nimport * as undici from 'undici';\n\nconst proxyAgent = new undici.ProxyAgent(process.env.PROXY_URL);\nconst client = new OpenAI({\n  fetchOptions: {\n    dispatcher: proxyAgent,\n  },\n});\n```\n\n### Changed exports\n\n#### Refactor of `openai/core`, `error`, `pagination`, `resource`, `streaming` and `uploads`\n\nMuch of the `openai/core` file was intended to be internal-only but it was publicly accessible, as such it has been refactored and split up into internal and public files, with public-facing code moved to a new `core` folder and internal code moving to the private `internal` folder.\n\nAt the same time, we moved some public-facing files which were previously at the top level into `core` to make the file structure cleaner and more clear:\n\n```typescript\n// Before\nimport 'openai/error';\nimport 'openai/pagination';\nimport 'openai/resource';\nimport 'openai/streaming';\nimport 'openai/uploads';\n\n// After\nimport 'openai/core/error';\nimport 'openai/core/pagination';\nimport 'openai/core/resource';\nimport 'openai/core/streaming';\nimport 'openai/core/uploads';\n```\n\nIf you were relying on anything that was only exported from `openai/core` and is also not accessible anywhere else, please open an issue and we'll consider adding it to the public API.\n\n#### Resource classes\n\nPreviously under certain circumstances it was possible to import resource classes like `Completions` directly from the root of the package. This was never valid at the type level and only worked in CommonJS files.\nNow you must always either reference them as static class properties or import them directly from the files in which they are defined.\n\n```typescript\n// Before\nconst { Completions } = require('openai');\n\n// After\nconst { OpenAI } = require('openai');\nOpenAI.Completions; // or import directly from openai/resources/completions\n```\n\n#### Cleaned up `uploads` exports\n\nAs part of the `core` refactor, `openai/uploads` was moved to `openai/core/uploads`\nand the following exports were removed, as they were not intended to be a part of the public API:\n\n- `fileFromPath`\n- `BlobPart`\n- `BlobLike`\n- `FileLike`\n- `ResponseLike`\n- `isResponseLike`\n- `isBlobLike`\n- `isFileLike`\n- `isUploadable`\n- `isMultipartBody`\n- `maybeMultipartFormRequestOptions`\n- `multipartFormRequestOptions`\n- `createForm`\n\nNote that `Uploadable` & `toFile` **are** still exported:\n\n```typescript\nimport { type Uploadable, toFile } from 'openai/core/uploads';\n```\n\n#### `APIClient`\n\nThe `APIClient` base client class has been removed as it is no longer needed. If you were importing this class then you must now import the main client class:\n\n```typescript\n// Before\nimport { APIClient } from 'openai/core';\n\n// After\nimport { OpenAI } from 'openai';\n```\n\n### File handling\n\nThe deprecated `fileFromPath` helper has been removed in favor of native Node.js streams:\n\n```ts\n// Before\nOpenAI.fileFromPath('path/to/file');\n\n// After\nimport fs from 'fs';\nfs.createReadStream('path/to/file');\n```\n\nNote that this function previously only worked on Node.js. If you're using Bun, you can use [`Bun.file`](https://bun.sh/docs/api/file-io) instead.\n\n### Shims removal\n\nPreviously you could configure the types that the SDK used like this:\n\n```ts\n// Tell TypeScript and the package to use the global Web fetch instead of node-fetch.\nimport 'openai/shims/web';\nimport OpenAI from 'openai';\n```\n\nThe `openai/shims` imports have been removed. Your global types must now be [correctly configured](#minimum-types-requirements).\n\n### Zod helpers optionality error\n\nPreviously, the following code would just output a warning to the console, now it will throw an error.\n\n```ts\nconst completion = await client.chat.completions.parse({\n  // ...\n  response_format: zodResponseFormat(\n    z.object({\n      optional_property: z.string().optional(),\n    }),\n    'schema',\n  ),\n});\n```\n\nYou must mark optional properties with `.nullable()` as purely optional fields are not supported by the [API](https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required).\n\n```ts\nconst completion = await client.chat.completions.parse({\n  // ...\n  response_format: zodResponseFormat(\n    z.object({\n      optional_property: z.string().optional().nullable(),\n    }),\n    'schema',\n  ),\n});\n```\n\n### Pagination changes\n\nThe `for await` syntax **is not affected**. This still works as-is:\n\n```ts\n// Automatically fetches more pages as needed.\nfor await (const fineTuningJob of client.fineTuning.jobs.list()) {\n  console.log(fineTuningJob);\n}\n```\n\nThe interface for manually paginating through list results has been simplified:\n\n```ts\n// Before\npage.nextPageParams();\npage.nextPageInfo();\n// Required manually handling { url } | { params } type\n\n// After\npage.nextPageRequestOptions();\n```\n\n#### Removed unnecessary classes\n\nPage classes for individual methods are now type aliases:\n\n```ts\n// Before\nexport class FineTuningJobsPage extends CursorPage<FineTuningJob> {}\n\n// After\nexport type FineTuningJobsPage = CursorPage<FineTuningJob>;\n```\n\nIf you were importing these classes at runtime, you'll need to switch to importing the base class or only import them at the type-level.\n\n### Beta chat namespace removed\n\nThe `beta.chat` namespace has been removed. All chat completion methods that were previously in beta have been moved to the main `chat.completions` namespace:\n\n```ts\n// Before\nclient.beta.chat.completions.parse()\nclient.beta.chat.completions.stream()\nclient.beta.chat.completions.runTools()\n\n// After\nclient.chat.completions.parse()\nclient.chat.completions.stream()\nclient.chat.completions.runTools()\n```\n\nAdditionally, related types have been moved:\n\n```ts\n// Before\nimport { ParsedChatCompletion, ParsedChoice, ParsedFunction } from 'openai/resources/beta/chat/completions';\n\n// After\nimport { ParsedChatCompletion, ParsedChoice, ParsedFunction } from 'openai/resources/chat/completions';\n```\n\n### Removed deprecated `.runFunctions` methods\n\nThe deprecated `client.chat.completions.runFunctions()` method and all of it's surrounding types have been removed, instead you should use\n`client.chat.completions.runTools()`.\n\n### `.runTools()` event / method names\n\nTo better align with the tool-based API, several event names in the ChatCompletionRunner have been renamed:\n\n```ts\n// Before\nopenai.chat.completions\n  .runTools({\n    // ..\n  })\n  .on('functionCall', (functionCall) => console.log('functionCall', functionCall))\n  .on('functionCallResult', (functionCallResult) => console.log('functionCallResult', functionCallResult))\n  .on('finalFunctionCall', (functionCall) => console.log('finalFunctionCall', functionCall))\n  .on('finalFunctionCallResult', (result) => console.log('finalFunctionCallResult', result));\n\n// After\nopenai.chat.completions\n  .runTools({\n    // ..\n  })\n  .on('functionToolCall', (functionCall) => console.log('functionCall', functionCall))\n  .on('functionToolCallResult', (functionCallResult) => console.log('functionCallResult', functionCallResult))\n  .on('finalFunctionToolCall', (functionCall) => console.log('finalFunctionCall', functionCall))\n  .on('finalFunctionToolCallResult', (result) => console.log('finalFunctionCallResult', result));\n```\n\nThe following event names have been changed:\n- `functionCall` → `functionToolCall`\n- `functionCallResult` → `functionToolCallResult`\n- `finalFunctionCall` → `finalFunctionToolCall`\n- `finalFunctionCallResult` → `finalFunctionToolCallResult`\n\nAdditionally, the following methods have been renamed:\n- `runner.finalFunctionCall()` → `runner.finalFunctionToolCall()`\n- `runner.finalFunctionCallResult()` → `runner.finalFunctionToolCallResult()`\n\n### `openai/src` directory removed\n\nPreviously IDEs may have auto-completed imports from the `openai/src` directory, however this\ndirectory was only included for an improved go-to-definition experience and should not have been used at runtime.\n\nIf you have any `openai/src/*` imports, you will need to replace them with `openai/*`.\n\n```ts\n// Before\nimport OpenAI from 'openai/src';\n\n// After\nimport OpenAI from 'openai';\n```\n\n## TypeScript troubleshooting\n\nWhen referencing the library after updating, you may encounter new type errors related to JS features like private properties or fetch classes like Request, Response, and Headers.\nTo resolve these issues, configure your tsconfig.json and install the appropriate `@types` packages for your runtime environment using the guidelines below:\n\n### Browsers\n\n`tsconfig.json`\n\n```jsonc\n{\n  \"target\": \"ES2018\", // note: we recommend ES2020 or higher\n  \"lib\": [\"DOM\", \"DOM.Iterable\", \"ES2018\"]\n}\n```\n\n### Node.js\n\n`tsconfig.json`\n\n```jsonc\n{\n  \"target\": \"ES2018\" // note: we recommend ES2020 or higher\n}\n```\n\n`package.json`\n\n```json\n{\n  \"devDependencies\": {\n    \"@types/node\": \">= 20\"\n  }\n}\n```\n\n### Cloudflare Workers\n\n`tsconfig.json`\n\n```jsonc\n{\n  \"target\": \"ES2018\", // note: we recommend ES2020 or higher\n  \"lib\": [\"ES2020\"], // <- needed by @cloudflare/workers-types\n  \"types\": [\"@cloudflare/workers-types\"]\n}\n```\n\n`package.json`\n\n```json\n{\n  \"devDependencies\": {\n    \"@cloudflare/workers-types\": \">= 0.20221111.0\"\n  }\n}\n```\n\n### Bun\n\n`tsconfig.json`\n\n```jsonc\n{\n  \"target\": \"ES2018\" // note: we recommend ES2020 or higher\n}\n```\n\n`package.json`\n\n```json\n{\n  \"devDependencies\": {\n    \"@types/bun\": \">= 1.2.0\"\n  }\n}\n```\n"
  },
  {
    "path": "README.md",
    "content": "# OpenAI TypeScript and JavaScript API Library\n\n[![NPM version](<https://img.shields.io/npm/v/openai.svg?label=npm%20(stable)>)](https://npmjs.org/package/openai) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/openai) [![JSR Version](https://jsr.io/badges/@openai/openai)](https://jsr.io/@openai/openai)\n\nThis library provides convenient access to the OpenAI REST API from TypeScript or JavaScript.\n\nIt is generated from our [OpenAPI specification](https://github.com/openai/openai-openapi) with [Stainless](https://stainlessapi.com/).\n\nTo learn how to use the OpenAI API, check out our [API Reference](https://platform.openai.com/docs/api-reference) and [Documentation](https://platform.openai.com/docs).\n\n## Installation\n\n```sh\nnpm install openai\n```\n\n### Installation from JSR\n\n```sh\ndeno add jsr:@openai/openai\nnpx jsr add @openai/openai\n```\n\nThese commands will make the module importable from the `@openai/openai` scope. You can also [import directly from JSR](https://jsr.io/docs/using-packages#importing-with-jsr-specifiers) without an install step if you're using the Deno JavaScript runtime:\n\n```ts\nimport OpenAI from 'jsr:@openai/openai';\n```\n\n## Usage\n\nThe 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).\n\nThe primary API for interacting with OpenAI models is the [Responses API](https://platform.openai.com/docs/api-reference/responses). You can generate text from the model with the code below.\n\n```ts\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted\n});\n\nconst response = await client.responses.create({\n  model: 'gpt-5.2',\n  instructions: 'You are a coding assistant that talks like a pirate',\n  input: 'Are semicolons optional in JavaScript?',\n});\n\nconsole.log(response.output_text);\n```\n\nThe previous standard (supported indefinitely) for generating text is the [Chat Completions API](https://platform.openai.com/docs/api-reference/chat). You can use that API to generate text from the model with the code below.\n\n```ts\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted\n});\n\nconst completion = await client.chat.completions.create({\n  model: 'gpt-5.2',\n  messages: [\n    { role: 'developer', content: 'Talk like a pirate.' },\n    { role: 'user', content: 'Are semicolons optional in JavaScript?' },\n  ],\n});\n\nconsole.log(completion.choices[0].message.content);\n```\n\n## Streaming responses\n\nWe provide support for streaming responses using Server Sent Events (SSE).\n\n```ts\nimport OpenAI from 'openai';\n\nconst client = new OpenAI();\n\nconst stream = await client.responses.create({\n  model: 'gpt-5.2',\n  input: 'Say \"Sheep sleep deep\" ten times fast!',\n  stream: true,\n});\n\nfor await (const event of stream) {\n  console.log(event);\n}\n```\n\n## File uploads\n\nRequest parameters that correspond to file uploads can be passed in many different forms:\n\n- `File` (or an object with the same structure)\n- a `fetch` `Response` (or an object with the same structure)\n- an `fs.ReadStream`\n- the return value of our `toFile` helper\n\n```ts\nimport fs from 'fs';\nimport OpenAI, { toFile } from 'openai';\n\nconst client = new OpenAI();\n\n// If you have access to Node `fs` we recommend using `fs.createReadStream()`:\nawait client.files.create({ file: fs.createReadStream('input.jsonl'), purpose: 'fine-tune' });\n\n// Or if you have the web `File` API you can pass a `File` instance:\nawait client.files.create({ file: new File(['my bytes'], 'input.jsonl'), purpose: 'fine-tune' });\n\n// You can also pass a `fetch` `Response`:\nawait client.files.create({\n  file: await fetch('https://somesite/input.jsonl'),\n  purpose: 'fine-tune',\n});\n\n// Finally, if none of the above are convenient, you can use our `toFile` helper:\nawait client.files.create({\n  file: await toFile(Buffer.from('my bytes'), 'input.jsonl'),\n  purpose: 'fine-tune',\n});\nawait client.files.create({\n  file: await toFile(new Uint8Array([0, 1, 2]), 'input.jsonl'),\n  purpose: 'fine-tune',\n});\n```\n\n## Webhook Verification\n\nVerifying webhook signatures is _optional but encouraged_.\n\nFor more information about webhooks, see [the API docs](https://platform.openai.com/docs/guides/webhooks).\n\n### Parsing webhook payloads\n\nFor most use cases, you will likely want to verify the webhook and parse the payload at the same time. To achieve this, we provide the method `client.webhooks.unwrap()`, which parses a webhook request and verifies that it was sent by OpenAI. This method will throw an error if the signature is invalid.\n\nNote that the `body` parameter must be the raw JSON string sent from the server (do not parse it first). The `.unwrap()` method will parse this JSON for you into an event object after verifying the webhook was sent from OpenAI.\n\n```ts\nimport { headers } from 'next/headers';\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  webhookSecret: process.env.OPENAI_WEBHOOK_SECRET, // env var used by default; explicit here.\n});\n\nexport async function webhook(request: Request) {\n  const headersList = headers();\n  const body = await request.text();\n\n  try {\n    const event = client.webhooks.unwrap(body, headersList);\n\n    switch (event.type) {\n      case 'response.completed':\n        console.log('Response completed:', event.data);\n        break;\n      case 'response.failed':\n        console.log('Response failed:', event.data);\n        break;\n      default:\n        console.log('Unhandled event type:', event.type);\n    }\n\n    return Response.json({ message: 'ok' });\n  } catch (error) {\n    console.error('Invalid webhook signature:', error);\n    return new Response('Invalid signature', { status: 400 });\n  }\n}\n```\n\n### Verifying webhook payloads directly\n\nIn some cases, you may want to verify the webhook separately from parsing the payload. If you prefer to handle these steps separately, we provide the method `client.webhooks.verifySignature()` to _only verify_ the signature of a webhook request. Like `.unwrap()`, this method will throw an error if the signature is invalid.\n\nNote that the `body` parameter must be the raw JSON string sent from the server (do not parse it first). You will then need to parse the body after verifying the signature.\n\n```ts\nimport { headers } from 'next/headers';\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  webhookSecret: process.env.OPENAI_WEBHOOK_SECRET, // env var used by default; explicit here.\n});\n\nexport async function webhook(request: Request) {\n  const headersList = headers();\n  const body = await request.text();\n\n  try {\n    client.webhooks.verifySignature(body, headersList);\n\n    // Parse the body after verification\n    const event = JSON.parse(body);\n    console.log('Verified event:', event);\n\n    return Response.json({ message: 'ok' });\n  } catch (error) {\n    console.error('Invalid webhook signature:', error);\n    return new Response('Invalid signature', { status: 400 });\n  }\n}\n```\n\n## Handling errors\n\nWhen the library is unable to connect to the API,\nor if the API returns a non-success status code (i.e., 4xx or 5xx response),\na subclass of `APIError` will be thrown:\n\n<!-- prettier-ignore -->\n```ts\nconst job = await client.fineTuning.jobs\n  .create({ model: 'gpt-4o', training_file: 'file-abc123' })\n  .catch(async (err) => {\n    if (err instanceof OpenAI.APIError) {\n      console.log(err.request_id);\n      console.log(err.status); // 400\n      console.log(err.name); // BadRequestError\n      console.log(err.headers); // {server: 'nginx', ...}\n    } else {\n      throw err;\n    }\n  });\n```\n\nError codes are as follows:\n\n| Status Code | Error Type                 |\n| ----------- | -------------------------- |\n| 400         | `BadRequestError`          |\n| 401         | `AuthenticationError`      |\n| 403         | `PermissionDeniedError`    |\n| 404         | `NotFoundError`            |\n| 422         | `UnprocessableEntityError` |\n| 429         | `RateLimitError`           |\n| >=500       | `InternalServerError`      |\n| N/A         | `APIConnectionError`       |\n\n## Request IDs\n\n> For more information on debugging requests, see [these docs](https://platform.openai.com/docs/api-reference/debugging-requests)\n\nAll 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.\n\n```ts\nconst completion = await client.chat.completions.create({\n  messages: [{ role: 'user', content: 'Say this is a test' }],\n  model: 'gpt-5.2',\n});\nconsole.log(completion._request_id); // req_123\n```\n\nYou can also access the Request ID using the `.withResponse()` method:\n\n```ts\nconst { data: stream, request_id } = await openai.chat.completions\n  .create({\n    model: 'gpt-5.2',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  })\n  .withResponse();\n```\n\n## Realtime API\n\nThe 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.\n\n```ts\nimport { OpenAIRealtimeWebSocket } from 'openai/realtime/websocket';\n\nconst rt = new OpenAIRealtimeWebSocket({ model: 'gpt-realtime' });\n\nrt.on('response.text.delta', (event) => process.stdout.write(event.delta));\n```\n\nFor more information see [realtime.md](realtime.md).\n\n## Microsoft Azure OpenAI\n\nTo use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`\nclass instead of the `OpenAI` class.\n\n> [!IMPORTANT]\n> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params\n> won't always be correct.\n\n```ts\nimport { AzureOpenAI } from 'openai';\nimport { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';\n\nconst credential = new DefaultAzureCredential();\nconst scope = 'https://cognitiveservices.azure.com/.default';\nconst azureADTokenProvider = getBearerTokenProvider(credential, scope);\n\nconst openai = new AzureOpenAI({ azureADTokenProvider });\n\nconst result = await openai.chat.completions.create({\n  model: 'gpt-5.2',\n  messages: [{ role: 'user', content: 'Say hello!' }],\n});\n\nconsole.log(result.choices[0]!.message?.content);\n```\n\n### Retries\n\nCertain errors will be automatically retried 2 times by default, with a short exponential backoff.\nConnection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,\n429 Rate Limit, and >=500 Internal errors will all be retried by default.\n\nYou can use the `maxRetries` option to configure or disable this:\n\n<!-- prettier-ignore -->\n```js\n// Configure the default for all requests:\nconst client = new OpenAI({\n  maxRetries: 0, // default is 2\n});\n\n// Or, configure per-request:\nawait client.chat.completions.create({ messages: [{ role: 'user', content: 'How can I get the name of the current day in JavaScript?' }], model: 'gpt-5.2' }, {\n  maxRetries: 5,\n});\n```\n\n### Timeouts\n\nRequests time out after 10 minutes by default. You can configure this with a `timeout` option:\n\n<!-- prettier-ignore -->\n```ts\n// Configure the default for all requests:\nconst client = new OpenAI({\n  timeout: 20 * 1000, // 20 seconds (default is 10 minutes)\n});\n\n// Override per-request:\nawait client.chat.completions.create({ messages: [{ role: 'user', content: 'How can I list all files in a directory using Python?' }], model: 'gpt-5.2' }, {\n  timeout: 5 * 1000,\n});\n```\n\nOn timeout, an `APIConnectionTimeoutError` is thrown.\n\nNote that requests which time out will be [retried twice by default](#retries).\n\n## Request IDs\n\n> For more information on debugging requests, see [these docs](https://platform.openai.com/docs/api-reference/debugging-requests)\n\nAll 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.\n\n```ts\nconst response = await client.responses.create({ model: 'gpt-5.2', input: 'testing 123' });\nconsole.log(response._request_id); // req_123\n```\n\nYou can also access the Request ID using the `.withResponse()` method:\n\n```ts\nconst { data: stream, request_id } = await openai.responses\n  .create({\n    model: 'gpt-5.2',\n    input: 'Say this is a test',\n    stream: true,\n  })\n  .withResponse();\n```\n\n## Auto-pagination\n\nList methods in the OpenAI API are paginated.\nYou can use the `for await … of` syntax to iterate through items across all pages:\n\n```ts\nasync function fetchAllFineTuningJobs(params) {\n  const allFineTuningJobs = [];\n  // Automatically fetches more pages as needed.\n  for await (const fineTuningJob of client.fineTuning.jobs.list({ limit: 20 })) {\n    allFineTuningJobs.push(fineTuningJob);\n  }\n  return allFineTuningJobs;\n}\n```\n\nAlternatively, you can request a single page at a time:\n\n```ts\nlet page = await client.fineTuning.jobs.list({ limit: 20 });\nfor (const fineTuningJob of page.data) {\n  console.log(fineTuningJob);\n}\n\n// Convenience methods are provided for manually paginating:\nwhile (page.hasNextPage()) {\n  page = await page.getNextPage();\n  // ...\n}\n```\n\n## Realtime API\n\nThe 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.\n\n```ts\nimport { OpenAIRealtimeWebSocket } from 'openai/realtime/websocket';\n\nconst rt = new OpenAIRealtimeWebSocket({ model: 'gpt-realtime' });\n\nrt.on('response.text.delta', (event) => process.stdout.write(event.delta));\n```\n\nFor more information see [realtime.md](realtime.md).\n\n## Microsoft Azure OpenAI\n\nTo use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`\nclass instead of the `OpenAI` class.\n\n> [!IMPORTANT]\n> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params\n> won't always be correct.\n\n```ts\nimport { AzureOpenAI } from 'openai';\nimport { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';\n\nconst credential = new DefaultAzureCredential();\nconst scope = 'https://cognitiveservices.azure.com/.default';\nconst azureADTokenProvider = getBearerTokenProvider(credential, scope);\n\nconst openai = new AzureOpenAI({\n  azureADTokenProvider,\n  apiVersion: '<The API version, e.g. 2024-10-01-preview>',\n});\n\nconst result = await openai.chat.completions.create({\n  model: 'gpt-5.2',\n  messages: [{ role: 'user', content: 'Say hello!' }],\n});\n\nconsole.log(result.choices[0]!.message?.content);\n```\n\nFor more information on support for the Azure API, see [azure.md](azure.md).\n\n## Advanced Usage\n\n### Accessing raw Response data (e.g., headers)\n\nThe \"raw\" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return.\nThis method returns as soon as the headers for a successful response are received and does not consume the response body, so you are free to write custom parsing or streaming logic.\n\nYou can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.\nUnlike `.asResponse()` this method consumes the body, returning once it is parsed.\n\n<!-- prettier-ignore -->\n```ts\nconst client = new OpenAI();\n\nconst httpResponse = await client.responses\n  .create({ model: 'gpt-5.2', input: 'say this is a test.' })\n  .asResponse();\n\n// access the underlying web standard Response object\nconsole.log(httpResponse.headers.get('X-My-Header'));\nconsole.log(httpResponse.statusText);\n\nconst { data: modelResponse, response: raw } = await client.responses\n  .create({ model: 'gpt-5.2', input: 'say this is a test.' })\n  .withResponse();\nconsole.log(raw.headers.get('X-My-Header'));\nconsole.log(modelResponse);\n```\n\n### Logging\n\n> [!IMPORTANT]\n> All log messages are intended for debugging only. The format and content of log messages\n> may change between releases.\n\n#### Log levels\n\nThe log level can be configured in two ways:\n\n1. Via the `OPENAI_LOG` environment variable\n2. Using the `logLevel` client option (overrides the environment variable if set)\n\n```ts\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  logLevel: 'debug', // Show all log messages\n});\n```\n\nAvailable log levels, from most to least verbose:\n\n- `'debug'` - Show debug messages, info, warnings, and errors\n- `'info'` - Show info messages, warnings, and errors\n- `'warn'` - Show warnings and errors (default)\n- `'error'` - Show only errors\n- `'off'` - Disable all logging\n\nAt the `'debug'` level, all HTTP requests and responses are logged, including headers and bodies.\nSome authentication-related headers are redacted, but sensitive data in request and response bodies\nmay still be visible.\n\n#### Custom logger\n\nBy default, this library logs to `globalThis.console`. You can also provide a custom logger.\nMost logging libraries are supported, including [pino](https://www.npmjs.com/package/pino), [winston](https://www.npmjs.com/package/winston), [bunyan](https://www.npmjs.com/package/bunyan), [consola](https://www.npmjs.com/package/consola), [signale](https://www.npmjs.com/package/signale), and [@std/log](https://jsr.io/@std/log). If your logger doesn't work, please open an issue.\n\nWhen providing a custom logger, the `logLevel` option still controls which messages are emitted, messages\nbelow the configured level will not be sent to your logger.\n\n```ts\nimport OpenAI from 'openai';\nimport pino from 'pino';\n\nconst logger = pino();\n\nconst client = new OpenAI({\n  logger: logger.child({ name: 'OpenAI' }),\n  logLevel: 'debug', // Send all messages to pino, allowing it to filter\n});\n```\n\n### Making custom/undocumented requests\n\nThis library is typed for convenient access to the documented API. If you need to access undocumented\nendpoints, params, or response properties, the library can still be used.\n\n#### Undocumented endpoints\n\nTo make requests to undocumented endpoints, you can use `client.get`, `client.post`, and other HTTP verbs.\nOptions on the client, such as retries, will be respected when making these requests.\n\n```ts\nawait client.post('/some/path', {\n  body: { some_prop: 'foo' },\n  query: { some_query_arg: 'bar' },\n});\n```\n\n#### Undocumented request params\n\nTo make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented\nparameter. This library doesn't validate at runtime that the request matches the type, so any extra values you\nsend will be sent as-is.\n\n```ts\nclient.chat.completions.create({\n  // ...\n  // @ts-expect-error baz is not yet public\n  baz: 'undocumented option',\n});\n```\n\nFor requests with the `GET` verb, any extra params will be in the query, all other requests will send the\nextra param in the body.\n\nIf you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request\noptions.\n\n#### Undocumented response properties\n\nTo access undocumented response properties, you may access the response object with `// @ts-expect-error` on\nthe response object, or cast the response object to the requisite type. Like the request params, we do not\nvalidate or strip extra properties from the response from the API.\n\n### Customizing the fetch client\n\nIf you want to use a different `fetch` function, you can either polyfill the global:\n\n```ts\nimport fetch from 'my-fetch';\n\nglobalThis.fetch = fetch;\n```\n\nOr pass it to the client:\n\n```ts\nimport OpenAI from 'openai';\nimport fetch from 'my-fetch';\n\nconst client = new OpenAI({ fetch });\n```\n\n### Fetch options\n\nIf you want to set custom `fetch` options without overriding the `fetch` function, you can provide a `fetchOptions` object when instantiating the client or making a request. (Request-specific options override client options.)\n\n```ts\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  fetchOptions: {\n    // `RequestInit` options\n  },\n});\n```\n\n#### Configuring proxies\n\nTo modify proxy behavior, you can provide custom `fetchOptions` that add runtime-specific proxy\noptions to requests:\n\n<img src=\"https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/node.svg\" align=\"top\" width=\"18\" height=\"21\"> **Node** <sup>[[docs](https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md#example---proxyagent-with-fetch)]</sup>\n\n```ts\nimport OpenAI from 'openai';\nimport * as undici from 'undici';\n\nconst proxyAgent = new undici.ProxyAgent('http://localhost:8888');\nconst client = new OpenAI({\n  fetchOptions: {\n    dispatcher: proxyAgent,\n  },\n});\n```\n\n<img src=\"https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/bun.svg\" align=\"top\" width=\"18\" height=\"21\"> **Bun** <sup>[[docs](https://bun.sh/guides/http/proxy)]</sup>\n\n```ts\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  fetchOptions: {\n    proxy: 'http://localhost:8888',\n  },\n});\n```\n\n<img src=\"https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/deno.svg\" align=\"top\" width=\"18\" height=\"21\"> **Deno** <sup>[[docs](https://docs.deno.com/api/deno/~/Deno.createHttpClient)]</sup>\n\n```ts\nimport OpenAI from 'npm:openai';\n\nconst httpClient = Deno.createHttpClient({ proxy: { url: 'http://localhost:8888' } });\nconst client = new OpenAI({\n  fetchOptions: {\n    client: httpClient,\n  },\n});\n```\n\n## Frequently Asked Questions\n\n## Semantic versioning\n\nThis package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:\n\n1. Changes that only affect static types, without breaking runtime behavior.\n2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_\n3. Changes that we do not expect to impact the vast majority of users in practice.\n\nWe take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.\n\nWe are keen for your feedback; please open an [issue](https://www.github.com/openai/openai-node/issues) with questions, bugs, or suggestions.\n\n## Requirements\n\nTypeScript >= 4.9 is supported.\n\nThe following runtimes are supported:\n\n- Node.js 20 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.\n- Deno v1.28.0 or higher.\n- Bun 1.0 or later.\n- Cloudflare Workers.\n- Vercel Edge Runtime.\n- Jest 28 or greater with the `\"node\"` environment (`\"jsdom\"` is not supported at this time).\n- Nitro v2.6 or greater.\n- Web browsers: disabled by default to avoid exposing your secret API credentials. Enable browser support by explicitly setting `dangerouslyAllowBrowser` to true'.\n  <details>\n    <summary>More explanation</summary>\n\n  ### Why is this dangerous?\n\n  Enabling the `dangerouslyAllowBrowser` option can be dangerous because it exposes your secret API credentials in the client-side code. Web browsers are inherently less secure than server environments,\n  any user with access to the browser can potentially inspect, extract, and misuse these credentials. This could lead to unauthorized access using your credentials and potentially compromise sensitive data or functionality.\n\n  ### When might this not be dangerous?\n\n  In certain scenarios where enabling browser support might not pose significant risks:\n\n  - Internal Tools: If the application is used solely within a controlled internal environment where the users are trusted, the risk of credential exposure can be mitigated.\n  - Public APIs with Limited Scope: If your API has very limited scope and the exposed credentials do not grant access to sensitive data or critical operations, the potential impact of exposure is reduced.\n  - Development or debugging purpose: Enabling this feature temporarily might be acceptable, provided the credentials are short-lived, aren't also used in production environments, or are frequently rotated.\n\n</details>\n\nNote that React Native is not supported at this time.\n\nIf you are interested in other runtime environments, please open or upvote an issue on GitHub.\n\n## Contributing\n\nSee [the contributing documentation](./CONTRIBUTING.md).\n"
  },
  {
    "path": "SECURITY.md",
    "content": "# Security Policy\n\n## Reporting Security Issues\n\nThis SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.\n\nTo report a security issue, please contact the Stainless team at security@stainless.com.\n\n## Responsible Disclosure\n\nWe appreciate the efforts of security researchers and individuals who help us maintain the security of\nSDKs we generate. If you believe you have found a security vulnerability, please adhere to responsible\ndisclosure practices by allowing us a reasonable amount of time to investigate and address the issue\nbefore making any information public.\n\n## Reporting Non-SDK Related Security Issues\n\nIf you encounter security issues that are not directly related to SDKs but pertain to the services\nor products provided by OpenAI, please follow the respective company's security reporting guidelines.\n\n### OpenAI Terms and Policies\n\nOur Security Policy can be found at [Security Policy URL](https://openai.com/policies/coordinated-vulnerability-disclosure-policy).\n\nPlease contact disclosure@openai.com for any questions or concerns regarding the security of our services.\n\n---\n\nThank you for helping us keep the SDKs and systems they interact with secure.\n"
  },
  {
    "path": "api.md",
    "content": "# Shared\n\nTypes:\n\n- <code><a href=\"./src/resources/shared.ts\">AllModels</a></code>\n- <code><a href=\"./src/resources/shared.ts\">ChatModel</a></code>\n- <code><a href=\"./src/resources/shared.ts\">ComparisonFilter</a></code>\n- <code><a href=\"./src/resources/shared.ts\">CompoundFilter</a></code>\n- <code><a href=\"./src/resources/shared.ts\">CustomToolInputFormat</a></code>\n- <code><a href=\"./src/resources/shared.ts\">ErrorObject</a></code>\n- <code><a href=\"./src/resources/shared.ts\">FunctionDefinition</a></code>\n- <code><a href=\"./src/resources/shared.ts\">FunctionParameters</a></code>\n- <code><a href=\"./src/resources/shared.ts\">Metadata</a></code>\n- <code><a href=\"./src/resources/shared.ts\">Reasoning</a></code>\n- <code><a href=\"./src/resources/shared.ts\">ReasoningEffort</a></code>\n- <code><a href=\"./src/resources/shared.ts\">ResponseFormatJSONObject</a></code>\n- <code><a href=\"./src/resources/shared.ts\">ResponseFormatJSONSchema</a></code>\n- <code><a href=\"./src/resources/shared.ts\">ResponseFormatText</a></code>\n- <code><a href=\"./src/resources/shared.ts\">ResponseFormatTextGrammar</a></code>\n- <code><a href=\"./src/resources/shared.ts\">ResponseFormatTextPython</a></code>\n- <code><a href=\"./src/resources/shared.ts\">ResponsesModel</a></code>\n\n# Completions\n\nTypes:\n\n- <code><a href=\"./src/resources/completions.ts\">Completion</a></code>\n- <code><a href=\"./src/resources/completions.ts\">CompletionChoice</a></code>\n- <code><a href=\"./src/resources/completions.ts\">CompletionUsage</a></code>\n\nMethods:\n\n- <code title=\"post /completions\">client.completions.<a href=\"./src/resources/completions.ts\">create</a>({ ...params }) -> Completion</code>\n\n# Chat\n\nTypes:\n\n- <code><a href=\"./src/resources/chat/chat.ts\">ChatModel</a></code>\n\n## Completions\n\nTypes:\n\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletion</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionAllowedToolChoice</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionAssistantMessageParam</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionAudio</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionAudioParam</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionChunk</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionContentPart</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionContentPartImage</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionContentPartInputAudio</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionContentPartRefusal</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionContentPartText</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionCustomTool</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionDeleted</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionDeveloperMessageParam</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionFunctionCallOption</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionFunctionMessageParam</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionFunctionTool</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionMessage</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionMessageCustomToolCall</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionMessageFunctionToolCall</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionMessageParam</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionMessageToolCall</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionModality</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionNamedToolChoice</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionNamedToolChoiceCustom</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionPredictionContent</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionRole</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionStoreMessage</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionStreamOptions</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionSystemMessageParam</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionTokenLogprob</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionTool</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionToolChoiceOption</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionToolMessageParam</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionUserMessageParam</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionAllowedTools</a></code>\n- <code><a href=\"./src/resources/chat/completions/completions.ts\">ChatCompletionReasoningEffort</a></code>\n\nMethods:\n\n- <code title=\"post /chat/completions\">client.chat.completions.<a href=\"./src/resources/chat/completions/completions.ts\">create</a>({ ...params }) -> ChatCompletion</code>\n- <code title=\"get /chat/completions/{completion_id}\">client.chat.completions.<a href=\"./src/resources/chat/completions/completions.ts\">retrieve</a>(completionID) -> ChatCompletion</code>\n- <code title=\"post /chat/completions/{completion_id}\">client.chat.completions.<a href=\"./src/resources/chat/completions/completions.ts\">update</a>(completionID, { ...params }) -> ChatCompletion</code>\n- <code title=\"get /chat/completions\">client.chat.completions.<a href=\"./src/resources/chat/completions/completions.ts\">list</a>({ ...params }) -> ChatCompletionsPage</code>\n- <code title=\"delete /chat/completions/{completion_id}\">client.chat.completions.<a href=\"./src/resources/chat/completions/completions.ts\">delete</a>(completionID) -> ChatCompletionDeleted</code>\n\n### Messages\n\nMethods:\n\n- <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>\n\n# Embeddings\n\nTypes:\n\n- <code><a href=\"./src/resources/embeddings.ts\">CreateEmbeddingResponse</a></code>\n- <code><a href=\"./src/resources/embeddings.ts\">Embedding</a></code>\n- <code><a href=\"./src/resources/embeddings.ts\">EmbeddingModel</a></code>\n\nMethods:\n\n- <code title=\"post /embeddings\">client.embeddings.<a href=\"./src/resources/embeddings.ts\">create</a>({ ...params }) -> CreateEmbeddingResponse</code>\n\n# Files\n\nTypes:\n\n- <code><a href=\"./src/resources/files.ts\">FileContent</a></code>\n- <code><a href=\"./src/resources/files.ts\">FileDeleted</a></code>\n- <code><a href=\"./src/resources/files.ts\">FileObject</a></code>\n- <code><a href=\"./src/resources/files.ts\">FilePurpose</a></code>\n\nMethods:\n\n- <code title=\"post /files\">client.files.<a href=\"./src/resources/files.ts\">create</a>({ ...params }) -> FileObject</code>\n- <code title=\"get /files/{file_id}\">client.files.<a href=\"./src/resources/files.ts\">retrieve</a>(fileID) -> FileObject</code>\n- <code title=\"get /files\">client.files.<a href=\"./src/resources/files.ts\">list</a>({ ...params }) -> FileObjectsPage</code>\n- <code title=\"delete /files/{file_id}\">client.files.<a href=\"./src/resources/files.ts\">delete</a>(fileID) -> FileDeleted</code>\n- <code title=\"get /files/{file_id}/content\">client.files.<a href=\"./src/resources/files.ts\">content</a>(fileID) -> Response</code>\n- <code>client.files.<a href=\"./src/resources/files.ts\">waitForProcessing</a>(id, { pollInterval = 5000, maxWait = 30 * 60 * 1000 }) -> Promise&lt;FileObject&gt;</code>\n\n# Images\n\nTypes:\n\n- <code><a href=\"./src/resources/images.ts\">Image</a></code>\n- <code><a href=\"./src/resources/images.ts\">ImageEditCompletedEvent</a></code>\n- <code><a href=\"./src/resources/images.ts\">ImageEditPartialImageEvent</a></code>\n- <code><a href=\"./src/resources/images.ts\">ImageEditStreamEvent</a></code>\n- <code><a href=\"./src/resources/images.ts\">ImageGenCompletedEvent</a></code>\n- <code><a href=\"./src/resources/images.ts\">ImageGenPartialImageEvent</a></code>\n- <code><a href=\"./src/resources/images.ts\">ImageGenStreamEvent</a></code>\n- <code><a href=\"./src/resources/images.ts\">ImageModel</a></code>\n- <code><a href=\"./src/resources/images.ts\">ImagesResponse</a></code>\n\nMethods:\n\n- <code title=\"post /images/variations\">client.images.<a href=\"./src/resources/images.ts\">createVariation</a>({ ...params }) -> ImagesResponse</code>\n- <code title=\"post /images/edits\">client.images.<a href=\"./src/resources/images.ts\">edit</a>({ ...params }) -> ImagesResponse</code>\n- <code title=\"post /images/generations\">client.images.<a href=\"./src/resources/images.ts\">generate</a>({ ...params }) -> ImagesResponse</code>\n\n# Audio\n\nTypes:\n\n- <code><a href=\"./src/resources/audio/audio.ts\">AudioModel</a></code>\n- <code><a href=\"./src/resources/audio/audio.ts\">AudioResponseFormat</a></code>\n\n## Transcriptions\n\nTypes:\n\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">Transcription</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionDiarized</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionDiarizedSegment</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionInclude</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionSegment</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionStreamEvent</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionTextDeltaEvent</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionTextDoneEvent</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionTextSegmentEvent</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionVerbose</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionWord</a></code>\n- <code><a href=\"./src/resources/audio/transcriptions.ts\">TranscriptionCreateResponse</a></code>\n\nMethods:\n\n- <code title=\"post /audio/transcriptions\">client.audio.transcriptions.<a href=\"./src/resources/audio/transcriptions.ts\">create</a>({ ...params }) -> TranscriptionCreateResponse</code>\n\n## Translations\n\nTypes:\n\n- <code><a href=\"./src/resources/audio/translations.ts\">Translation</a></code>\n- <code><a href=\"./src/resources/audio/translations.ts\">TranslationVerbose</a></code>\n- <code><a href=\"./src/resources/audio/translations.ts\">TranslationCreateResponse</a></code>\n\nMethods:\n\n- <code title=\"post /audio/translations\">client.audio.translations.<a href=\"./src/resources/audio/translations.ts\">create</a>({ ...params }) -> TranslationCreateResponse</code>\n\n## Speech\n\nTypes:\n\n- <code><a href=\"./src/resources/audio/speech.ts\">SpeechModel</a></code>\n\nMethods:\n\n- <code title=\"post /audio/speech\">client.audio.speech.<a href=\"./src/resources/audio/speech.ts\">create</a>({ ...params }) -> Response</code>\n\n# Moderations\n\nTypes:\n\n- <code><a href=\"./src/resources/moderations.ts\">Moderation</a></code>\n- <code><a href=\"./src/resources/moderations.ts\">ModerationImageURLInput</a></code>\n- <code><a href=\"./src/resources/moderations.ts\">ModerationModel</a></code>\n- <code><a href=\"./src/resources/moderations.ts\">ModerationMultiModalInput</a></code>\n- <code><a href=\"./src/resources/moderations.ts\">ModerationTextInput</a></code>\n- <code><a href=\"./src/resources/moderations.ts\">ModerationCreateResponse</a></code>\n\nMethods:\n\n- <code title=\"post /moderations\">client.moderations.<a href=\"./src/resources/moderations.ts\">create</a>({ ...params }) -> ModerationCreateResponse</code>\n\n# Models\n\nTypes:\n\n- <code><a href=\"./src/resources/models.ts\">Model</a></code>\n- <code><a href=\"./src/resources/models.ts\">ModelDeleted</a></code>\n\nMethods:\n\n- <code title=\"get /models/{model}\">client.models.<a href=\"./src/resources/models.ts\">retrieve</a>(model) -> Model</code>\n- <code title=\"get /models\">client.models.<a href=\"./src/resources/models.ts\">list</a>() -> ModelsPage</code>\n- <code title=\"delete /models/{model}\">client.models.<a href=\"./src/resources/models.ts\">delete</a>(model) -> ModelDeleted</code>\n\n# FineTuning\n\n## Methods\n\nTypes:\n\n- <code><a href=\"./src/resources/fine-tuning/methods.ts\">DpoHyperparameters</a></code>\n- <code><a href=\"./src/resources/fine-tuning/methods.ts\">DpoMethod</a></code>\n- <code><a href=\"./src/resources/fine-tuning/methods.ts\">ReinforcementHyperparameters</a></code>\n- <code><a href=\"./src/resources/fine-tuning/methods.ts\">ReinforcementMethod</a></code>\n- <code><a href=\"./src/resources/fine-tuning/methods.ts\">SupervisedHyperparameters</a></code>\n- <code><a href=\"./src/resources/fine-tuning/methods.ts\">SupervisedMethod</a></code>\n\n## Jobs\n\nTypes:\n\n- <code><a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">FineTuningJob</a></code>\n- <code><a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">FineTuningJobEvent</a></code>\n- <code><a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">FineTuningJobWandbIntegration</a></code>\n- <code><a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">FineTuningJobWandbIntegrationObject</a></code>\n- <code><a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">FineTuningJobIntegration</a></code>\n\nMethods:\n\n- <code title=\"post /fine_tuning/jobs\">client.fineTuning.jobs.<a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">create</a>({ ...params }) -> FineTuningJob</code>\n- <code title=\"get /fine_tuning/jobs/{fine_tuning_job_id}\">client.fineTuning.jobs.<a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">retrieve</a>(fineTuningJobID) -> FineTuningJob</code>\n- <code title=\"get /fine_tuning/jobs\">client.fineTuning.jobs.<a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">list</a>({ ...params }) -> FineTuningJobsPage</code>\n- <code title=\"post /fine_tuning/jobs/{fine_tuning_job_id}/cancel\">client.fineTuning.jobs.<a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">cancel</a>(fineTuningJobID) -> FineTuningJob</code>\n- <code title=\"get /fine_tuning/jobs/{fine_tuning_job_id}/events\">client.fineTuning.jobs.<a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">listEvents</a>(fineTuningJobID, { ...params }) -> FineTuningJobEventsPage</code>\n- <code title=\"post /fine_tuning/jobs/{fine_tuning_job_id}/pause\">client.fineTuning.jobs.<a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">pause</a>(fineTuningJobID) -> FineTuningJob</code>\n- <code title=\"post /fine_tuning/jobs/{fine_tuning_job_id}/resume\">client.fineTuning.jobs.<a href=\"./src/resources/fine-tuning/jobs/jobs.ts\">resume</a>(fineTuningJobID) -> FineTuningJob</code>\n\n### Checkpoints\n\nTypes:\n\n- <code><a href=\"./src/resources/fine-tuning/jobs/checkpoints.ts\">FineTuningJobCheckpoint</a></code>\n\nMethods:\n\n- <code title=\"get /fine_tuning/jobs/{fine_tuning_job_id}/checkpoints\">client.fineTuning.jobs.checkpoints.<a href=\"./src/resources/fine-tuning/jobs/checkpoints.ts\">list</a>(fineTuningJobID, { ...params }) -> FineTuningJobCheckpointsPage</code>\n\n## Checkpoints\n\n### Permissions\n\nTypes:\n\n- <code><a href=\"./src/resources/fine-tuning/checkpoints/permissions.ts\">PermissionCreateResponse</a></code>\n- <code><a href=\"./src/resources/fine-tuning/checkpoints/permissions.ts\">PermissionRetrieveResponse</a></code>\n- <code><a href=\"./src/resources/fine-tuning/checkpoints/permissions.ts\">PermissionListResponse</a></code>\n- <code><a href=\"./src/resources/fine-tuning/checkpoints/permissions.ts\">PermissionDeleteResponse</a></code>\n\nMethods:\n\n- <code title=\"post /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions\">client.fineTuning.checkpoints.permissions.<a href=\"./src/resources/fine-tuning/checkpoints/permissions.ts\">create</a>(fineTunedModelCheckpoint, { ...params }) -> PermissionCreateResponsesPage</code>\n- <code title=\"get /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions\">client.fineTuning.checkpoints.permissions.<a href=\"./src/resources/fine-tuning/checkpoints/permissions.ts\">retrieve</a>(fineTunedModelCheckpoint, { ...params }) -> PermissionRetrieveResponse</code>\n- <code title=\"get /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions\">client.fineTuning.checkpoints.permissions.<a href=\"./src/resources/fine-tuning/checkpoints/permissions.ts\">list</a>(fineTunedModelCheckpoint, { ...params }) -> PermissionListResponsesPage</code>\n- <code title=\"delete /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions/{permission_id}\">client.fineTuning.checkpoints.permissions.<a href=\"./src/resources/fine-tuning/checkpoints/permissions.ts\">delete</a>(permissionID, { ...params }) -> PermissionDeleteResponse</code>\n\n## Alpha\n\n### Graders\n\nTypes:\n\n- <code><a href=\"./src/resources/fine-tuning/alpha/graders.ts\">GraderRunResponse</a></code>\n- <code><a href=\"./src/resources/fine-tuning/alpha/graders.ts\">GraderValidateResponse</a></code>\n\nMethods:\n\n- <code title=\"post /fine_tuning/alpha/graders/run\">client.fineTuning.alpha.graders.<a href=\"./src/resources/fine-tuning/alpha/graders.ts\">run</a>({ ...params }) -> GraderRunResponse</code>\n- <code title=\"post /fine_tuning/alpha/graders/validate\">client.fineTuning.alpha.graders.<a href=\"./src/resources/fine-tuning/alpha/graders.ts\">validate</a>({ ...params }) -> GraderValidateResponse</code>\n\n# Graders\n\n## GraderModels\n\nTypes:\n\n- <code><a href=\"./src/resources/graders/grader-models.ts\">GraderInputs</a></code>\n- <code><a href=\"./src/resources/graders/grader-models.ts\">LabelModelGrader</a></code>\n- <code><a href=\"./src/resources/graders/grader-models.ts\">MultiGrader</a></code>\n- <code><a href=\"./src/resources/graders/grader-models.ts\">PythonGrader</a></code>\n- <code><a href=\"./src/resources/graders/grader-models.ts\">ScoreModelGrader</a></code>\n- <code><a href=\"./src/resources/graders/grader-models.ts\">StringCheckGrader</a></code>\n- <code><a href=\"./src/resources/graders/grader-models.ts\">TextSimilarityGrader</a></code>\n\n# VectorStores\n\nTypes:\n\n- <code><a href=\"./src/resources/vector-stores/vector-stores.ts\">AutoFileChunkingStrategyParam</a></code>\n- <code><a href=\"./src/resources/vector-stores/vector-stores.ts\">FileChunkingStrategy</a></code>\n- <code><a href=\"./src/resources/vector-stores/vector-stores.ts\">FileChunkingStrategyParam</a></code>\n- <code><a href=\"./src/resources/vector-stores/vector-stores.ts\">OtherFileChunkingStrategyObject</a></code>\n- <code><a href=\"./src/resources/vector-stores/vector-stores.ts\">StaticFileChunkingStrategy</a></code>\n- <code><a href=\"./src/resources/vector-stores/vector-stores.ts\">StaticFileChunkingStrategyObject</a></code>\n- <code><a href=\"./src/resources/vector-stores/vector-stores.ts\">StaticFileChunkingStrategyObjectParam</a></code>\n- <code><a href=\"./src/resources/vector-stores/vector-stores.ts\">VectorStore</a></code>\n- <code><a href=\"./src/resources/vector-stores/vector-stores.ts\">VectorStoreDeleted</a></code>\n- <code><a href=\"./src/resources/vector-stores/vector-stores.ts\">VectorStoreSearchResponse</a></code>\n\nMethods:\n\n- <code title=\"post /vector_stores\">client.vectorStores.<a href=\"./src/resources/vector-stores/vector-stores.ts\">create</a>({ ...params }) -> VectorStore</code>\n- <code title=\"get /vector_stores/{vector_store_id}\">client.vectorStores.<a href=\"./src/resources/vector-stores/vector-stores.ts\">retrieve</a>(vectorStoreID) -> VectorStore</code>\n- <code title=\"post /vector_stores/{vector_store_id}\">client.vectorStores.<a href=\"./src/resources/vector-stores/vector-stores.ts\">update</a>(vectorStoreID, { ...params }) -> VectorStore</code>\n- <code title=\"get /vector_stores\">client.vectorStores.<a href=\"./src/resources/vector-stores/vector-stores.ts\">list</a>({ ...params }) -> VectorStoresPage</code>\n- <code title=\"delete /vector_stores/{vector_store_id}\">client.vectorStores.<a href=\"./src/resources/vector-stores/vector-stores.ts\">delete</a>(vectorStoreID) -> VectorStoreDeleted</code>\n- <code title=\"post /vector_stores/{vector_store_id}/search\">client.vectorStores.<a href=\"./src/resources/vector-stores/vector-stores.ts\">search</a>(vectorStoreID, { ...params }) -> VectorStoreSearchResponsesPage</code>\n\n## Files\n\nTypes:\n\n- <code><a href=\"./src/resources/vector-stores/files.ts\">VectorStoreFile</a></code>\n- <code><a href=\"./src/resources/vector-stores/files.ts\">VectorStoreFileDeleted</a></code>\n- <code><a href=\"./src/resources/vector-stores/files.ts\">FileContentResponse</a></code>\n\nMethods:\n\n- <code title=\"post /vector_stores/{vector_store_id}/files\">client.vectorStores.files.<a href=\"./src/resources/vector-stores/files.ts\">create</a>(vectorStoreID, { ...params }) -> VectorStoreFile</code>\n- <code title=\"get /vector_stores/{vector_store_id}/files/{file_id}\">client.vectorStores.files.<a href=\"./src/resources/vector-stores/files.ts\">retrieve</a>(fileID, { ...params }) -> VectorStoreFile</code>\n- <code title=\"post /vector_stores/{vector_store_id}/files/{file_id}\">client.vectorStores.files.<a href=\"./src/resources/vector-stores/files.ts\">update</a>(fileID, { ...params }) -> VectorStoreFile</code>\n- <code title=\"get /vector_stores/{vector_store_id}/files\">client.vectorStores.files.<a href=\"./src/resources/vector-stores/files.ts\">list</a>(vectorStoreID, { ...params }) -> VectorStoreFilesPage</code>\n- <code title=\"delete /vector_stores/{vector_store_id}/files/{file_id}\">client.vectorStores.files.<a href=\"./src/resources/vector-stores/files.ts\">delete</a>(fileID, { ...params }) -> VectorStoreFileDeleted</code>\n- <code title=\"get /vector_stores/{vector_store_id}/files/{file_id}/content\">client.vectorStores.files.<a href=\"./src/resources/vector-stores/files.ts\">content</a>(fileID, { ...params }) -> FileContentResponsesPage</code>\n- <code>client.vectorStores.files.<a href=\"./src/resources/vector-stores/files.ts\">createAndPoll</a>(vectorStoreId, body, options?) -> Promise&lt;VectorStoreFile&gt;</code>\n- <code>client.vectorStores.files.<a href=\"./src/resources/vector-stores/files.ts\">poll</a>(vectorStoreId, fileId, options?) -> Promise&lt;VectorStoreFile&gt;</code>\n- <code>client.vectorStores.files.<a href=\"./src/resources/vector-stores/files.ts\">upload</a>(vectorStoreId, file, options?) -> Promise&lt;VectorStoreFile&gt;</code>\n- <code>client.vectorStores.files.<a href=\"./src/resources/vector-stores/files.ts\">uploadAndPoll</a>(vectorStoreId, file, options?) -> Promise&lt;VectorStoreFile&gt;</code>\n\n## FileBatches\n\nTypes:\n\n- <code><a href=\"./src/resources/vector-stores/file-batches.ts\">VectorStoreFileBatch</a></code>\n\nMethods:\n\n- <code title=\"post /vector_stores/{vector_store_id}/file_batches\">client.vectorStores.fileBatches.<a href=\"./src/resources/vector-stores/file-batches.ts\">create</a>(vectorStoreID, { ...params }) -> VectorStoreFileBatch</code>\n- <code title=\"get /vector_stores/{vector_store_id}/file_batches/{batch_id}\">client.vectorStores.fileBatches.<a href=\"./src/resources/vector-stores/file-batches.ts\">retrieve</a>(batchID, { ...params }) -> VectorStoreFileBatch</code>\n- <code title=\"post /vector_stores/{vector_store_id}/file_batches/{batch_id}/cancel\">client.vectorStores.fileBatches.<a href=\"./src/resources/vector-stores/file-batches.ts\">cancel</a>(batchID, { ...params }) -> VectorStoreFileBatch</code>\n- <code title=\"get /vector_stores/{vector_store_id}/file_batches/{batch_id}/files\">client.vectorStores.fileBatches.<a href=\"./src/resources/vector-stores/file-batches.ts\">listFiles</a>(batchID, { ...params }) -> VectorStoreFilesPage</code>\n- <code>client.vectorStores.fileBatches.<a href=\"./src/resources/vector-stores/file-batches.ts\">createAndPoll</a>(vectorStoreId, body, options?) -> Promise&lt;VectorStoreFileBatch&gt;</code>\n- <code>client.vectorStores.fileBatches.<a href=\"./src/resources/vector-stores/file-batches.ts\">poll</a>(vectorStoreId, batchId, options?) -> Promise&lt;VectorStoreFileBatch&gt;</code>\n- <code>client.vectorStores.fileBatches.<a href=\"./src/resources/vector-stores/file-batches.ts\">uploadAndPoll</a>(vectorStoreId, { files, fileIds? }, options?) -> Promise&lt;VectorStoreFileBatch&gt;</code>\n\n# [Webhooks](src/resources/webhooks/api.md)\n\n# Beta\n\n## ChatKit\n\nTypes:\n\n- <code><a href=\"./src/resources/beta/chatkit/chatkit.ts\">ChatKitWorkflow</a></code>\n\n### Sessions\n\nMethods:\n\n- <code title=\"post /chatkit/sessions\">client.beta.chatkit.sessions.<a href=\"./src/resources/beta/chatkit/sessions.ts\">create</a>({ ...params }) -> ChatSession</code>\n- <code title=\"post /chatkit/sessions/{session_id}/cancel\">client.beta.chatkit.sessions.<a href=\"./src/resources/beta/chatkit/sessions.ts\">cancel</a>(sessionID) -> ChatSession</code>\n\n### Threads\n\nTypes:\n\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSession</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSessionAutomaticThreadTitling</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSessionChatKitConfiguration</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSessionChatKitConfigurationParam</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSessionExpiresAfterParam</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSessionFileUpload</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSessionHistory</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSessionRateLimits</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSessionRateLimitsParam</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSessionStatus</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatSessionWorkflowParam</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatKitAttachment</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatKitResponseOutputText</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatKitThread</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatKitThreadAssistantMessageItem</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatKitThreadItemList</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatKitThreadUserMessageItem</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ChatKitWidgetItem</a></code>\n- <code><a href=\"./src/resources/beta/chatkit/threads.ts\">ThreadDeleteResponse</a></code>\n\nMethods:\n\n- <code title=\"get /chatkit/threads/{thread_id}\">client.beta.chatkit.threads.<a href=\"./src/resources/beta/chatkit/threads.ts\">retrieve</a>(threadID) -> ChatKitThread</code>\n- <code title=\"get /chatkit/threads\">client.beta.chatkit.threads.<a href=\"./src/resources/beta/chatkit/threads.ts\">list</a>({ ...params }) -> ChatKitThreadsPage</code>\n- <code title=\"delete /chatkit/threads/{thread_id}\">client.beta.chatkit.threads.<a href=\"./src/resources/beta/chatkit/threads.ts\">delete</a>(threadID) -> ThreadDeleteResponse</code>\n- <code title=\"get /chatkit/threads/{thread_id}/items\">client.beta.chatkit.threads.<a href=\"./src/resources/beta/chatkit/threads.ts\">listItems</a>(threadID, { ...params }) -> ChatKitThreadItemListDataPage</code>\n\n## Assistants\n\nTypes:\n\n- <code><a href=\"./src/resources/beta/assistants.ts\">Assistant</a></code>\n- <code><a href=\"./src/resources/beta/assistants.ts\">AssistantDeleted</a></code>\n- <code><a href=\"./src/resources/beta/assistants.ts\">AssistantStreamEvent</a></code>\n- <code><a href=\"./src/resources/beta/assistants.ts\">AssistantTool</a></code>\n- <code><a href=\"./src/resources/beta/assistants.ts\">CodeInterpreterTool</a></code>\n- <code><a href=\"./src/resources/beta/assistants.ts\">FileSearchTool</a></code>\n- <code><a href=\"./src/resources/beta/assistants.ts\">FunctionTool</a></code>\n- <code><a href=\"./src/resources/beta/assistants.ts\">MessageStreamEvent</a></code>\n- <code><a href=\"./src/resources/beta/assistants.ts\">RunStepStreamEvent</a></code>\n- <code><a href=\"./src/resources/beta/assistants.ts\">RunStreamEvent</a></code>\n- <code><a href=\"./src/resources/beta/assistants.ts\">ThreadStreamEvent</a></code>\n\nMethods:\n\n- <code title=\"post /assistants\">client.beta.assistants.<a href=\"./src/resources/beta/assistants.ts\">create</a>({ ...params }) -> Assistant</code>\n- <code title=\"get /assistants/{assistant_id}\">client.beta.assistants.<a href=\"./src/resources/beta/assistants.ts\">retrieve</a>(assistantID) -> Assistant</code>\n- <code title=\"post /assistants/{assistant_id}\">client.beta.assistants.<a href=\"./src/resources/beta/assistants.ts\">update</a>(assistantID, { ...params }) -> Assistant</code>\n- <code title=\"get /assistants\">client.beta.assistants.<a href=\"./src/resources/beta/assistants.ts\">list</a>({ ...params }) -> AssistantsPage</code>\n- <code title=\"delete /assistants/{assistant_id}\">client.beta.assistants.<a href=\"./src/resources/beta/assistants.ts\">delete</a>(assistantID) -> AssistantDeleted</code>\n\n## Threads\n\nTypes:\n\n- <code><a href=\"./src/resources/beta/threads/threads.ts\">AssistantResponseFormatOption</a></code>\n- <code><a href=\"./src/resources/beta/threads/threads.ts\">AssistantToolChoice</a></code>\n- <code><a href=\"./src/resources/beta/threads/threads.ts\">AssistantToolChoiceFunction</a></code>\n- <code><a href=\"./src/resources/beta/threads/threads.ts\">AssistantToolChoiceOption</a></code>\n- <code><a href=\"./src/resources/beta/threads/threads.ts\">Thread</a></code>\n- <code><a href=\"./src/resources/beta/threads/threads.ts\">ThreadDeleted</a></code>\n\nMethods:\n\n- <code title=\"post /threads\">client.beta.threads.<a href=\"./src/resources/beta/threads/threads.ts\">create</a>({ ...params }) -> Thread</code>\n- <code title=\"get /threads/{thread_id}\">client.beta.threads.<a href=\"./src/resources/beta/threads/threads.ts\">retrieve</a>(threadID) -> Thread</code>\n- <code title=\"post /threads/{thread_id}\">client.beta.threads.<a href=\"./src/resources/beta/threads/threads.ts\">update</a>(threadID, { ...params }) -> Thread</code>\n- <code title=\"delete /threads/{thread_id}\">client.beta.threads.<a href=\"./src/resources/beta/threads/threads.ts\">delete</a>(threadID) -> ThreadDeleted</code>\n- <code title=\"post /threads/runs\">client.beta.threads.<a href=\"./src/resources/beta/threads/threads.ts\">createAndRun</a>({ ...params }) -> Run</code>\n- <code>client.beta.threads.<a href=\"./src/resources/beta/threads/threads.ts\">createAndRunPoll</a>(body, options?) -> Promise&lt;Threads.Run&gt;</code>\n- <code>client.beta.threads.<a href=\"./src/resources/beta/threads/threads.ts\">createAndRunStream</a>(body, options?) -> AssistantStream</code>\n\n### Runs\n\nTypes:\n\n- <code><a href=\"./src/resources/beta/threads/runs/runs.ts\">RequiredActionFunctionToolCall</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/runs.ts\">Run</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/runs.ts\">RunStatus</a></code>\n\nMethods:\n\n- <code title=\"post /threads/{thread_id}/runs\">client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">create</a>(threadID, { ...params }) -> Run</code>\n- <code title=\"get /threads/{thread_id}/runs/{run_id}\">client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">retrieve</a>(runID, { ...params }) -> Run</code>\n- <code title=\"post /threads/{thread_id}/runs/{run_id}\">client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">update</a>(runID, { ...params }) -> Run</code>\n- <code title=\"get /threads/{thread_id}/runs\">client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">list</a>(threadID, { ...params }) -> RunsPage</code>\n- <code title=\"post /threads/{thread_id}/runs/{run_id}/cancel\">client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">cancel</a>(runID, { ...params }) -> Run</code>\n- <code title=\"post /threads/{thread_id}/runs/{run_id}/submit_tool_outputs\">client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">submitToolOutputs</a>(runID, { ...params }) -> Run</code>\n- <code>client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">createAndPoll</a>(threadId, body, options?) -> Promise&lt;Run&gt;</code>\n- <code>client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">createAndStream</a>(threadId, body, options?) -> AssistantStream</code>\n- <code>client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">poll</a>(runId, params, options?) -> Promise&lt;Run&gt;</code>\n- <code>client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">stream</a>(threadId, body, options?) -> AssistantStream</code>\n- <code>client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">submitToolOutputsAndPoll</a>(runId, params, options?) -> Promise&lt;Run&gt;</code>\n- <code>client.beta.threads.runs.<a href=\"./src/resources/beta/threads/runs/runs.ts\">submitToolOutputsStream</a>(runId, params, options?) -> AssistantStream</code>\n\n#### Steps\n\nTypes:\n\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">CodeInterpreterLogs</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">CodeInterpreterOutputImage</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">CodeInterpreterToolCall</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">CodeInterpreterToolCallDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">FileSearchToolCall</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">FileSearchToolCallDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">FunctionToolCall</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">FunctionToolCallDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">MessageCreationStepDetails</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">RunStep</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">RunStepDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">RunStepDeltaEvent</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">RunStepDeltaMessageDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">RunStepInclude</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">ToolCall</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">ToolCallDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">ToolCallDeltaObject</a></code>\n- <code><a href=\"./src/resources/beta/threads/runs/steps.ts\">ToolCallsStepDetails</a></code>\n\nMethods:\n\n- <code title=\"get /threads/{thread_id}/runs/{run_id}/steps/{step_id}\">client.beta.threads.runs.steps.<a href=\"./src/resources/beta/threads/runs/steps.ts\">retrieve</a>(stepID, { ...params }) -> RunStep</code>\n- <code title=\"get /threads/{thread_id}/runs/{run_id}/steps\">client.beta.threads.runs.steps.<a href=\"./src/resources/beta/threads/runs/steps.ts\">list</a>(runID, { ...params }) -> RunStepsPage</code>\n\n### Messages\n\nTypes:\n\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">Annotation</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">AnnotationDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">FileCitationAnnotation</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">FileCitationDeltaAnnotation</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">FilePathAnnotation</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">FilePathDeltaAnnotation</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">ImageFile</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">ImageFileContentBlock</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">ImageFileDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">ImageFileDeltaBlock</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">ImageURL</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">ImageURLContentBlock</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">ImageURLDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">ImageURLDeltaBlock</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">Message</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">MessageContent</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">MessageContentDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">MessageContentPartParam</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">MessageDeleted</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">MessageDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">MessageDeltaEvent</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">RefusalContentBlock</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">RefusalDeltaBlock</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">Text</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">TextContentBlock</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">TextContentBlockParam</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">TextDelta</a></code>\n- <code><a href=\"./src/resources/beta/threads/messages.ts\">TextDeltaBlock</a></code>\n\nMethods:\n\n- <code title=\"post /threads/{thread_id}/messages\">client.beta.threads.messages.<a href=\"./src/resources/beta/threads/messages.ts\">create</a>(threadID, { ...params }) -> Message</code>\n- <code title=\"get /threads/{thread_id}/messages/{message_id}\">client.beta.threads.messages.<a href=\"./src/resources/beta/threads/messages.ts\">retrieve</a>(messageID, { ...params }) -> Message</code>\n- <code title=\"post /threads/{thread_id}/messages/{message_id}\">client.beta.threads.messages.<a href=\"./src/resources/beta/threads/messages.ts\">update</a>(messageID, { ...params }) -> Message</code>\n- <code title=\"get /threads/{thread_id}/messages\">client.beta.threads.messages.<a href=\"./src/resources/beta/threads/messages.ts\">list</a>(threadID, { ...params }) -> MessagesPage</code>\n- <code title=\"delete /threads/{thread_id}/messages/{message_id}\">client.beta.threads.messages.<a href=\"./src/resources/beta/threads/messages.ts\">delete</a>(messageID, { ...params }) -> MessageDeleted</code>\n\n# Batches\n\nTypes:\n\n- <code><a href=\"./src/resources/batches.ts\">Batch</a></code>\n- <code><a href=\"./src/resources/batches.ts\">BatchError</a></code>\n- <code><a href=\"./src/resources/batches.ts\">BatchRequestCounts</a></code>\n- <code><a href=\"./src/resources/batches.ts\">BatchUsage</a></code>\n\nMethods:\n\n- <code title=\"post /batches\">client.batches.<a href=\"./src/resources/batches.ts\">create</a>({ ...params }) -> Batch</code>\n- <code title=\"get /batches/{batch_id}\">client.batches.<a href=\"./src/resources/batches.ts\">retrieve</a>(batchID) -> Batch</code>\n- <code title=\"get /batches\">client.batches.<a href=\"./src/resources/batches.ts\">list</a>({ ...params }) -> BatchesPage</code>\n- <code title=\"post /batches/{batch_id}/cancel\">client.batches.<a href=\"./src/resources/batches.ts\">cancel</a>(batchID) -> Batch</code>\n\n# Uploads\n\nTypes:\n\n- <code><a href=\"./src/resources/uploads/uploads.ts\">Upload</a></code>\n\nMethods:\n\n- <code title=\"post /uploads\">client.uploads.<a href=\"./src/resources/uploads/uploads.ts\">create</a>({ ...params }) -> Upload</code>\n- <code title=\"post /uploads/{upload_id}/cancel\">client.uploads.<a href=\"./src/resources/uploads/uploads.ts\">cancel</a>(uploadID) -> Upload</code>\n- <code title=\"post /uploads/{upload_id}/complete\">client.uploads.<a href=\"./src/resources/uploads/uploads.ts\">complete</a>(uploadID, { ...params }) -> Upload</code>\n\n## Parts\n\nTypes:\n\n- <code><a href=\"./src/resources/uploads/parts.ts\">UploadPart</a></code>\n\nMethods:\n\n- <code title=\"post /uploads/{upload_id}/parts\">client.uploads.parts.<a href=\"./src/resources/uploads/parts.ts\">create</a>(uploadID, { ...params }) -> UploadPart</code>\n\n# [Responses](src/resources/responses/api.md)\n\n# [Realtime](src/resources/realtime/api.md)\n\n# [Conversations](src/resources/conversations/api.md)\n\n# Evals\n\nTypes:\n\n- <code><a href=\"./src/resources/evals/evals.ts\">EvalCustomDataSourceConfig</a></code>\n- <code><a href=\"./src/resources/evals/evals.ts\">EvalStoredCompletionsDataSourceConfig</a></code>\n- <code><a href=\"./src/resources/evals/evals.ts\">EvalCreateResponse</a></code>\n- <code><a href=\"./src/resources/evals/evals.ts\">EvalRetrieveResponse</a></code>\n- <code><a href=\"./src/resources/evals/evals.ts\">EvalUpdateResponse</a></code>\n- <code><a href=\"./src/resources/evals/evals.ts\">EvalListResponse</a></code>\n- <code><a href=\"./src/resources/evals/evals.ts\">EvalDeleteResponse</a></code>\n\nMethods:\n\n- <code title=\"post /evals\">client.evals.<a href=\"./src/resources/evals/evals.ts\">create</a>({ ...params }) -> EvalCreateResponse</code>\n- <code title=\"get /evals/{eval_id}\">client.evals.<a href=\"./src/resources/evals/evals.ts\">retrieve</a>(evalID) -> EvalRetrieveResponse</code>\n- <code title=\"post /evals/{eval_id}\">client.evals.<a href=\"./src/resources/evals/evals.ts\">update</a>(evalID, { ...params }) -> EvalUpdateResponse</code>\n- <code title=\"get /evals\">client.evals.<a href=\"./src/resources/evals/evals.ts\">list</a>({ ...params }) -> EvalListResponsesPage</code>\n- <code title=\"delete /evals/{eval_id}\">client.evals.<a href=\"./src/resources/evals/evals.ts\">delete</a>(evalID) -> EvalDeleteResponse</code>\n\n## Runs\n\nTypes:\n\n- <code><a href=\"./src/resources/evals/runs/runs.ts\">CreateEvalCompletionsRunDataSource</a></code>\n- <code><a href=\"./src/resources/evals/runs/runs.ts\">CreateEvalJSONLRunDataSource</a></code>\n- <code><a href=\"./src/resources/evals/runs/runs.ts\">EvalAPIError</a></code>\n- <code><a href=\"./src/resources/evals/runs/runs.ts\">RunCreateResponse</a></code>\n- <code><a href=\"./src/resources/evals/runs/runs.ts\">RunRetrieveResponse</a></code>\n- <code><a href=\"./src/resources/evals/runs/runs.ts\">RunListResponse</a></code>\n- <code><a href=\"./src/resources/evals/runs/runs.ts\">RunDeleteResponse</a></code>\n- <code><a href=\"./src/resources/evals/runs/runs.ts\">RunCancelResponse</a></code>\n\nMethods:\n\n- <code title=\"post /evals/{eval_id}/runs\">client.evals.runs.<a href=\"./src/resources/evals/runs/runs.ts\">create</a>(evalID, { ...params }) -> RunCreateResponse</code>\n- <code title=\"get /evals/{eval_id}/runs/{run_id}\">client.evals.runs.<a href=\"./src/resources/evals/runs/runs.ts\">retrieve</a>(runID, { ...params }) -> RunRetrieveResponse</code>\n- <code title=\"get /evals/{eval_id}/runs\">client.evals.runs.<a href=\"./src/resources/evals/runs/runs.ts\">list</a>(evalID, { ...params }) -> RunListResponsesPage</code>\n- <code title=\"delete /evals/{eval_id}/runs/{run_id}\">client.evals.runs.<a href=\"./src/resources/evals/runs/runs.ts\">delete</a>(runID, { ...params }) -> RunDeleteResponse</code>\n- <code title=\"post /evals/{eval_id}/runs/{run_id}\">client.evals.runs.<a href=\"./src/resources/evals/runs/runs.ts\">cancel</a>(runID, { ...params }) -> RunCancelResponse</code>\n\n### OutputItems\n\nTypes:\n\n- <code><a href=\"./src/resources/evals/runs/output-items.ts\">OutputItemRetrieveResponse</a></code>\n- <code><a href=\"./src/resources/evals/runs/output-items.ts\">OutputItemListResponse</a></code>\n\nMethods:\n\n- <code title=\"get /evals/{eval_id}/runs/{run_id}/output_items/{output_item_id}\">client.evals.runs.outputItems.<a href=\"./src/resources/evals/runs/output-items.ts\">retrieve</a>(outputItemID, { ...params }) -> OutputItemRetrieveResponse</code>\n- <code title=\"get /evals/{eval_id}/runs/{run_id}/output_items\">client.evals.runs.outputItems.<a href=\"./src/resources/evals/runs/output-items.ts\">list</a>(runID, { ...params }) -> OutputItemListResponsesPage</code>\n\n# Containers\n\nTypes:\n\n- <code><a href=\"./src/resources/containers/containers.ts\">ContainerCreateResponse</a></code>\n- <code><a href=\"./src/resources/containers/containers.ts\">ContainerRetrieveResponse</a></code>\n- <code><a href=\"./src/resources/containers/containers.ts\">ContainerListResponse</a></code>\n\nMethods:\n\n- <code title=\"post /containers\">client.containers.<a href=\"./src/resources/containers/containers.ts\">create</a>({ ...params }) -> ContainerCreateResponse</code>\n- <code title=\"get /containers/{container_id}\">client.containers.<a href=\"./src/resources/containers/containers.ts\">retrieve</a>(containerID) -> ContainerRetrieveResponse</code>\n- <code title=\"get /containers\">client.containers.<a href=\"./src/resources/containers/containers.ts\">list</a>({ ...params }) -> ContainerListResponsesPage</code>\n- <code title=\"delete /containers/{container_id}\">client.containers.<a href=\"./src/resources/containers/containers.ts\">delete</a>(containerID) -> void</code>\n\n## Files\n\nTypes:\n\n- <code><a href=\"./src/resources/containers/files/files.ts\">FileCreateResponse</a></code>\n- <code><a href=\"./src/resources/containers/files/files.ts\">FileRetrieveResponse</a></code>\n- <code><a href=\"./src/resources/containers/files/files.ts\">FileListResponse</a></code>\n\nMethods:\n\n- <code title=\"post /containers/{container_id}/files\">client.containers.files.<a href=\"./src/resources/containers/files/files.ts\">create</a>(containerID, { ...params }) -> FileCreateResponse</code>\n- <code title=\"get /containers/{container_id}/files/{file_id}\">client.containers.files.<a href=\"./src/resources/containers/files/files.ts\">retrieve</a>(fileID, { ...params }) -> FileRetrieveResponse</code>\n- <code title=\"get /containers/{container_id}/files\">client.containers.files.<a href=\"./src/resources/containers/files/files.ts\">list</a>(containerID, { ...params }) -> FileListResponsesPage</code>\n- <code title=\"delete /containers/{container_id}/files/{file_id}\">client.containers.files.<a href=\"./src/resources/containers/files/files.ts\">delete</a>(fileID, { ...params }) -> void</code>\n\n### Content\n\nMethods:\n\n- <code title=\"get /containers/{container_id}/files/{file_id}/content\">client.containers.files.content.<a href=\"./src/resources/containers/files/content.ts\">retrieve</a>(fileID, { ...params }) -> Response</code>\n\n# Skills\n\nTypes:\n\n- <code><a href=\"./src/resources/skills/skills.ts\">DeletedSkill</a></code>\n- <code><a href=\"./src/resources/skills/skills.ts\">Skill</a></code>\n- <code><a href=\"./src/resources/skills/skills.ts\">SkillList</a></code>\n\nMethods:\n\n- <code title=\"post /skills\">client.skills.<a href=\"./src/resources/skills/skills.ts\">create</a>({ ...params }) -> Skill</code>\n- <code title=\"get /skills/{skill_id}\">client.skills.<a href=\"./src/resources/skills/skills.ts\">retrieve</a>(skillID) -> Skill</code>\n- <code title=\"post /skills/{skill_id}\">client.skills.<a href=\"./src/resources/skills/skills.ts\">update</a>(skillID, { ...params }) -> Skill</code>\n- <code title=\"get /skills\">client.skills.<a href=\"./src/resources/skills/skills.ts\">list</a>({ ...params }) -> SkillsPage</code>\n- <code title=\"delete /skills/{skill_id}\">client.skills.<a href=\"./src/resources/skills/skills.ts\">delete</a>(skillID) -> DeletedSkill</code>\n\n## Content\n\nMethods:\n\n- <code title=\"get /skills/{skill_id}/content\">client.skills.content.<a href=\"./src/resources/skills/content.ts\">retrieve</a>(skillID) -> Response</code>\n\n## Versions\n\nTypes:\n\n- <code><a href=\"./src/resources/skills/versions/versions.ts\">DeletedSkillVersion</a></code>\n- <code><a href=\"./src/resources/skills/versions/versions.ts\">SkillVersion</a></code>\n- <code><a href=\"./src/resources/skills/versions/versions.ts\">SkillVersionList</a></code>\n\nMethods:\n\n- <code title=\"post /skills/{skill_id}/versions\">client.skills.versions.<a href=\"./src/resources/skills/versions/versions.ts\">create</a>(skillID, { ...params }) -> SkillVersion</code>\n- <code title=\"get /skills/{skill_id}/versions/{version}\">client.skills.versions.<a href=\"./src/resources/skills/versions/versions.ts\">retrieve</a>(version, { ...params }) -> SkillVersion</code>\n- <code title=\"get /skills/{skill_id}/versions\">client.skills.versions.<a href=\"./src/resources/skills/versions/versions.ts\">list</a>(skillID, { ...params }) -> SkillVersionsPage</code>\n- <code title=\"delete /skills/{skill_id}/versions/{version}\">client.skills.versions.<a href=\"./src/resources/skills/versions/versions.ts\">delete</a>(version, { ...params }) -> DeletedSkillVersion</code>\n\n### Content\n\nMethods:\n\n- <code title=\"get /skills/{skill_id}/versions/{version}/content\">client.skills.versions.content.<a href=\"./src/resources/skills/versions/content.ts\">retrieve</a>(version, { ...params }) -> Response</code>\n\n# Videos\n\nTypes:\n\n- <code><a href=\"./src/resources/videos.ts\">ImageInputReferenceParam</a></code>\n- <code><a href=\"./src/resources/videos.ts\">Video</a></code>\n- <code><a href=\"./src/resources/videos.ts\">VideoCreateError</a></code>\n- <code><a href=\"./src/resources/videos.ts\">VideoModel</a></code>\n- <code><a href=\"./src/resources/videos.ts\">VideoSeconds</a></code>\n- <code><a href=\"./src/resources/videos.ts\">VideoSize</a></code>\n- <code><a href=\"./src/resources/videos.ts\">VideoDeleteResponse</a></code>\n- <code><a href=\"./src/resources/videos.ts\">VideoCreateCharacterResponse</a></code>\n- <code><a href=\"./src/resources/videos.ts\">VideoGetCharacterResponse</a></code>\n\nMethods:\n\n- <code title=\"post /videos\">client.videos.<a href=\"./src/resources/videos.ts\">create</a>({ ...params }) -> Video</code>\n- <code title=\"get /videos/{video_id}\">client.videos.<a href=\"./src/resources/videos.ts\">retrieve</a>(videoID) -> Video</code>\n- <code title=\"get /videos\">client.videos.<a href=\"./src/resources/videos.ts\">list</a>({ ...params }) -> VideosPage</code>\n- <code title=\"delete /videos/{video_id}\">client.videos.<a href=\"./src/resources/videos.ts\">delete</a>(videoID) -> VideoDeleteResponse</code>\n- <code title=\"post /videos/characters\">client.videos.<a href=\"./src/resources/videos.ts\">createCharacter</a>({ ...params }) -> VideoCreateCharacterResponse</code>\n- <code title=\"get /videos/{video_id}/content\">client.videos.<a href=\"./src/resources/videos.ts\">downloadContent</a>(videoID, { ...params }) -> Response</code>\n- <code title=\"post /videos/edits\">client.videos.<a href=\"./src/resources/videos.ts\">edit</a>({ ...params }) -> Video</code>\n- <code title=\"post /videos/extensions\">client.videos.<a href=\"./src/resources/videos.ts\">extend</a>({ ...params }) -> Video</code>\n- <code title=\"get /videos/characters/{character_id}\">client.videos.<a href=\"./src/resources/videos.ts\">getCharacter</a>(characterID) -> VideoGetCharacterResponse</code>\n- <code title=\"post /videos/{video_id}/remix\">client.videos.<a href=\"./src/resources/videos.ts\">remix</a>(videoID, { ...params }) -> Video</code>\n"
  },
  {
    "path": "azure.md",
    "content": "# Microsoft Azure OpenAI\n\nTo use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`\nclass instead of the `OpenAI` class.\n\n> [!IMPORTANT]\n> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params\n> won't always be correct.\n\n```ts\nimport { AzureOpenAI } from 'openai';\nimport { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';\n\nconst credential = new DefaultAzureCredential();\nconst scope = 'https://cognitiveservices.azure.com/.default';\nconst azureADTokenProvider = getBearerTokenProvider(credential, scope);\n\nconst openai = new AzureOpenAI({\n  azureADTokenProvider,\n  apiVersion: '<The API version, e.g. 2024-10-01-preview>',\n});\n\nconst result = await openai.chat.completions.create({\n  model: 'gpt-4o',\n  messages: [{ role: 'user', content: 'Say hello!' }],\n});\n\nconsole.log(result.choices[0]!.message?.content);\n```\n\nFor more information on support for the Azure API, see [azure.md](azure.md).\n\n## Realtime API\n\nThis SDK provides real-time streaming capabilities for Azure OpenAI through the `OpenAIRealtimeWS` and `OpenAIRealtimeWebSocket` clients described previously.\n\nTo 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:\n\n```ts\nconst cred = new DefaultAzureCredential();\nconst scope = 'https://cognitiveservices.azure.com/.default';\nconst deploymentName = 'gpt-4o-realtime-preview-1001';\nconst azureADTokenProvider = getBearerTokenProvider(cred, scope);\nconst client = new AzureOpenAI({\n  azureADTokenProvider,\n  apiVersion: '2024-10-01-preview',\n  deployment: deploymentName,\n});\nconst rt = await OpenAIRealtimeWS.azure(client);\n```\n\nOnce the instance has been created, you can then begin sending requests and receiving streaming responses in real time.\n"
  },
  {
    "path": "bin/check-release-environment",
    "content": "#!/usr/bin/env bash\n\nerrors=()\n\nif [ -z \"${STAINLESS_API_KEY}\" ]; then\n  errors+=(\"The STAINLESS_API_KEY secret has not been set. Please contact Stainless for an API key & set it in your organization secrets on GitHub.\")\nfi\n\nlenErrors=${#errors[@]}\n\nif [[ lenErrors -gt 0 ]]; then\n  echo -e \"Found the following errors in the release environment:\\n\"\n\n  for error in \"${errors[@]}\"; do\n    echo -e \"- $error\\n\"\n  done\n\n  exit 1\nfi\n\necho \"The environment is ready to push releases!\"\n\n"
  },
  {
    "path": "bin/cli",
    "content": "#!/usr/bin/env node\n\nconst { spawnSync } = require('child_process');\n\nconst commands = {\n  migrate: {\n    description: 'Run migrations to update to the latest major SDK version',\n    fn: () => {\n      const result = spawnSync(\n        'npx',\n        [\n          '-y',\n          'https://github.com/stainless-api/migrate-ts/releases/download/0.0.3/stainless-api-migrate-0.0.3.tgz',\n          '--migrationConfig',\n          require.resolve('./migration-config.json'),\n          ...process.argv.slice(3),\n        ],\n        { stdio: 'inherit' },\n      );\n      if (result.status !== 0) {\n        process.exit(result.status);\n      }\n    },\n  },\n};\n\nfunction exitWithHelp() {\n  console.log(`Usage: openai <subcommand>`);\n  console.log();\n  console.log('Subcommands:');\n\n  for (const [name, info] of Object.entries(commands)) {\n    console.log(`  ${name}  ${info.description}`);\n  }\n\n  console.log();\n  process.exit(1);\n}\n\nif (process.argv.length < 3) {\n  exitWithHelp();\n}\n\nconst commandName = process.argv[2];\n\nconst command = commands[commandName];\nif (!command) {\n  console.log(`Unknown subcommand ${commandName}.`);\n  exitWithHelp();\n}\n\ncommand.fn();\n"
  },
  {
    "path": "bin/migration-config.json",
    "content": "{\n  \"pkg\": \"openai\",\n  \"githubRepo\": \"https://github.com/openai/openai-node\",\n  \"clientClass\": \"OpenAI\",\n  \"methods\": [\n    {\n      \"base\": \"chat.completions\",\n      \"name\": \"delete\",\n      \"oldName\": \"del\"\n    },\n    {\n      \"base\": \"chat.completions\",\n      \"name\": \"stream\",\n      \"oldBase\": \"beta.chat.completions\"\n    },\n    {\n      \"base\": \"chat.completions\",\n      \"name\": \"parse\",\n      \"oldBase\": \"beta.chat.completions\"\n    },\n    {\n      \"base\": \"chat.completions\",\n      \"name\": \"runTools\",\n      \"oldBase\": \"beta.chat.completions\"\n    },\n    {\n      \"base\": \"files\",\n      \"name\": \"delete\",\n      \"oldName\": \"del\"\n    },\n    {\n      \"base\": \"models\",\n      \"name\": \"delete\",\n      \"oldName\": \"del\"\n    },\n    {\n      \"base\": \"fineTuning.checkpoints.permissions\",\n      \"name\": \"delete\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"permission_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldName\": \"del\",\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"fine_tuned_model_checkpoint\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"permission_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"vectorStores\",\n      \"name\": \"delete\",\n      \"oldName\": \"del\"\n    },\n    {\n      \"base\": \"vectorStores.files\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"vector_store_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"vectorStores.files\",\n      \"name\": \"update\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"vector_store_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"vectorStores.files\",\n      \"name\": \"delete\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldName\": \"del\",\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"vector_store_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"vectorStores.files\",\n      \"name\": \"content\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"vector_store_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"vectorStores.fileBatches\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"batch_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"vector_store_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"batch_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"vectorStores.fileBatches\",\n      \"name\": \"cancel\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"batch_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"vector_store_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"batch_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"vectorStores.fileBatches\",\n      \"name\": \"listFiles\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"batch_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"vector_store_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"batch_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": true\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"beta.assistants\",\n      \"name\": \"delete\",\n      \"oldName\": \"del\"\n    },\n    {\n      \"base\": \"beta.threads\",\n      \"name\": \"delete\",\n      \"oldName\": \"del\"\n    },\n    {\n      \"base\": \"beta.threads.runs\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"thread_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"beta.threads.runs\",\n      \"name\": \"update\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"thread_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"beta.threads.runs\",\n      \"name\": \"cancel\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"thread_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"beta.threads.runs\",\n      \"name\": \"submitToolOutputs\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"thread_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"beta.threads.runs.steps\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"step_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"thread_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"step_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": true\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"beta.threads.runs.steps\",\n      \"name\": \"list\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"thread_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": true\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"beta.threads.messages\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"message_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"thread_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"message_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"beta.threads.messages\",\n      \"name\": \"update\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"message_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"thread_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"message_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"beta.threads.messages\",\n      \"name\": \"delete\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"message_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldName\": \"del\",\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"thread_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"message_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"responses\",\n      \"name\": \"delete\",\n      \"oldName\": \"del\"\n    },\n    {\n      \"base\": \"evals\",\n      \"name\": \"delete\",\n      \"oldName\": \"del\"\n    },\n    {\n      \"base\": \"evals.runs\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"eval_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"evals.runs\",\n      \"name\": \"delete\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldName\": \"del\",\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"eval_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"evals.runs\",\n      \"name\": \"cancel\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"eval_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"evals.runs.outputItems\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"output_item_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"eval_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"output_item_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"evals.runs.outputItems\",\n      \"name\": \"list\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"eval_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"run_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": true\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"containers\",\n      \"name\": \"delete\",\n      \"oldName\": \"del\"\n    },\n    {\n      \"base\": \"containers.files\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"container_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"containers.files\",\n      \"name\": \"delete\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldName\": \"del\",\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"container_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"containers.files.content\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"container_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"file_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"skills.versions\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"version\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"skill_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"version\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"skills.versions\",\n      \"name\": \"delete\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"version\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"skill_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"version\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    },\n    {\n      \"base\": \"skills.versions.content\",\n      \"name\": \"retrieve\",\n      \"params\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"version\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"params\",\n          \"maybeOverload\": false\n        },\n        {\n          \"type\": \"options\"\n        }\n      ],\n      \"oldParams\": [\n        {\n          \"type\": \"param\",\n          \"key\": \"skill_id\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"param\",\n          \"key\": \"version\",\n          \"location\": \"path\"\n        },\n        {\n          \"type\": \"options\"\n        }\n      ]\n    }\n  ]\n}\n"
  },
  {
    "path": "bin/publish-jsr",
    "content": "#!/usr/bin/env bash\n\nset -eux\n\n# Build the project\nyarn build\n\n# Navigate to the dist directory\ncd dist-deno\n\nnpx jsr publish ${JSR_TOKEN:+\"--token=$JSR_TOKEN\"}\n"
  },
  {
    "path": "bin/publish-npm",
    "content": "#!/usr/bin/env bash\n\nset -eux\n\nif [[ ${NPM_TOKEN:-} ]]; then\n  npm config set '//registry.npmjs.org/:_authToken' \"$NPM_TOKEN\"\nelif [[ ! ${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-} ]]; then\n  echo \"ERROR: NPM_TOKEN must be set if not running in a Github Action with id-token permission\"\n  exit 1\nfi\n\nyarn build\ncd dist\n\n# Get package name and version from package.json\nPACKAGE_NAME=\"$(jq -r -e '.name' ./package.json)\"\nVERSION=\"$(jq -r -e '.version' ./package.json)\"\n\n# Get latest version from npm\n#\n# If the package doesn't exist, npm will return:\n# {\n#   \"error\": {\n#     \"code\": \"E404\",\n#     \"summary\": \"Unpublished on 2025-06-05T09:54:53.528Z\",\n#     \"detail\": \"'the_package' is not in this registry...\"\n#   }\n# }\nNPM_INFO=\"$(npm view \"$PACKAGE_NAME\" version --json 2>/dev/null || true)\"\n\n# Check if we got an E404 error\nif echo \"$NPM_INFO\" | jq -e '.error.code == \"E404\"' > /dev/null 2>&1; then\n  # Package doesn't exist yet, no last version\n  LAST_VERSION=\"\"\nelif echo \"$NPM_INFO\" | jq -e '.error' > /dev/null 2>&1; then\n  # Report other errors\n  echo \"ERROR: npm returned unexpected data:\"\n  echo \"$NPM_INFO\"\n  exit 1\nelse\n  # Success - get the version\n  LAST_VERSION=$(echo \"$NPM_INFO\" | jq -r '.') # strip quotes\nfi\n\n# Check if current version is pre-release (e.g. alpha / beta / rc)\nCURRENT_IS_PRERELEASE=false\nif [[ \"$VERSION\" =~ -([a-zA-Z]+) ]]; then\n  CURRENT_IS_PRERELEASE=true\n  CURRENT_TAG=\"${BASH_REMATCH[1]}\"\nfi\n\n# Check if last version is a stable release\nLAST_IS_STABLE_RELEASE=true\nif [[ -z \"$LAST_VERSION\" || \"$LAST_VERSION\" =~ -([a-zA-Z]+) ]]; then\n  LAST_IS_STABLE_RELEASE=false\nfi\n\n# Use a corresponding alpha/beta tag if there already is a stable release and we're publishing a prerelease.\nif $CURRENT_IS_PRERELEASE && $LAST_IS_STABLE_RELEASE; then\n  TAG=\"$CURRENT_TAG\"\nelse\n  TAG=\"latest\"\nfi\n\n# Install OIDC compatible npm version\nnpm install --prefix ../oidc/ npm@11.6.2\n\n# Publish with the appropriate tag\nexport npm_config_registry='https://registry.npmjs.org'\n../oidc/node_modules/.bin/npm publish --tag \"$TAG\"\n"
  },
  {
    "path": "ecosystem-tests/browser-direct-import/.gitignore",
    "content": "/node_modules\n/dist\n"
  },
  {
    "path": "ecosystem-tests/browser-direct-import/package.json",
    "content": "{\n  \"name\": \"browser-direct-import\",\n  \"version\": \"0.0.1\",\n  \"private\": true,\n  \"scripts\": {\n    \"tsc\": \"tsc --noEmit\",\n    \"test\": \"ts-node src/test.ts\",\n    \"test:ci\": \"start-server-and-test serve http://localhost:8081 test\",\n    \"serve\": \"sirv -q public --port 8081\"\n  },\n  \"devDependencies\": {\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"puppeteer\": \"^23.4.0\",\n    \"sirv-cli\": \"^3.0.0\",\n    \"start-server-and-test\": \"^2.0.0\",\n    \"ts-node\": \"^10.9.1\",\n    \"typescript\": \"^4.7.4\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/browser-direct-import/public/index.html",
    "content": "<!DOCTYPE html>\n<html>\n  <head>\n    <meta charset=\"utf-8\" />\n    <title>Package in the Browser</title>\n  </head>\n  <body>\n    <div id=\"running\">Running tests...</div>\n    <script src=\"index.js\" type=\"module\"></script>\n  </body>\n</html>\n"
  },
  {
    "path": "ecosystem-tests/browser-direct-import/public/index.js",
    "content": "// @ts-check\nimport OpenAI, { toFile } from './node_modules/openai/index.mjs';\nimport { distance } from './node_modules/fastest-levenshtein/esm/mod.js';\n\n/** @typedef {{ path: string[]; run: () => any; timeout?: number; }} TestCase */\n\n/** @type {TestCase[]} */\nconst tests = [];\n\n/** @typedef {{ path: string[]; passed: boolean; error?: string }} TestResult */\n\nasync function runTests() {\n  /** @type {TestResult[]} */\n  const results = [];\n  function displayResults() {\n    let pre = document.getElementById('results');\n    if (!pre) {\n      pre = document.createElement('pre');\n      pre.id = 'results';\n      document.body.appendChild(pre);\n    }\n    pre.innerText = JSON.stringify(results, null, 2);\n  }\n  for (const { path, run, timeout } of tests) {\n    console.log('running', ...path);\n    try {\n      await Promise.race([\n        run(),\n        new Promise((_, reject) =>\n          setTimeout(() => reject(new Error(`Test timed out after ${timeout} ms`)), timeout),\n        ),\n      ]);\n      console.log('passed ', ...path);\n      results.push({ path, passed: true });\n    } catch (error) {\n      console.log('error  ', ...path);\n      console.error(error);\n      results.push({ path, passed: false, error: error instanceof Error ? error.stack : String(error) });\n    }\n    displayResults();\n  }\n  const runningEl = document.getElementById('running');\n  if (runningEl) runningEl.remove();\n}\n\n/** @type {string[]} */\nconst testPath = [];\n\n/**\n * @param {string} description \n * @param {() => void} handler \n */\nfunction describe(description, handler) {\n  testPath.push(description);\n  try {\n    handler();\n  } finally {\n    testPath.pop();\n  }\n}\n\n/**\n * @param {string} description\n * @param {() => any} run\n * @param {number} [timeout=60000]\n */\nfunction it(description, run, timeout = 60000) {\n  tests.push({ path: [...testPath, description], run, timeout });\n}\n\n/**\n * @param {any} received\n * @returns {{\n *   toEqual: (expected: any) => void;\n *   toBeSimilarTo: (comparedTo: string, expectedDistance: number) => void;\n * }}\n */\nfunction expect(received) {\n  return {\n    toEqual(expected) {\n      if (!Object.is(received, expected)) {\n        throw new Error(\n          [`Received: ${JSON.stringify(received)}`, `Expected: ${JSON.stringify(expected)}`].join('\\n'),\n        );\n      }\n    },\n    toBeSimilarTo(comparedTo, expectedDistance) {\n      const actualDistance = distance(received, comparedTo);\n      if (actualDistance < expectedDistance) return;\n\n      throw new Error(\n        [\n          `Received: ${JSON.stringify(received)}`,\n          `Expected: ${JSON.stringify(comparedTo)}`,\n          `Expected distance: ${expectedDistance}`,\n          `Received distance: ${actualDistance}`,\n        ].join('\\n'),\n      );\n    },\n  };\n}\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst params = new URLSearchParams(location.search);\n\nconst client = new OpenAI({ apiKey: params.get('apiKey') ?? undefined, dangerouslyAllowBrowser: true });\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\nit(`raw response`, async function () {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  // test that we can use web Response API\n  const { body } = response;\n  if (!body) throw new Error('expected response.body to be defined');\n\n  const reader = body.getReader();\n  /** @type {Uint8Array[]} */\n  const chunks = [];\n  let result;\n  do {\n    result = await reader.read();\n    if (!result.done) chunks.push(result.value);\n  } while (!result.done);\n\n  reader.releaseLock();\n\n  let offset = 0;\n  const merged = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n  for (const chunk of chunks) {\n    merged.set(chunk, offset);\n    offset += chunk.length;\n  }\n\n  const json = /** @type {OpenAI.ChatCompletion} */ (JSON.parse(new TextDecoder().decode(merged)));\n  expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);\n});\n\nit(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\nif (typeof File !== 'undefined') {\n  it('handles builtinFile', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      .then((x) => new File([x], filename));\n\n    const result = await client.audio.transcriptions.create({ file, model });\n    expect(result.text).toBeSimilarTo(correctAnswer, 12);\n  });\n}\n\nit('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe('toFile', () => {\n  if (typeof Blob !== 'undefined') {\n    it('handles builtin Blob', async function () {\n      const result = await client.files.create({\n        file: await toFile(\n          // @ts-ignore avoid DOM lib for testing purposes\n          new Blob([new TextEncoder().encode(fineTune)]),\n          'finetune.jsonl',\n        ),\n        purpose: 'fine-tune',\n      });\n      expect(result.filename).toEqual('finetune.jsonl');\n    });\n  }\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n});\n\nrunTests();"
  },
  {
    "path": "ecosystem-tests/browser-direct-import/src/test.ts",
    "content": "import puppeteer from 'puppeteer';\n\n(async () => {\n  const browser = await puppeteer.launch({\n    args: ['--no-sandbox'],\n  });\n  let page;\n  try {\n    page = await browser.newPage();\n    function debugEvent(subj: string) {\n      return subj.padEnd('requestfailed'.length);\n    }\n    page\n      .on('console', (message) =>\n        console.error(\n          `${debugEvent('console')} ${message\n            .type()\n            .substr(0, 'warning'.length)\n            .toUpperCase()\n            .padEnd('warning'.length)} ${message.text()}`,\n        ),\n      )\n      .on('pageerror', ({ message }) => console.error(`${debugEvent('pageerror')} ${message}`))\n      .on('response', (response) =>\n        console.error(`${debugEvent('response')} ${response.status()} ${response.url()}`),\n      )\n      .on('requestfailed', (request) =>\n        console.error(`${debugEvent('requestfailed')} ${request.failure()?.errorText} ${request.url()}`),\n      );\n\n    const apiKey = process.env.OPENAI_API_KEY;\n\n    if (!apiKey) throw new Error('missing process.env.OPENAI_API_KEY');\n\n    // Navigate the page to a URL\n    await page.goto(`http://localhost:8081/index.html?apiKey=${apiKey}`);\n\n    await page.waitForSelector('#running', { timeout: 15000 });\n\n    let start = Date.now();\n    while ((await page.$('#running')) != null && Date.now() - start < 3 * 60000) {\n      await new Promise((r) => setTimeout(r, 1000));\n    }\n\n    let results;\n    const resultsEl = await page.$('#results');\n    if (resultsEl) {\n      const text = await page.evaluate((el) => el.textContent, resultsEl);\n      results = text ? JSON.parse(text) : undefined;\n    }\n\n    if (!Array.isArray(results)) {\n      throw new Error(`failed to get test results from page`);\n    }\n    const failed = results.filter((r) => !r.passed);\n    if (failed.length) {\n      throw new Error(\n        `${failed.length} of ${results.length} tests failed: ${JSON.stringify(failed, null, 2)}`,\n      );\n    }\n    console.log(`${results.length} tests passed!`);\n  } catch (error) {\n    if (page) {\n      try {\n        const html = await page.evaluate(() => document.body.innerHTML);\n        console.error(`\\n====================\\nBODY HTML\\n====================\\n\\n${html}\\n\\n`);\n      } catch (error) {\n        console.error(`failed to get body HTML for debugging`, error);\n      }\n    }\n    throw error;\n  } finally {\n    await browser.close();\n  }\n})();\n"
  },
  {
    "path": "ecosystem-tests/browser-direct-import/tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"module\": \"commonjs\",\n    \"strict\": true,\n    \"noImplicitReturns\": true,\n    \"removeComments\": true,\n    \"preserveConstEnums\": true,\n    \"sourceMap\": true,\n    \"declaration\": true,\n    \"skipLibCheck\": false,\n    \"target\": \"es2015\",\n    \"lib\": [\"es2017\", \"dom\"],\n    \"outDir\": \"dist\",\n    \"rootDir\": \"./\",\n    \"baseUrl\": \".\",\n    \"paths\": {\n      \"*\": [\"types/*\"]\n    }\n  },\n  \"include\": [\"src/**/*\", \"public/index.js\"],\n  \"exclude\": [\"node_modules/*\"]\n}\n"
  },
  {
    "path": "ecosystem-tests/bun/.gitignore",
    "content": "# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore\n\n# Logs\n\nlogs\n_.log\nnpm-debug.log_\nyarn-debug.log*\nyarn-error.log*\nlerna-debug.log*\n.pnpm-debug.log*\n\n# Diagnostic reports (https://nodejs.org/api/report.html)\n\nreport.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json\n\n# Runtime data\n\npids\n_.pid\n_.seed\n\\*.pid.lock\n\n# Directory for instrumented libs generated by jscoverage/JSCover\n\nlib-cov\n\n# Coverage directory used by tools like istanbul\n\ncoverage\n\\*.lcov\n\n# nyc test coverage\n\n.nyc_output\n\n# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)\n\n.grunt\n\n# Bower dependency directory (https://bower.io/)\n\nbower_components\n\n# node-waf configuration\n\n.lock-wscript\n\n# Compiled binary addons (https://nodejs.org/api/addons.html)\n\nbuild/Release\n\n# Dependency directories\n\nnode_modules/\njspm_packages/\n\n# Snowpack dependency directory (https://snowpack.dev/)\n\nweb_modules/\n\n# TypeScript cache\n\n\\*.tsbuildinfo\n\n# Optional npm cache directory\n\n.npm\n\n# Optional eslint cache\n\n.eslintcache\n\n# Optional stylelint cache\n\n.stylelintcache\n\n# Microbundle cache\n\n.rpt2_cache/\n.rts2_cache_cjs/\n.rts2_cache_es/\n.rts2_cache_umd/\n\n# Optional REPL history\n\n.node_repl_history\n\n# Output of 'npm pack'\n\n\\*.tgz\n\n# Yarn Integrity file\n\n.yarn-integrity\n\n# dotenv environment variable files\n\n.env\n.env.development.local\n.env.test.local\n.env.production.local\n.env.local\n\n# parcel-bundler cache (https://parceljs.org/)\n\n.cache\n.parcel-cache\n\n# Next.js build output\n\n.next\nout\n\n# Nuxt.js build / generate output\n\n.nuxt\ndist\n\n# Gatsby files\n\n.cache/\n\n# Comment in the public line in if your project uses Gatsby and not Next.js\n\n# https://nextjs.org/blog/next-9-1#public-directory-support\n\n# public\n\n# vuepress build output\n\n.vuepress/dist\n\n# vuepress v2.x temp and cache directory\n\n.temp\n.cache\n\n# Docusaurus cache and generated files\n\n.docusaurus\n\n# Serverless directories\n\n.serverless/\n\n# FuseBox cache\n\n.fusebox/\n\n# DynamoDB Local files\n\n.dynamodb/\n\n# TernJS port file\n\n.tern-port\n\n# Stores VSCode versions used for testing VSCode extensions\n\n.vscode-test\n\n# yarn v2\n\n.yarn/cache\n.yarn/unplugged\n.yarn/build-state.yml\n.yarn/install-state.gz\n.pnp.\\*\n"
  },
  {
    "path": "ecosystem-tests/bun/README.md",
    "content": "# openai-bun-test\n\nTo install dependencies:\n\n```bash\nbun install\n```\n\nTo run:\n\n```bash\nbun run index.ts\n```\n"
  },
  {
    "path": "ecosystem-tests/bun/openai.test.ts",
    "content": "import OpenAI, { toFile } from 'openai';\nimport fs from 'fs';\nimport { distance } from 'fastest-levenshtein';\nimport { test, expect } from 'bun:test';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI();\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\nfunction expectSimilar(received: any, comparedTo: string, expectedDistance: number) {\n  const message = () =>\n    [\n      `Received: ${JSON.stringify(received)}`,\n      `Expected: ${JSON.stringify(comparedTo)}`,\n      `Expected distance: ${expectedDistance}`,\n      `Received distance: ${actualDistance}`,\n    ].join('\\n');\n\n  const actualDistance = distance(received, comparedTo);\n  expect(actualDistance).toBeLessThan(expectedDistance);\n}\n\ntest(`basic request works`, async function () {\n  const completion = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n  });\n  expectSimilar(completion.choices[0]?.message?.content, 'This is a test', 10);\n});\n\ntest(`proxied request works`, async function () {\n  const client = new OpenAI({\n    fetchOptions: {\n      proxy: process.env['ECOSYSTEM_TESTS_PROXY'],\n    },\n  });\n  \n  const completion = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n  });\n  expectSimilar(completion.choices[0]?.message?.content, 'This is a test', 10);\n});\n\ntest(`raw response`, async function () {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  // test that we can use web Response API\n  const { body } = response;\n  if (!body) throw new Error('expected response.body to be defined');\n\n  const reader = body.getReader();\n  const chunks: Uint8Array[] = [];\n  let result;\n  do {\n    result = await reader.read();\n    if (!result.done) chunks.push(result.value);\n  } while (!result.done);\n\n  reader.releaseLock();\n\n  let offset = 0;\n  const merged = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n  for (const chunk of chunks) {\n    merged.set(chunk, offset);\n    offset += chunk.length;\n  }\n\n  const json: ChatCompletion = JSON.parse(new TextDecoder().decode(merged));\n  expectSimilar(json.choices[0]?.message.content || '', 'This is a test', 10);\n});\n\ntest(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expectSimilar(chunks.map((c) => c.choices[0]?.delta.content || '').join(''), 'This is a test', 10);\n});\n\n// @ts-ignore avoid DOM lib for testing purposes\nif (typeof File !== 'undefined') {\n  test('handles builtinFile', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      // @ts-ignore avoid DOM lib for testing purposes\n      .then((x) => new File([x], filename));\n\n    const result = await client.audio.transcriptions.create({ file, model });\n    expectSimilar(result.text, correctAnswer, 12);\n  });\n}\n\ntest('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expectSimilar(result.text, correctAnswer, 12);\n});\n\ntest('handles fs.ReadStream', async function () {\n  const result = await client.audio.transcriptions.create({\n    file: fs.createReadStream('sample1.mp3'),\n    model,\n  });\n  expectSimilar(result.text, correctAnswer, 12);\n});\n\ntest('handles Bun.File', async function () {\n  const result = await client.audio.transcriptions.create({\n    file: Bun.file('sample1.mp3'),\n    model,\n  });\n  expectSimilar(result.text, correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\n// @ts-ignore avoid DOM lib for testing purposes\nif (typeof Blob !== 'undefined') {\n  test('toFile handles builtin Blob', async function () {\n    const result = await client.files.create({\n      file: await toFile(\n        // @ts-ignore avoid DOM lib for testing purposes\n        new Blob([new TextEncoder().encode(fineTune)]),\n        'finetune.jsonl',\n      ),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n}\ntest('toFile handles Uint8Array', async function () {\n  const result = await client.files.create({\n    file: await toFile(\n      // @ts-ignore avoid DOM lib for testing purposes\n      new TextEncoder().encode(fineTune),\n      'finetune.jsonl',\n    ),\n    purpose: 'fine-tune',\n  });\n  expect(result.filename).toEqual('finetune.jsonl');\n});\ntest('toFile handles ArrayBuffer', async function () {\n  const result = await client.files.create({\n    file: await toFile(\n      // @ts-ignore avoid DOM lib for testing purposes\n      new TextEncoder().encode(fineTune).buffer,\n      'finetune.jsonl',\n    ),\n    purpose: 'fine-tune',\n  });\n  expect(result.filename).toEqual('finetune.jsonl');\n});\ntest('toFile handles DataView', async function () {\n  const result = await client.files.create({\n    file: await toFile(\n      // @ts-ignore avoid DOM lib for testing purposes\n      new DataView(new TextEncoder().encode(fineTune).buffer),\n      'finetune.jsonl',\n    ),\n    purpose: 'fine-tune',\n  });\n  expect(result.filename).toEqual('finetune.jsonl');\n});\n"
  },
  {
    "path": "ecosystem-tests/bun/package.json",
    "content": "{\n  \"name\": \"openai-bun-test\",\n  \"module\": \"index.ts\",\n  \"type\": \"module\",\n  \"engines\": {\n    \"bun\": \">=1.0.0\"\n  },\n  \"scripts\": {\n    \"tsc\": \"tsc\"\n  },\n  \"devDependencies\": {\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"bun-types\": \"1.2.17\",\n    \"typescript\": \"5.8.3\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/bun/tsconfig.json",
    "content": "{\n  \"include\": [\"*.ts\"],\n  \"compilerOptions\": {\n    \"lib\": [\"ESNext\"],\n    \"module\": \"esnext\",\n    \"target\": \"esnext\",\n    \"moduleResolution\": \"bundler\",\n    \"moduleDetection\": \"force\",\n    \"allowImportingTsExtensions\": true,\n    \"strict\": true,\n    \"downlevelIteration\": true,\n    \"skipLibCheck\": false,\n    \"jsx\": \"preserve\",\n    \"allowSyntheticDefaultImports\": true,\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"noEmit\": true,\n    \"types\": [\n      \"bun-types\" // add Bun global\n    ]\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/cli.ts",
    "content": "import fs from 'fs/promises';\nimport execa from 'execa';\nimport yargs from 'yargs';\nimport assert from 'assert';\nimport path from 'path';\nimport { createServer } from 'http';\nimport { connect } from 'net';\n\nconst TAR_NAME = 'openai.tgz';\nconst PACK_FOLDER = '.pack';\nconst PACK_FILE = `${PACK_FOLDER}/${TAR_NAME}`;\nconst IS_CI = Boolean(process.env['CI'] && process.env['CI'] !== 'false');\n\nasync function defaultNodeRunner() {\n  await installPackage();\n  await run('npm', ['run', 'tsc']);\n  if (state.live) {\n    await run('npm', ['test']);\n  }\n}\n\nconst projectRunners = {\n  'node-ts-cjs': defaultNodeRunner,\n  'node-ts-cjs-web': defaultNodeRunner,\n  'node-ts-cjs-auto': defaultNodeRunner,\n  'node-ts4.5-jest28': defaultNodeRunner,\n  'node-ts-esm': defaultNodeRunner,\n  'node-ts-esm-web': defaultNodeRunner,\n  'node-ts-esm-auto': defaultNodeRunner,\n  'node-js': async () => {\n    await installPackage();\n    await run('node', ['test.js']);\n  },\n  'ts-browser-webpack': async () => {\n    await installPackage();\n\n    await run('npm', ['run', 'tsc']);\n    await run('npm', ['run', 'build']);\n\n    if (state.live) {\n      await run('npm', ['run', 'test:ci']);\n    }\n  },\n  'browser-direct-import': async () => {\n    await installPackage();\n\n    await fs.rm('public/node_modules', { force: true });\n    await fs.symlink('../node_modules', 'public/node_modules');\n\n    await run('npm', ['run', 'tsc']);\n\n    if (state.live) {\n      await run('npm', ['run', 'test:ci']);\n    }\n  },\n  'vercel-edge': async () => {\n    await installPackage();\n\n    if (state.live) {\n      await run('npm', ['run', 'test:ci:dev']);\n    }\n    await run('npm', ['run', 'build']);\n\n    if (state.live) {\n      await run('npm', ['run', 'test:ci']);\n    }\n    if (state.deploy) {\n      await run('npm', ['run', 'vercel', 'deploy', '--prod', '--force']);\n    }\n  },\n  'cloudflare-worker': async () => {\n    await installPackage();\n\n    await fs.writeFile('.dev.vars', `OPENAI_API_KEY='${process.env['OPENAI_API_KEY']}'`);\n    await run('npm', ['run', 'tsc']);\n\n    if (state.live) {\n      await run('npm', ['run', 'test:ci']);\n    }\n    if (state.deploy) {\n      await run('npm', ['run', 'deploy']);\n    }\n  },\n  bun: async () => {\n    if (state.fromNpm) {\n      await run('bun', ['install', '-D', state.fromNpm]);\n      return;\n    }\n\n    const packFile = getPackFile();\n    await fs.copyFile(packFile, `./${TAR_NAME}`);\n    await run('bun', ['install', '-D', `./${TAR_NAME}`]);\n\n    await run('npm', ['run', 'tsc']);\n\n    if (state.live) {\n      await run('bun', ['test']);\n    }\n  },\n  // deno: async () => {\n  //   // we don't need to explicitly install the package here\n  //   // because our deno setup relies on `rootDir/deno` to exist\n  //   // which is an artifact produced from our build process\n  //   await run('deno', ['task', 'install']);\n  //   await run('deno', ['task', 'check']);\n  //\n  //   if (state.live) await run('deno', ['task', 'test']);\n  // },\n};\n\nlet projectNames = Object.keys(projectRunners) as Array<keyof typeof projectRunners>;\nconst projectNamesSet = new Set(projectNames);\n\nasync function startProxy() {\n  const proxy = createServer((_req, res) => {\n    res.end();\n  });\n\n  proxy.on('connect', (req, clientSocket, head) => {\n    console.log('got proxied connection');\n    const serverSocket = connect(443, 'api.openai.com', () => {\n      clientSocket.write(\n        'HTTP/1.1 200 Connection Established\\r\\n' + 'Proxy-agent: Node.js-Proxy\\r\\n' + '\\r\\n',\n      );\n      serverSocket.write(head);\n      serverSocket.pipe(clientSocket);\n      clientSocket.pipe(serverSocket);\n    });\n  });\n\n  await new Promise<void>((resolve) => proxy.listen(0, '127.0.0.1', resolve));\n\n  const address = proxy.address();\n  assert(address && typeof address !== 'string');\n  process.env['ECOSYSTEM_TESTS_PROXY'] = 'http://127.0.0.1:' + address.port;\n\n  return () => {\n    delete process.env['ECOSYSTEM_TESTS_PROXY'];\n    proxy.close();\n  };\n}\n\nfunction parseArgs() {\n  return yargs(process.argv.slice(2))\n    .scriptName('ecosystem-tests')\n    .usage('run tests using various different project setups')\n\n    .positional('projects', {\n      type: 'string',\n      array: true,\n      choices: projectNames,\n    })\n\n    .options({\n      verbose: {\n        type: 'boolean',\n        default: false,\n      },\n      skip: {\n        type: 'array',\n        default: [],\n        description: 'Skip one or more projects. Separate project names with a space.',\n      },\n      skipPack: {\n        type: 'boolean',\n        default: false,\n      },\n      fromNpm: {\n        type: 'string',\n        description: 'Test installing from a given NPM package instead of the local package',\n      },\n      live: {\n        type: 'boolean',\n        default: false,\n        description: 'Make live API requests',\n      },\n      deploy: {\n        type: 'boolean',\n        default: false,\n        description: 'Push projects to live servers',\n      },\n      jobs: {\n        type: 'number',\n        default: 1,\n        description: 'number of parallel jobs to run',\n      },\n      retry: {\n        type: 'number',\n        default: 0,\n        description: 'number of times to retry failing jobs',\n      },\n      retryDelay: {\n        type: 'number',\n        default: 1000,\n        description: 'delay between retries in ms',\n      },\n      parallel: {\n        type: 'boolean',\n        default: false,\n        description: 'run all projects in parallel (jobs = # projects)',\n      },\n      noCleanup: {\n        type: 'boolean',\n        default: false,\n      },\n    })\n    .help().argv;\n}\n\ntype Args = Awaited<ReturnType<typeof parseArgs>>;\n\nlet state: Args & { rootDir: string };\ntype ChildOutputChunk = { dest: 'stdout' | 'stderr'; data: string | Buffer };\n\nasync function main() {\n  if (!process.env['OPENAI_API_KEY']) {\n    console.error(`Error: The environment variable OPENAI_API_KEY must be set. Run the command\n  $echo 'OPENAI_API_KEY = \"'\"\\${OPENAI_API_KEY}\"'\"' >> ecosystem-tests/cloudflare-worker/wrangler.toml`);\n    process.exit(0);\n  }\n\n  const args = (await parseArgs()) as Args;\n  console.error(`args:`, args);\n\n  // Some projects, e.g. Deno can be slow to run, so offer the option to skip them. Example:\n  //   --skip=deno node-ts-cjs\n  if (args.skip.length > 0) {\n    args.skip.forEach((projectName, idx) => {\n      // Ensure the inputted project name is lower case\n      args.skip[idx] = (projectName + '').toLowerCase();\n    });\n\n    projectNames = projectNames.filter((projectName) => (args.skip as string[]).indexOf(projectName) < 0);\n\n    args.skip.forEach((projectName) => {\n      projectNamesSet.delete(projectName as any);\n    });\n  }\n\n  const tmpFolderPath = path.resolve(process.cwd(), 'tmp');\n\n  const rootDir = await packageDir();\n  console.error(`rootDir:`, rootDir);\n\n  state = { ...args, rootDir };\n\n  process.chdir(rootDir);\n\n  if (!args.skipPack) {\n    await buildPackage();\n  }\n\n  const positionalArgs = args._.filter(Boolean);\n\n  // For some reason `yargs` doesn't pick up the positional args correctly\n  const projectsToRun = (\n    args.projects?.length ? args.projects\n    : positionalArgs.length ?\n      positionalArgs.filter((n) => typeof n === 'string' && (projectNamesSet as Set<string>).has(n))\n    : projectNames) as typeof projectNames;\n  console.error(`running projects: ${projectsToRun}`);\n\n  const failed: typeof projectNames = [];\n\n  let cleanupWasRun = false;\n\n  // Cleanup the various artifacts created as part of executing this script\n  async function runCleanup() {\n    if (cleanupWasRun) {\n      return;\n    }\n    cleanupWasRun = true;\n\n    // Restore the original files in the ecosystem-tests folders from before\n    // npm install was run\n    await fileCache.restoreFiles(tmpFolderPath);\n\n    const packFolderPath = path.join(process.cwd(), PACK_FOLDER);\n\n    try {\n      // Clean up the .pack folder if this was the process that created it.\n      await fs.unlink(PACK_FILE);\n      await fs.rmdir(packFolderPath);\n    } catch (err) {\n      console.log('Failed to delete .pack folder', err);\n    }\n\n    for (let i = 0; i < projectNames.length; i++) {\n      const projectName = (projectNames as any)[i] as string;\n\n      await defaultNodeCleanup(projectName).catch((err: any) => {\n        console.error('Error: Cleanup of file artifacts failed for project', projectName, err);\n      });\n    }\n  }\n\n  async function runCleanupAndExit() {\n    await runCleanup();\n\n    process.exit(1);\n  }\n\n  if (!(await fileExists(tmpFolderPath))) {\n    await fs.mkdir(tmpFolderPath);\n  }\n\n  let { jobs } = args;\n  if (args.parallel) {\n    jobs = projectsToRun.length;\n  }\n\n  if (!args.noCleanup) {\n    // The cleanup code is only executed from the parent script that runs\n    // multiple projects.\n    process.on('SIGINT', runCleanupAndExit);\n    process.on('SIGTERM', runCleanupAndExit);\n    process.on('exit', runCleanup);\n\n    await fileCache.cacheFiles(tmpFolderPath);\n  }\n\n  const stopProxy = await startProxy();\n  try {\n    if (jobs > 1) {\n      const queue = [...projectsToRun];\n      const runningProjects = new Set();\n\n      const cursorLeft = '\\x1B[G';\n      const eraseLine = '\\x1B[2K';\n\n      let progressDisplayed = false;\n      function clearProgress() {\n        if (progressDisplayed) {\n          process.stderr.write(cursorLeft + eraseLine);\n          progressDisplayed = false;\n        }\n      }\n      const spinner = ['|', '/', '-', '\\\\'];\n\n      function showProgress() {\n        clearProgress();\n        progressDisplayed = true;\n        const spin = spinner[Math.floor(Date.now() / 500) % spinner.length];\n        process.stderr.write(\n          `${spin} Running ${[...runningProjects].join(', ')}`.substring(0, process.stdout.columns - 3) +\n            '...',\n        );\n      }\n\n      const progressInterval = setInterval(showProgress, process.stdout.isTTY ? 500 : 5000);\n      showProgress();\n\n      await Promise.all(\n        [...Array(jobs).keys()].map(async () => {\n          while (queue.length) {\n            const project = queue.shift();\n            if (!project) {\n              break;\n            }\n\n            // preserve interleaved ordering of writes to stdout/stderr\n            const chunks: ChildOutputChunk[] = [];\n            try {\n              runningProjects.add(project);\n              await withRetry(\n                async () => {\n                  const child = execa(\n                    'yarn',\n                    [\n                      'tsn',\n                      __filename,\n                      project,\n                      '--skip-pack',\n                      '--noCleanup',\n                      `--retry=${args.retry}`,\n                      ...(args.live ? ['--live'] : []),\n                      ...(args.verbose ? ['--verbose'] : []),\n                      ...(args.deploy ? ['--deploy'] : []),\n                      ...(args.fromNpm ? ['--from-npm'] : []),\n                    ],\n                    {\n                      stdio: 'pipe',\n                      encoding: 'utf8',\n                      maxBuffer: 100 * 1024 * 1024,\n                      env: {\n                        DISABLE_V8_COMPILE_CACHE: process.env['DISABLE_V8_COMPILE_CACHE'] ?? '1',\n                      },\n                    },\n                  );\n                  child.stdout?.on('data', (data) => chunks.push({ dest: 'stdout', data }));\n                  child.stderr?.on('data', (data) => chunks.push({ dest: 'stderr', data }));\n                  await child;\n                },\n                `${project} worker process`,\n                args.retry,\n                args.retryDelay,\n                isLikelyNodeCrash,\n              );\n            } catch (error) {\n              failed.push(project);\n            } finally {\n              runningProjects.delete(project);\n            }\n\n            if (IS_CI) {\n              console.log(`::group::${failed.includes(project) ? '❌' : '✅'} ${project}`);\n            }\n\n            for (const { data } of chunks) {\n              process.stdout.write(data);\n            }\n            if (IS_CI) console.log('::endgroup::');\n          }\n        }),\n      );\n\n      clearInterval(progressInterval);\n      clearProgress();\n    } else {\n      for (const project of projectsToRun) {\n        const fn = projectRunners[project];\n\n        await withChdir(path.join(rootDir, 'ecosystem-tests', project), async () => {\n          console.error('\\n');\n          console.error(banner(`▶️ ${project}`));\n          console.error('\\n');\n\n          try {\n            await withRetry(fn, project, state.retry, state.retryDelay);\n            console.error('\\n');\n            console.error(`✅ ${project}`);\n          } catch (err) {\n            if (err && (err as any).shortMessage) {\n              console.error((err as any).shortMessage);\n            } else {\n              console.error(err);\n            }\n            console.error('\\n');\n            console.error(`❌ ${project}`);\n            failed.push(project);\n          }\n          console.error('\\n');\n        });\n      }\n    }\n  } finally {\n    stopProxy();\n  }\n\n  if (!args.noCleanup) {\n    await runCleanup();\n  }\n\n  if (failed.length) {\n    console.error(`${failed.length} project(s) failed - ${failed.join(', ')}`);\n    process.exit(1);\n  }\n  console.error();\n  process.exit(0);\n}\n\nasync function withRetry(\n  fn: () => Promise<void>,\n  identifier: string,\n  retryAmount: number,\n  retryDelayMs: number,\n  shouldRetry: (err: unknown) => boolean = () => true,\n): Promise<void> {\n  let retriesLeft = retryAmount;\n  while (true) {\n    try {\n      return await fn();\n    } catch (err) {\n      if (retriesLeft <= 0 || !shouldRetry(err)) throw err;\n      retriesLeft -= 1;\n      console.error(\n        `${identifier} failed due to ${errorMessage(\n          err,\n        )}; retries left ${retriesLeft}, next retry in ${retryDelayMs}ms`,\n      );\n      await new Promise((resolve) => setTimeout(resolve, retryDelayMs));\n    }\n  }\n}\n\nfunction errorMessage(err: unknown): string {\n  if (\n    err &&\n    typeof err === 'object' &&\n    'shortMessage' in err &&\n    typeof (err as any).shortMessage === 'string'\n  ) {\n    return (err as any).shortMessage;\n  }\n  return String(err);\n}\n\nfunction isLikelyNodeCrash(err: unknown): boolean {\n  const signal = err && typeof err === 'object' ? (err as any).signal : undefined;\n  if (signal === 'SIGABRT' || signal === 'SIGSEGV' || signal === 'SIGBUS' || signal === 'SIGILL') {\n    return true;\n  }\n\n  const output =\n    err && typeof err === 'object' ? `${(err as any).stderr || ''}\\n${(err as any).stdout || ''}` : '';\n  return /Fatal error in|Check failed:|Segmentation fault|core dumped/i.test(output);\n}\n\nfunction centerPad(text: string, width = text.length, char = ' '): string {\n  return text.padStart(Math.floor((width + text.length) / 2), char).padEnd(width, char);\n}\n\nfunction banner(name: string, width = 80): string {\n  function line(text = ''): string {\n    if (text) text = centerPad(text, width - 40);\n    return centerPad(text, width, '/');\n  }\n  return [line(), line(), line(' '), line(name), line(' '), line(), line()].join('\\n');\n}\n\nmodule.exports = banner;\n\nasync function buildPackage() {\n  if (state.fromNpm) {\n    return;\n  }\n\n  if (!(await pathExists(PACK_FOLDER))) {\n    await fs.mkdir(PACK_FOLDER);\n  }\n\n  // Run our build script to ensure all of our build artifacts are up to date.\n  // This matters the most for deno as it directly relies on build artifacts\n  // instead of the pack file\n  await run('yarn', ['build']);\n\n  const proc = await run('npm', ['pack', '--ignore-scripts', '--json'], {\n    cwd: path.join(process.cwd(), 'dist'),\n    alwaysPipe: true,\n  });\n\n  const pack = JSON.parse(proc.stdout);\n  assert(Array.isArray(pack), `Expected pack output to be an array but got ${typeof pack}`);\n  assert(pack.length === 1, `Expected pack output to be an array of length 1 but got ${pack.length}`);\n\n  const filename = path.join('dist', (pack[0] as any).filename);\n  console.error({ filename });\n\n  await fs.rename(filename, PACK_FILE);\n  console.error(`Successfully created tarball at ${PACK_FILE}`);\n}\n\nasync function installPackage() {\n  if (state.fromNpm) {\n    await run('npm', ['install', '-D', state.fromNpm]);\n    return;\n  }\n\n  try {\n    // Ensure that there is a clean node_modules folder.\n    await run('rm', ['-rf', `./node_modules`]);\n  } catch (err) {}\n\n  const packFile = getPackFile();\n  await fs.copyFile(packFile, `./${TAR_NAME}`);\n  return await run('npm', ['install', '-D', `./${TAR_NAME}`]);\n}\n\nfunction getPackFile() {\n  return path.relative(process.cwd(), path.join(state.rootDir, PACK_FILE));\n}\n\n// ------------------ helpers ------------------\n\ninterface RunOpts extends execa.Options {\n  alwaysPipe?: boolean;\n}\n\nasync function run(command: string, args: string[], config?: RunOpts): Promise<execa.ExecaReturnValue> {\n  if (state.verbose && !config?.alwaysPipe) {\n    config = { ...config, stdio: 'inherit' };\n  }\n\n  console.debug('[run]:', command, ...args);\n  try {\n    return await execa(command, args, config);\n  } catch (error) {\n    if (error instanceof Object && !state.verbose) {\n      const { stderr, stdout } = error as any;\n      if (stderr) process.stderr.write(stderr);\n      if (stdout) process.stderr.write(stdout);\n    }\n    throw error;\n  }\n}\n\nasync function withChdir<R>(newDir: string, fn: () => Promise<R>): Promise<R> {\n  const oldDir = process.cwd();\n\n  try {\n    process.chdir(newDir);\n    return await fn();\n  } finally {\n    process.chdir(oldDir);\n  }\n}\n\nasync function pathExists(path: string) {\n  try {\n    await fs.access(path);\n    return true;\n  } catch (error) {\n    return false;\n  }\n}\n\n/**\n * Find closest parent directory that contains a file `package.json`\n */\nexport const packageDir = async (): Promise<string> => {\n  let currentDir = process.cwd();\n  const root = path.parse(currentDir).root;\n  while (currentDir !== root) {\n    const filepath = path.resolve(currentDir, 'package.json');\n    if (await pathExists(filepath)) {\n      return currentDir;\n    }\n    currentDir = path.resolve(currentDir, '..');\n  }\n\n  throw new Error('Package directory not found');\n};\n\n// Caches files that are modified by this script, e.g. package.json,\n// so that they can be restored when the script either finishes or is\n// terminated\nconst fileCache = (() => {\n  const filesToCache: Array<string> = ['package.json', 'package-lock.json', 'deno.lock', 'bun.lockb'];\n\n  return {\n    // Copy existing files from each ecosystem-tests project folder to the ./tmp folder\n    cacheFiles: async (tmpFolderPath: string) => {\n      for (let i = 0; i < projectNames.length; i++) {\n        const projectName = (projectNames as any)[i] as string;\n        const projectPath = path.resolve(process.cwd(), 'ecosystem-tests', projectName);\n\n        for (let j = 0; j < filesToCache.length; j++) {\n          const fileName = filesToCache[j] || '';\n\n          const filePath = path.resolve(projectPath, fileName);\n          if (await fileExists(filePath)) {\n            const tmpProjectPath = path.resolve(tmpFolderPath, projectName);\n\n            if (!(await fileExists(tmpProjectPath))) {\n              await fs.mkdir(tmpProjectPath);\n            }\n            await fs.copyFile(filePath, path.resolve(tmpProjectPath, fileName));\n          }\n        }\n      }\n    },\n\n    // Restore the original files to each ecosystem-tests project folder from the ./tmp folder\n    restoreFiles: async (tmpFolderPath: string) => {\n      for (let i = 0; i < projectNames.length; i++) {\n        const projectName = (projectNames as any)[i] as string;\n\n        const projectPath = path.resolve(process.cwd(), 'ecosystem-tests', projectName);\n        const tmpProjectPath = path.resolve(tmpFolderPath, projectName);\n\n        for (let j = 0; j < filesToCache.length; j++) {\n          const fileName = filesToCache[j] || '';\n\n          const filePath = path.resolve(tmpProjectPath, fileName);\n          if (await fileExists(filePath)) {\n            await fs.rename(filePath, path.resolve(projectPath, fileName));\n          }\n        }\n        await fs.rmdir(tmpProjectPath);\n      }\n    },\n  };\n})();\n\nasync function defaultNodeCleanup(projectName: string) {\n  try {\n    const projectPath = path.resolve(process.cwd(), 'ecosystem-tests', projectName);\n\n    const packFilePath = path.resolve(projectPath, TAR_NAME);\n\n    if (await fileExists(packFilePath)) {\n      await fs.unlink(packFilePath);\n    }\n  } catch (err) {\n    console.error('Cleanup failed for project', projectName, err);\n  }\n}\n\nasync function fileExists(filePath: string) {\n  try {\n    await fs.stat(filePath);\n    return true;\n  } catch {\n    return false;\n  }\n}\n\nmain().catch((err) => {\n  console.error(err);\n  process.exit(1);\n});\n"
  },
  {
    "path": "ecosystem-tests/cloudflare-worker/.editorconfig",
    "content": "# http://editorconfig.org\nroot = true\n\n[*]\nindent_style = tab\ntab_width = 2\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\n\n[*.yml]\nindent_style = space\n"
  },
  {
    "path": "ecosystem-tests/cloudflare-worker/.prettierrc",
    "content": "{\n\t\"printWidth\": 140,\n\t\"singleQuote\": true,\n\t\"semi\": true,\n\t\"useTabs\": true\n}\n"
  },
  {
    "path": "ecosystem-tests/cloudflare-worker/jest.config.cjs",
    "content": "/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = {\n\ttransform: {},\n\ttestEnvironment: 'node',\n\ttestMatch: ['<rootDir>/tests/*.js'],\n\twatchPathIgnorePatterns: ['<rootDir>/node_modules/'],\n\tverbose: false,\n\ttestTimeout: 60000,\n};\n"
  },
  {
    "path": "ecosystem-tests/cloudflare-worker/package.json",
    "content": "{\n\t\"name\": \"cfw\",\n\t\"version\": \"0.0.0\",\n\t\"private\": true,\n\t\"type\": \"module\",\n\t\"scripts\": {\n\t\t\"tsc\": \"tsc && tsc -p tsconfig.check.json\",\n\t\t\"deploy\": \"wrangler publish\",\n\t\t\"start\": \"wrangler dev\",\n\t\t\"test\": \"node --experimental-vm-modules node_modules/jest/bin/jest.js\",\n\t\t\"test:ci\": \"start-server-and-test start http://localhost:8787 test\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@cloudflare/workers-types\": \"^4.20250525.0\",\n\t\t\"fastest-levenshtein\": \"^1.0.16\",\n\t\t\"jest\": \"^29.5.0\",\n\t\t\"start-server-and-test\": \"^2.0.0\",\n\t\t\"ts-jest\": \"^29.1.0\",\n\t\t\"typescript\": \"5.8.3\",\n\t\t\"wrangler\": \"^3.74.0\"\n\t}\n}\n"
  },
  {
    "path": "ecosystem-tests/cloudflare-worker/src/uploadWebApiTestCases.ts",
    "content": "import OpenAI, { toFile } from 'openai';\nimport { TranscriptionCreateParams } from 'openai/resources/audio/transcriptions';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\n/**\n * Tests uploads using various Web API data objects.\n * This is structured to support running these tests on builtins in the environment in\n * Node or Cloudflare workers etc. or on polyfills like from node-fetch/formdata-node\n */\nexport function uploadWebApiTestCases({\n\tclient,\n\tit,\n\texpectEqual,\n\texpectSimilar,\n}: {\n\t/**\n\t * OpenAI client instance\n\t */\n\tclient: OpenAI;\n\t/**\n\t * Jest it() function, or an imitation in envs like Cloudflare workers\n\t */\n\tit: (desc: string, handler: () => Promise<void>) => void;\n\t/**\n\t * Jest expect(a).toEqual(b) function, or an imitation in envs like Cloudflare workers\n\t */\n\texpectEqual(a: unknown, b: unknown): void;\n\t/**\n\t * Assert that the levenshtein distance between the two given strings is less than the given max distance.\n\t */\n\texpectSimilar(received: string, expected: string, maxDistance: number): void;\n}) {\n\tconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\n\tconst filename = 'sample-1.mp3';\n\n\tconst correctAnswer =\n\t\t'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\n\tconst model = 'whisper-1';\n\n\tasync function typeTests() {\n\t\t// @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n\t\tawait client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n\t\t// @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n\t\tawait client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n\t\t// @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n\t\tawait client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n\t}\n\n\tit(`raw response`, async function () {\n\t\tconst response = await client.chat.completions\n\t\t\t.create({\n\t\t\t\tmodel: 'gpt-4',\n\t\t\t\tmessages: [{ role: 'user', content: 'Say this is a test' }],\n\t\t\t})\n\t\t\t.asResponse();\n\n\t\t// test that we can use web Response API\n\t\tconst { body } = response;\n\t\tif (!body) throw new Error('expected response.body to be defined');\n\n\t\tconst reader = body.getReader();\n\t\tconst chunks: Uint8Array[] = [];\n\t\tlet result;\n\t\tdo {\n\t\t\tresult = await reader.read();\n\t\t\tif (!result.done) chunks.push(result.value);\n\t\t} while (!result.done);\n\n\t\treader.releaseLock();\n\n\t\tlet offset = 0;\n\t\tconst merged = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n\t\tfor (const chunk of chunks) {\n\t\t\tmerged.set(chunk, offset);\n\t\t\toffset += chunk.length;\n\t\t}\n\n\t\tconst json: ChatCompletion = JSON.parse(new TextDecoder().decode(merged));\n\t\texpectSimilar(json.choices[0]?.message.content || '', 'This is a test', 10);\n\t});\n\n\tit(`streaming works`, async function () {\n\t\tconst stream = await client.chat.completions.create({\n\t\t\tmodel: 'gpt-4',\n\t\t\tmessages: [{ role: 'user', content: 'Say this is a test' }],\n\t\t\tstream: true,\n\t\t});\n\t\tconst chunks = [];\n\t\tfor await (const part of stream) {\n\t\t\tchunks.push(part);\n\t\t}\n\t\texpectSimilar(chunks.map((c) => c.choices[0]?.delta.content || '').join(''), 'This is a test', 10);\n\t});\n\n\tit('handles File', async () => {\n\t\tconst file = await fetch(url)\n\t\t\t.then((x) => x.arrayBuffer())\n\t\t\t.then((x) => new File([x], filename));\n\n\t\tconst params: TranscriptionCreateParams = { file, model };\n\n\t\tconst result = await client.audio.transcriptions.create(params);\n\t\texpectSimilar(result.text, correctAnswer, 12);\n\t});\n\n\tit('handles Response', async () => {\n\t\tconst file = await fetch(url);\n\n\t\tconst result = await client.audio.transcriptions.create({ file, model });\n\t\texpectSimilar(result.text, correctAnswer, 12);\n\t});\n\n\tconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\n\tit('toFile handles string', async () => {\n\t\t// @ts-expect-error we don't type support for `string` to avoid a footgun with passing the file path\n\t\tconst file = await toFile(fineTune, 'finetune.jsonl');\n\t\tconst result = await client.files.create({ file, purpose: 'fine-tune' });\n\t\texpectEqual(result.filename, 'finetune.jsonl');\n\t});\n\tit('toFile handles Blob', async () => {\n\t\tconst result = await client.files.create({ file: await toFile(new Blob([fineTune]), 'finetune.jsonl'), purpose: 'fine-tune' });\n\t\texpectEqual(result.filename, 'finetune.jsonl');\n\t});\n\tit('toFile handles Uint8Array', async () => {\n\t\tconst result = await client.files.create({\n\t\t\tfile: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n\t\t\tpurpose: 'fine-tune',\n\t\t});\n\t\texpectEqual(result.filename, 'finetune.jsonl');\n\t});\n\tit('toFile handles ArrayBuffer', async () => {\n\t\tconst result = await client.files.create({\n\t\t\t// @ts-ignore\n\t\t\tfile: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n\t\t\tpurpose: 'fine-tune',\n\t\t});\n\t\texpectEqual(result.filename, 'finetune.jsonl');\n\t});\n\tit('toFile handles DataView', async () => {\n\t\tconst result = await client.files.create({\n\t\t\tfile: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n\t\t\tpurpose: 'fine-tune',\n\t\t});\n\t\texpectEqual(result.filename, 'finetune.jsonl');\n\t});\n}\n"
  },
  {
    "path": "ecosystem-tests/cloudflare-worker/src/worker.ts",
    "content": "import { distance } from 'fastest-levenshtein';\n\n/**\n * Welcome to Cloudflare Workers! This is your first worker.\n *\n * - Run `npm run dev` in your terminal to start a development server\n * - Open a browser tab at http://localhost:8787/ to see your worker in action\n * - Run `npm run deploy` to publish your worker\n *\n * Learn more at https://developers.cloudflare.com/workers/\n */\n\nexport interface Env {\n\t// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/\n\t// MY_KV_NAMESPACE: KVNamespace;\n\t//\n\t// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/\n\t// MY_DURABLE_OBJECT: DurableObjectNamespace;\n\t//\n\t// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/\n\t// MY_BUCKET: R2Bucket;\n\t//\n\t// Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/\n\t// MY_SERVICE: Fetcher;\n\t//\n\t// Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/\n\t// MY_QUEUE: Queue;\n\n\tOPENAI_API_KEY: string;\n}\n\ntype Test = { description: string; handler: () => Promise<void> };\n\nexport default {\n\tasync fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {\n\t\tconst url = new URL(request.url);\n\t\t// start-server-and-test polls / to see if the server is up and running\n\t\tif (url.pathname === '/') return new Response();\n\t\t// then the test code requests /test\n\t\tif (url.pathname !== '/test') return new Response(null, { status: 404 });\n\t\ttry {\n\t\t\tconsole.error('importing openai');\n\t\t\tconst { default: OpenAI } = await import('openai');\n\t\t\tconsole.error('importing test cases');\n\t\t\tconst { uploadWebApiTestCases } = await import('./uploadWebApiTestCases.js');\n\t\t\tconsole.error('creating client');\n\t\t\tconst client = new OpenAI({ apiKey: env.OPENAI_API_KEY });\n\t\t\tconsole.error('created client');\n\n\t\t\tconst tests: Test[] = [];\n\t\t\tfunction it(description: string, handler: () => Promise<void>) {\n\t\t\t\ttests.push({ description, handler });\n\t\t\t}\n\t\t\tfunction expectEqual(a: any, b: any) {\n\t\t\t\tif (!Object.is(a, b)) {\n\t\t\t\t\tthrow new Error(`expected values to be equal: ${JSON.stringify({ a, b })}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfunction expectSimilar(received: string, expected: string, maxDistance: number) {\n\t\t\t\tconst receivedDistance = distance(received, expected);\n\t\t\t\tif (receivedDistance < maxDistance) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst message = [\n\t\t\t\t\t`Received: ${JSON.stringify(received)}`,\n\t\t\t\t\t`Expected: ${JSON.stringify(expected)}`,\n\t\t\t\t\t`Max distance: ${maxDistance}`,\n\t\t\t\t\t`Received distance: ${receivedDistance}`,\n\t\t\t\t].join('\\n');\n\n\t\t\t\tthrow new Error(message);\n\t\t\t}\n\n\t\t\tuploadWebApiTestCases({\n\t\t\t\tclient: client as any,\n\t\t\t\tit,\n\t\t\t\texpectEqual,\n\t\t\t\texpectSimilar,\n\t\t\t});\n\n\t\t\tlet allPassed = true;\n\t\t\tconst results = [];\n\n\t\t\tfor (const { description, handler } of tests) {\n\t\t\t\tconsole.error('running', description);\n\t\t\t\tlet result;\n\t\t\t\ttry {\n\t\t\t\t\tresult = await handler();\n\t\t\t\t\tconsole.error('passed ', description);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error('failed ', description, error);\n\t\t\t\t\tallPassed = false;\n\t\t\t\t\tresult = error instanceof Error ? error.stack : String(error);\n\t\t\t\t}\n\t\t\t\tresults.push(`${description}\\n\\n${String(result)}`);\n\t\t\t}\n\n\t\t\treturn new Response(allPassed ? 'Passed!' : results.join('\\n\\n'));\n\t\t} catch (error) {\n\t\t\tconsole.error(error instanceof Error ? error.stack : String(error));\n\t\t\treturn new Response(error instanceof Error ? error.stack : String(error), { status: 500 });\n\t\t}\n\t},\n};\n"
  },
  {
    "path": "ecosystem-tests/cloudflare-worker/tests/test.js",
    "content": "it(\n\t'works',\n\tasync () => {\n\t\texpect(await (await fetch('http://localhost:8787/test')).text()).toEqual('Passed!');\n\t},\n\t3 * 60000\n);\n"
  },
  {
    "path": "ecosystem-tests/cloudflare-worker/tsconfig.check.json",
    "content": "{\n  \"extends\": \"./tsconfig.json\",\n  \"include\": [\"src\"],\n  \"exclude\": [\"tests\", \"jest.config.cjs\"],\n  \"compilerOptions\": {\n    \"skipLibCheck\": true\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/cloudflare-worker/tsconfig.json",
    "content": "{\n\t\"include\": [\"src/*.ts\"],\n\t\"compilerOptions\": {\n\t\t/* Visit https://aka.ms/tsconfig.json to read more about this file */\n\n\t\t/* Projects */\n\t\t// \"incremental\": true,                              /* Enable incremental compilation */\n\t\t// \"composite\": true,                                /* Enable constraints that allow a TypeScript project to be used with project references. */\n\t\t// \"tsBuildInfoFile\": \"./\",                          /* Specify the folder for .tsbuildinfo incremental compilation files. */\n\t\t// \"disableSourceOfProjectReferenceRedirect\": true,  /* Disable preferring source files instead of declaration files when referencing composite projects */\n\t\t// \"disableSolutionSearching\": true,                 /* Opt a project out of multi-project reference checking when editing. */\n\t\t// \"disableReferencedProjectLoad\": true,             /* Reduce the number of projects loaded automatically by TypeScript. */\n\n\t\t/* Language and Environment */\n\t\t\"target\": \"ESNext\" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,\n\t\t\"lib\": [\"ESNext\"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,\n\t\t\"jsx\": \"react\" /* Specify what JSX code is generated. */,\n\t\t// \"experimentalDecorators\": true,                   /* Enable experimental support for TC39 stage 2 draft decorators. */\n\t\t// \"emitDecoratorMetadata\": true,                    /* Emit design-type metadata for decorated declarations in source files. */\n\t\t// \"jsxFactory\": \"\",                                 /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */\n\t\t// \"jsxFragmentFactory\": \"\",                         /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */\n\t\t// \"jsxImportSource\": \"\",                            /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */\n\t\t// \"reactNamespace\": \"\",                             /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */\n\t\t// \"noLib\": true,                                    /* Disable including any library files, including the default lib.d.ts. */\n\t\t// \"useDefineForClassFields\": true,                  /* Emit ECMAScript-standard-compliant class fields. */\n\n\t\t/* Modules */\n\t\t\"module\": \"es2022\" /* Specify what module code is generated. */,\n\t\t// \"rootDir\": \"./\",                                 /* Specify the root folder within your source files. */\n\t\t\"moduleResolution\": \"bundler\" /* Specify how TypeScript looks up a file from a given module specifier. */,\n\t\t// \"baseUrl\": \"./\",                                  /* Specify the base directory to resolve non-relative module names. */\n\t\t// \"paths\": {},                                      /* Specify a set of entries that re-map imports to additional lookup locations. */\n\t\t// \"rootDirs\": [],                                   /* Allow multiple folders to be treated as one when resolving modules. */\n\t\t// \"typeRoots\": [],                                  /* Specify multiple folders that act like `./node_modules/@types`. */\n\t\t\"types\": [\"@cloudflare/workers-types\"] /* Specify type package names to be included without being referenced in a source file. */,\n\t\t// \"allowUmdGlobalAccess\": true,                     /* Allow accessing UMD globals from modules. */\n\t\t// \"resolveJsonModule\": true /* Enable importing .json files */,\n\t\t// \"noResolve\": true,                                /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */\n\n\t\t/* JavaScript Support */\n\t\t\"allowJs\": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */,\n\t\t\"checkJs\": false /* Enable error reporting in type-checked JavaScript files. */,\n\t\t// \"maxNodeModuleJsDepth\": 1,                        /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */\n\n\t\t/* Emit */\n\t\t// \"declaration\": true,                              /* Generate .d.ts files from TypeScript and JavaScript files in your project. */\n\t\t// \"declarationMap\": true,                           /* Create sourcemaps for d.ts files. */\n\t\t// \"emitDeclarationOnly\": true,                      /* Only output d.ts files and not JavaScript files. */\n\t\t// \"sourceMap\": true,                                /* Create source map files for emitted JavaScript files. */\n\t\t// \"outFile\": \"./\",                                  /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */\n\t\t// \"outDir\": \"./\",                                   /* Specify an output folder for all emitted files. */\n\t\t// \"removeComments\": true,                           /* Disable emitting comments. */\n\t\t\"noEmit\": true /* Disable emitting files from a compilation. */,\n\t\t// \"importHelpers\": true,                            /* Allow importing helper functions from tslib once per project, instead of including them per-file. */\n\t\t// \"importsNotUsedAsValues\": \"remove\",               /* Specify emit/checking behavior for imports that are only used for types */\n\t\t// \"downlevelIteration\": true,                       /* Emit more compliant, but verbose and less performant JavaScript for iteration. */\n\t\t// \"sourceRoot\": \"\",                                 /* Specify the root path for debuggers to find the reference source code. */\n\t\t// \"mapRoot\": \"\",                                    /* Specify the location where debugger should locate map files instead of generated locations. */\n\t\t// \"inlineSourceMap\": true,                          /* Include sourcemap files inside the emitted JavaScript. */\n\t\t// \"inlineSources\": true,                            /* Include source code in the sourcemaps inside the emitted JavaScript. */\n\t\t// \"emitBOM\": true,                                  /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */\n\t\t// \"newLine\": \"crlf\",                                /* Set the newline character for emitting files. */\n\t\t// \"stripInternal\": true,                            /* Disable emitting declarations that have `@internal` in their JSDoc comments. */\n\t\t// \"noEmitHelpers\": true,                            /* Disable generating custom helper functions like `__extends` in compiled output. */\n\t\t// \"noEmitOnError\": true,                            /* Disable emitting files if any type checking errors are reported. */\n\t\t// \"preserveConstEnums\": true,                       /* Disable erasing `const enum` declarations in generated code. */\n\t\t// \"declarationDir\": \"./\",                           /* Specify the output directory for generated declaration files. */\n\t\t// \"preserveValueImports\": true,                     /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */\n\n\t\t/* Interop Constraints */\n\t\t\"isolatedModules\": true /* Ensure that each file can be safely transpiled without relying on other imports. */,\n\t\t\"allowSyntheticDefaultImports\": true /* Allow 'import x from y' when a module doesn't have a default export. */,\n\t\t// \"esModuleInterop\": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,\n\t\t// \"preserveSymlinks\": true,                         /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */\n\t\t\"forceConsistentCasingInFileNames\": true /* Ensure that casing is correct in imports. */,\n\n\t\t/* Type Checking */\n\t\t\"strict\": true /* Enable all strict type-checking options. */,\n\t\t// \"noImplicitAny\": true,                            /* Enable error reporting for expressions and declarations with an implied `any` type.. */\n\t\t// \"strictNullChecks\": true,                         /* When type checking, take into account `null` and `undefined`. */\n\t\t// \"strictFunctionTypes\": true,                      /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */\n\t\t// \"strictBindCallApply\": true,                      /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */\n\t\t// \"strictPropertyInitialization\": true,             /* Check for class properties that are declared but not set in the constructor. */\n\t\t// \"noImplicitThis\": true,                           /* Enable error reporting when `this` is given the type `any`. */\n\t\t// \"useUnknownInCatchVariables\": true,               /* Type catch clause variables as 'unknown' instead of 'any'. */\n\t\t// \"alwaysStrict\": true,                             /* Ensure 'use strict' is always emitted. */\n\t\t// \"noUnusedLocals\": true,                           /* Enable error reporting when a local variables aren't read. */\n\t\t// \"noUnusedParameters\": true,                       /* Raise an error when a function parameter isn't read */\n\t\t// \"exactOptionalPropertyTypes\": true,               /* Interpret optional property types as written, rather than adding 'undefined'. */\n\t\t// \"noImplicitReturns\": true,                        /* Enable error reporting for codepaths that do not explicitly return in a function. */\n\t\t// \"noFallthroughCasesInSwitch\": true,               /* Enable error reporting for fallthrough cases in switch statements. */\n\t\t// \"noUncheckedIndexedAccess\": true,                 /* Include 'undefined' in index signature results */\n\t\t// \"noImplicitOverride\": true,                       /* Ensure overriding members in derived classes are marked with an override modifier. */\n\t\t// \"noPropertyAccessFromIndexSignature\": true,       /* Enforces using indexed accessors for keys declared using an indexed type */\n\t\t// \"allowUnusedLabels\": true,                        /* Disable error reporting for unused labels. */\n\t\t// \"allowUnreachableCode\": true,                     /* Disable error reporting for unreachable code. */\n\n\t\t/* Completeness */\n\t\t// \"skipDefaultLibCheck\": true,                      /* Skip type checking .d.ts files that are included with TypeScript. */\n\t\t\"skipLibCheck\": true /* Skip type checking all .d.ts files. */\n\t}\n}\n"
  },
  {
    "path": "ecosystem-tests/cloudflare-worker/wrangler.toml",
    "content": "name = \"cfw\"\nmain = \"src/worker.ts\"\ncompatibility_date = \"2023-06-18\"\n#node_compat = true\n\n# # KV Namespace binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/kv\n# [[kv_namespaces]]\n# binding = \"MY_KV_NAMESPACE\"\n# id = \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n\n# # Durable Object binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/durable-objects\n# [[durable_objects]]\n# binding = \"MY_DURABLE_OBJECT\"\n# class_name = \"MyDurableObject\"\n\n# # Bucket binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/kv#bucket\n# [[buckets]]\n# binding = \"MY_BUCKET\"\n# name = \"my-bucket\"\n# bucket_id = \"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\"\n\n# # Service binding - For more information: https://developers.cloudflare.com/workers/platform/services\n# [[routes]]\n# binding = \"MY_SERVICE\"\n# pattern = \"/api/*\"\n# script = \"api.js\"\n\n# # Queue binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/queues\n# [[queues]]\n# binding = \"MY_QUEUE\"\n# name = \"my-queue\"\n# zone_id = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n\n# [env.production]\n# MY_VARIABLE = \"production_value\"\n\n# [env.staging]\n# MY_VARIABLE = \"staging_value\"\n\n# [env.shared]\n# SHARED_VARIABLE = \"shared_value\"\n\n[vars]\n"
  },
  {
    "path": "ecosystem-tests/deno/deno.jsonc",
    "content": "{\n  \"tasks\": {\n    \"install\": \"deno install --node-modules-dir main_test.ts -f\",\n    \"check\": \"deno lint && deno check main_test.ts\",\n    \"test\": \"deno test --allow-env --allow-net --allow-read --node-modules-dir\"\n  },\n  \"imports\": {\n    \"openai\": \"../../deno/mod.ts\",\n    \"openai/\": \"../../deno/\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/deno/main_test.ts",
    "content": "import { assertEquals, AssertionError } from 'https://deno.land/std@0.192.0/testing/asserts.ts';\nimport { distance } from 'https://deno.land/x/fastest_levenshtein/mod.ts';\nimport OpenAI, { toFile } from 'openai';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI({ apiKey: Deno.env.get('OPENAI_API_KEY') });\n\nasync function _typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\nfunction assertSimilar(received: string, expected: string, maxDistance: number) {\n  const receivedDistance = distance(received, expected);\n  if (receivedDistance < maxDistance) {\n    return;\n  }\n\n  const message = [\n    `Received: ${JSON.stringify(received)}`,\n    `Expected: ${JSON.stringify(expected)}`,\n    `Max distance: ${maxDistance}`,\n    `Received distance: ${receivedDistance}`,\n  ].join('\\n');\n\n  throw new AssertionError(message);\n}\n\nDeno.test(async function rawResponse() {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  // test that we can use web Response API\n  const { body } = response;\n  if (!body) throw new Error('expected response.body to be defined');\n\n  const reader = body.getReader();\n  const chunks: Uint8Array[] = [];\n  let result;\n  do {\n    result = await reader.read();\n    if (!result.done) chunks.push(result.value);\n  } while (!result.done);\n\n  reader.releaseLock();\n\n  let offset = 0;\n  const merged = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n  for (const chunk of chunks) {\n    merged.set(chunk, offset);\n    offset += chunk.length;\n  }\n\n  const json: OpenAI.ChatCompletion = JSON.parse(new TextDecoder().decode(merged));\n  assertSimilar(json.choices[0]?.message.content || '', 'This is a test', 10);\n});\n\nDeno.test(async function streamingWorks() {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  assertSimilar(chunks.map((c) => c.choices[0]?.delta.content || '').join(''), 'This is a test', 10);\n});\n\nDeno.test(async function handlesFile() {\n  const file = await fetch(url)\n    .then((x) => x.arrayBuffer())\n    .then((x) => new File([x], filename));\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  assertSimilar(result.text, correctAnswer, 12);\n});\nDeno.test(async function handlesResponse() {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  assertSimilar(result.text, correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\nDeno.test(async function toFileHandlesBlob() {\n  const result = await client.files.create({\n    file: await toFile(new Blob([fineTune]), 'finetune.jsonl'),\n    purpose: 'fine-tune',\n  });\n  assertEquals(result.filename, 'finetune.jsonl');\n});\nDeno.test(async function toFileHandlesUint8Array() {\n  const result = await client.files.create({\n    file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n    purpose: 'fine-tune',\n  });\n  assertEquals(result.filename, 'finetune.jsonl');\n});\nDeno.test(async function toFileHandlesArrayBuffer() {\n  const result = await client.files.create({\n    file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n    purpose: 'fine-tune',\n  });\n  assertEquals(result.filename, 'finetune.jsonl');\n});\nDeno.test(async function toFileHandlesDataView() {\n  const result = await client.files.create({\n    file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n    purpose: 'fine-tune',\n  });\n  assertEquals(result.filename, 'finetune.jsonl');\n});\n"
  },
  {
    "path": "ecosystem-tests/node-js/package.json",
    "content": "{\n  \"name\": \"node-js\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"author\": \"\",\n  \"license\": \"ISC\"\n}\n"
  },
  {
    "path": "ecosystem-tests/node-js/test.js",
    "content": "const openaiKey = \"a valid OpenAI key\"\nconst OpenAI = require('openai');\n\nconsole.log(OpenAI)\n\nconst openai = new OpenAI({\n\tapiKey: openaiKey,\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs/jest.config.cjs",
    "content": "/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = {\n  preset: 'ts-jest',\n  testEnvironment: 'node',\n  testMatch: ['<rootDir>/tests/*.ts'],\n  watchPathIgnorePatterns: ['<rootDir>/node_modules/'],\n  verbose: false,\n  testTimeout: 60000,\n};\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs/package.json",
    "content": "{\n  \"name\": \"node-ts-cjs\",\n  \"version\": \"0.0.1\",\n  \"main\": \"index.js\",\n  \"private\": true,\n  \"scripts\": {\n    \"tsc\": \"tsc && tsc -p tsconfig.nodenext.json\",\n    \"test\": \"jest\"\n  },\n  \"dependencies\": {\n    \"formdata-node\": \"^4.4.1\",\n    \"tsconfig-paths\": \"^4.0.0\",\n    \"typescript\": \"^5.7.3\",\n    \"undici\": \"^7.10.0\"\n  },\n  \"devDependencies\": {\n    \"@types/node\": \"^20.14.8\",\n    \"@types/ws\": \"^8.5.4\",\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"jest\": \"^29.5.0\",\n    \"jest-fixed-jsdom\": \"^0.0.10\",\n    \"ts-jest\": \"^29.1.0\"\n  },\n  \"type\": \"commonjs\"\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs/tests/test-jsdom.ts",
    "content": "/**\n * @jest-environment jest-fixed-jsdom\n */\nimport OpenAI, { toFile } from 'openai';\nimport { distance } from 'fastest-levenshtein';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI({\n  apiKey: process.env['OPENAI_API_KEY'],\n  dangerouslyAllowBrowser: true,\n});\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\ndeclare global {\n  namespace jest {\n    interface Matchers<R> {\n      toBeSimilarTo(comparedTo: string, expectedDistance: number): R;\n    }\n  }\n}\nexpect.extend({\n  toBeSimilarTo(received, comparedTo: string, expectedDistance: number) {\n    const message = () =>\n      [\n        `Received: ${JSON.stringify(received)}`,\n        `Expected: ${JSON.stringify(comparedTo)}`,\n        `Expected distance: ${expectedDistance}`,\n        `Received distance: ${actualDistance}`,\n      ].join('\\n');\n\n    const actualDistance = distance(received, comparedTo);\n    if (actualDistance < expectedDistance) {\n      return {\n        message,\n        pass: true,\n      };\n    }\n\n    return {\n      message,\n      pass: false,\n    };\n  },\n});\n\ntest(`basic request works`, async function () {\n  const completion = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n  });\n  expect(completion.choices[0]?.message?.content).toBeSimilarTo('This is a test', 10);\n});\n\nit(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\nit.skip('handles builtinFile', async function () {\n  const file = await fetch(url)\n    .then((x) => x.arrayBuffer())\n    .then((x) => new File([x], filename));\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit.skip('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe.skip('toFile', () => {\n  it('handles builtin Blob', async function () {\n    const result = await client.files.create({\n      file: await toFile(new Blob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs/tests/test-node.ts",
    "content": "import OpenAI, { toFile } from 'openai';\nimport { TranscriptionCreateParams } from 'openai/resources/audio/transcriptions';\nimport * as undici from 'undici';\nimport { File as FormDataFile, Blob as FormDataBlob } from 'formdata-node';\nimport * as fs from 'fs';\nimport { distance } from 'fastest-levenshtein';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI();\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\ndeclare global {\n  namespace jest {\n    interface Matchers<R> {\n      toBeSimilarTo(comparedTo: string, expectedDistance: number): R;\n    }\n  }\n}\nexpect.extend({\n  toBeSimilarTo(received, comparedTo: string, expectedDistance: number) {\n    const message = () =>\n      [\n        `Received: ${JSON.stringify(received)}`,\n        `Expected: ${JSON.stringify(comparedTo)}`,\n        `Expected distance: ${expectedDistance}`,\n        `Received distance: ${actualDistance}`,\n      ].join('\\n');\n\n    const actualDistance = distance(received, comparedTo);\n    if (actualDistance < expectedDistance) {\n      return {\n        message,\n        pass: true,\n      };\n    }\n\n    return {\n      message,\n      pass: false,\n    };\n  },\n});\n\nit(`raw response`, async function () {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  const decoder = new TextDecoder();\n  const chunks: string[] = [];\n  for await (const chunk of response.body!) {\n    chunks.push(decoder.decode(chunk));\n  }\n\n  const json: ChatCompletion = JSON.parse(chunks.join(''));\n  expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);\n});\n\nit(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\n// TODO: setup proxy server\ntest.skip(`proxied request`, async function () {\n  const dispatcher = new undici.ProxyAgent(process.env['ECOSYSTEM_TESTS_PROXY']!);\n  const client = new OpenAI({\n    fetchOptions: {\n      dispatcher,\n    },\n  });\n  const completion = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n  });\n  expect(completion.choices[0]?.message?.content).toBeSimilarTo('This is a test', 10);\n});\n\nit('handles builtinFile', async function () {\n  const file = await fetch(url)\n    .then((x) => x.arrayBuffer())\n    .then(\n      (x) =>\n        new File(\n          [\n            // @ts-ignore array buffer can't be passed to File at the type-level\n            x,\n          ],\n          filename,\n        ),\n    );\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit('handles fs.ReadStream', async function () {\n  const result = await client.audio.transcriptions.create({\n    file: fs.createReadStream('sample1.mp3'),\n    model,\n  });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe('toFile', () => {\n  it('handles form-data Blob', async function () {\n    const result = await client.files.create({\n      file: await toFile(new FormDataBlob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  if (typeof Blob !== 'undefined') {\n    it('handles builtin Blob', async function () {\n      const result = await client.files.create({\n        file: await toFile(new Blob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n        purpose: 'fine-tune',\n      });\n      expect(result.filename).toEqual('finetune.jsonl');\n    });\n  }\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n\n  it('handles formdata-node File', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      .then((x) => toFile(new FormDataFile([x], filename)));\n\n    expect(file.name).toEqual(filename);\n  \n    const params: TranscriptionCreateParams = { file, model };\n  \n    const result = await client.audio.transcriptions.create(params);\n    expect(result.text).toBeSimilarTo(correctAnswer, 12);\n  });\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs/tsconfig.json",
    "content": "{\n  \"include\": [\"tests/*.ts\"],\n  \"exclude\": [\"tests/*-shim-errors.ts\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2015\",\n    \"lib\": [\"ES2015\", \"DOM.AsyncIterable\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"commonjs\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"node\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": false\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs/tsconfig.nodenext.json",
    "content": "{\n  \"include\": [\"tests/*.ts\"],\n  \"exclude\": [\"tests/*-shim-errors.ts\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2015\",\n    \"lib\": [\"ES2015\", \"DOM.AsyncIterable\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"NodeNext\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"NodeNext\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": false\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-auto/jest.config.cjs",
    "content": "/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = {\n  preset: 'ts-jest',\n  testEnvironment: 'node',\n  testMatch: ['<rootDir>/tests/*.ts'],\n  watchPathIgnorePatterns: ['<rootDir>/node_modules/'],\n  verbose: false,\n  testTimeout: 60000,\n};\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-auto/moduleResolution/node/type-tests.ts",
    "content": "import OpenAI from 'openai';\n\nconst client = new OpenAI();\n\nasync function typeTests() {\n  const response = await client.audio.transcriptions\n    .create({\n      file: 'test' as any,\n      model: 'whisper-1',\n    })\n    .asResponse();\n  response.body;\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-auto/moduleResolution/nodenext/type-tests.ts",
    "content": "import OpenAI from 'openai';\n\nasync function typeTests(client: OpenAI) {\n  const response = await client.chat.completions.create({ model: 'gpt-4o', messages: [] }).asResponse();\n  const url: string = response.url;\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-auto/package.json",
    "content": "{\n  \"name\": \"node-ts-cjs-auto\",\n  \"version\": \"0.0.1\",\n  \"main\": \"index.js\",\n  \"private\": true,\n  \"scripts\": {\n    \"tsc\": \"tsc && tsc -p tsconfig.nodenext.json\",\n    \"test\": \"jest\"\n  },\n  \"dependencies\": {\n    \"formdata-node\": \"^4.4.1\",\n    \"tsconfig-paths\": \"^4.0.0\"\n  },\n  \"devDependencies\": {\n    \"@types/node\": \"^20.4.2\",\n    \"@types/ws\": \"^8.5.4\",\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"jest\": \"^28.1.3\",\n    \"ts-jest\": \"^28.0.8\",\n    \"typescript\": \"4.7.4\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-auto/tests/test.ts",
    "content": "import OpenAI, { APIUserAbortError, toFile } from 'openai';\nimport { TranscriptionCreateParams } from 'openai/resources/audio/transcriptions';\nimport { File as FormDataFile, Blob as FormDataBlob } from 'formdata-node';\nimport * as fs from 'fs';\nimport { distance } from 'fastest-levenshtein';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI();\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\ndeclare global {\n  namespace jest {\n    interface Matchers<R> {\n      toBeSimilarTo(comparedTo: string, expectedDistance: number): R;\n    }\n  }\n}\nexpect.extend({\n  toBeSimilarTo(received, comparedTo: string, expectedDistance: number) {\n    const message = () =>\n      [\n        `Received: ${JSON.stringify(received)}`,\n        `Expected: ${JSON.stringify(comparedTo)}`,\n        `Expected distance: ${expectedDistance}`,\n        `Received distance: ${actualDistance}`,\n      ].join('\\n');\n\n    const actualDistance = distance(received, comparedTo);\n    if (actualDistance < expectedDistance) {\n      return {\n        message,\n        pass: true,\n      };\n    }\n\n    return {\n      message,\n      pass: false,\n    };\n  },\n});\n\nit(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\nit(`ChatCompletionStream works`, async function () {\n  const chunks: OpenAI.Chat.ChatCompletionChunk[] = [];\n  const contents: [string, string][] = [];\n  const messages: OpenAI.Chat.ChatCompletionMessageParam[] = [];\n  const chatCompletions: OpenAI.Chat.ChatCompletion[] = [];\n  let finalContent: string | undefined;\n  let finalMessage: OpenAI.Chat.ChatCompletionMessageParam | undefined;\n  let finalChatCompletion: OpenAI.Chat.ChatCompletion | undefined;\n\n  const stream = client.chat.completions\n    .stream({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .on('chunk', (chunk) => chunks.push(chunk))\n    .on('content', (delta, snapshot) => contents.push([delta, snapshot]))\n    .on('message', (message) => messages.push(message))\n    .on('chatCompletion', (completion) => chatCompletions.push(completion))\n    .on('finalContent', (content) => (finalContent = content))\n    .on('finalMessage', (message) => (finalMessage = message))\n    .on('finalChatCompletion', (completion) => (finalChatCompletion = completion));\n  const content = await stream.finalContent();\n\n  expect(content).toBeSimilarTo('This is a test', 10);\n  expect(chunks.length).toBeGreaterThan(0);\n  expect(contents.length).toBeGreaterThan(0);\n  for (const chunk of chunks) {\n    expect(chunk.id).toEqual(finalChatCompletion?.id);\n    expect(chunk.created).toEqual(finalChatCompletion?.created);\n    expect(chunk.model).toEqual(finalChatCompletion?.model);\n  }\n  expect(finalContent).toEqual(content);\n  expect(contents.at(-1)?.[1]).toEqual(content);\n  expect(finalMessage?.content).toEqual(content);\n  expect(finalChatCompletion?.choices?.[0]?.message.content).toEqual(content);\n  expect(messages).toEqual([finalMessage]);\n  expect(chatCompletions).toEqual([finalChatCompletion]);\n  expect(await stream.finalContent()).toEqual(content);\n  expect(await stream.finalMessage()).toEqual(finalMessage);\n  expect(await stream.finalChatCompletion()).toEqual(finalChatCompletion);\n});\n\nit(`aborting ChatCompletionStream works`, async function () {\n  const chunks: OpenAI.Chat.ChatCompletionChunk[] = [];\n  const contents: [string, string][] = [];\n  const messages: OpenAI.Chat.ChatCompletionMessageParam[] = [];\n  const chatCompletions: OpenAI.Chat.ChatCompletion[] = [];\n  let finalContent: string | undefined;\n  let finalMessage: OpenAI.Chat.ChatCompletionMessageParam | undefined;\n  let finalChatCompletion: OpenAI.Chat.ChatCompletion | undefined;\n  let emittedError: any;\n  let caughtError: any;\n  const controller = new AbortController();\n  const stream = client.chat.completions\n    .stream(\n      {\n        model: 'gpt-4',\n        messages: [{ role: 'user', content: 'Say this is a test' }],\n      },\n      { signal: controller.signal },\n    )\n    .on('error', (e) => (emittedError = e))\n    .on('chunk', (chunk) => chunks.push(chunk))\n    .on('content', (delta, snapshot) => {\n      contents.push([delta, snapshot]);\n      controller.abort();\n    })\n    .on('message', (message) => messages.push(message))\n    .on('chatCompletion', (completion) => chatCompletions.push(completion))\n    .on('finalContent', (content) => (finalContent = content))\n    .on('finalMessage', (message) => (finalMessage = message))\n    .on('finalChatCompletion', (completion) => (finalChatCompletion = completion));\n  try {\n    await stream.finalContent();\n  } catch (error) {\n    caughtError = error;\n  }\n  expect(caughtError).toBeInstanceOf(APIUserAbortError);\n  expect(finalContent).toBeUndefined();\n  expect(finalMessage).toBeUndefined();\n  expect(finalChatCompletion).toBeUndefined();\n  expect(chatCompletions).toEqual([]);\n  expect(chunks.length).toBeGreaterThan(0);\n  expect(contents.length).toBeGreaterThan(0);\n});\n\nit('handles builtinFile', async function () {\n  const file = await fetch(url)\n    .then((x) => x.arrayBuffer())\n    .then(\n      (x) =>\n        new File(\n          [\n            // @ts-ignore array buffer can't be passed to File at the type-level\n            x,\n          ],\n          filename,\n        ),\n    );\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit('handles fs.ReadStream', async function () {\n  const result = await client.audio.transcriptions.create({\n    file: fs.createReadStream('sample1.mp3'),\n    model,\n  });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe('toFile', () => {\n  it('handles form-data Blob', async function () {\n    const result = await client.files.create({\n      file: await toFile(new FormDataBlob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  if (typeof Blob !== 'undefined') {\n    it('handles builtin Blob', async function () {\n      const result = await client.files.create({\n        file: await toFile(new Blob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n        purpose: 'fine-tune',\n      });\n      expect(result.filename).toEqual('finetune.jsonl');\n    });\n  }\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles formdata-node File', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      .then((x) => toFile(new FormDataFile([x], filename)));\n\n    expect(file.name).toEqual(filename);\n  \n    const params: TranscriptionCreateParams = { file, model };\n  \n    const result = await client.audio.transcriptions.create(params);\n    expect(result.text).toBeSimilarTo(correctAnswer, 12);\n  });\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-auto/tsconfig.json",
    "content": "{\n  \"include\": [\"tests/*\", \"moduleResolution/node/*\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2015\",\n    \"lib\": [\"ES2015\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"commonjs\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"node\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": false\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-auto/tsconfig.nodenext.json",
    "content": "{\n  \"include\": [\"tests/*\", \"moduleResolution/nodenext/*\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2015\",\n    \"lib\": [\"ES2015\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"commonjs\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"NodeNext\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": false\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-web/jest.config.cjs",
    "content": "/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = {\n  preset: 'ts-jest',\n  testEnvironment: 'node',\n  testMatch: ['<rootDir>/tests/*.ts'],\n  watchPathIgnorePatterns: ['<rootDir>/node_modules/'],\n  verbose: false,\n  testTimeout: 60000,\n};\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-web/package.json",
    "content": "{\n  \"name\": \"node-ts-cjs-web\",\n  \"version\": \"0.0.1\",\n  \"main\": \"index.js\",\n  \"private\": true,\n  \"scripts\": {\n    \"tsc\": \"tsc && tsc -p tsconfig.nodenext.json\",\n    \"test\": \"jest\"\n  },\n  \"dependencies\": {\n    \"formdata-node\": \"^4.4.1\",\n    \"tsconfig-paths\": \"^4.0.0\"\n  },\n  \"devDependencies\": {\n    \"jest-fixed-jsdom\": \"^0.0.10\",\n    \"@types/node\": \"^18.0.0\",\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"jest\": \"^29.5.0\",\n    \"ts-jest\": \"^29.1.0\",\n    \"typescript\": \"4.7.4\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-web/tests/test-jsdom.ts",
    "content": "/**\n * @jest-environment jest-fixed-jsdom\n */\nimport OpenAI, { toFile } from 'openai';\nimport { distance } from 'fastest-levenshtein';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI({ apiKey: process.env['OPENAI_API_KEY'], dangerouslyAllowBrowser: true });\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\ndeclare global {\n  namespace jest {\n    interface Matchers<R> {\n      toBeSimilarTo(comparedTo: string, expectedDistance: number): R;\n    }\n  }\n}\nexpect.extend({\n  toBeSimilarTo(received, comparedTo: string, expectedDistance: number) {\n    const message = () =>\n      [\n        `Received: ${JSON.stringify(received)}`,\n        `Expected: ${JSON.stringify(comparedTo)}`,\n        `Expected distance: ${expectedDistance}`,\n        `Received distance: ${actualDistance}`,\n      ].join('\\n');\n\n    const actualDistance = distance(received, comparedTo);\n    if (actualDistance < expectedDistance) {\n      return {\n        message,\n        pass: true,\n      };\n    }\n\n    return {\n      message,\n      pass: false,\n    };\n  },\n});\n\ntest(`basic request works`, async function () {\n  const completion = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n  });\n  expect(completion.choices[0]?.message?.content).toBeSimilarTo('This is a test', 10);\n});\n\n// response bodies aren't working with the chosen polyfills\nit.skip(`raw response`, async function () {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  // test that we can use web Response API\n  const { body } = response;\n  if (!body) throw new Error('expected response.body to be defined');\n\n  const reader = body.getReader();\n  const chunks: Uint8Array[] = [];\n  let result;\n  do {\n    result = await reader.read();\n    if (!result.done) chunks.push(result.value);\n  } while (!result.done);\n\n  reader.releaseLock();\n\n  let offset = 0;\n  const merged = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n  for (const chunk of chunks) {\n    merged.set(chunk, offset);\n    offset += chunk.length;\n  }\n\n  const json: ChatCompletion = JSON.parse(new TextDecoder().decode(merged));\n  expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);\n});\n\n// response bodies aren't working with the chosen polyfills\nit.skip(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\n// file uploads aren't working with the chosen polyfills\nit.skip('handles builtinFile', async function () {\n  const file = await fetch(url)\n    .then((x) => x.arrayBuffer())\n    .then((x) => new File([x], filename));\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit.skip('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe.skip('toFile', () => {\n  it('handles builtin Blob', async function () {\n    const result = await client.files.create({\n      file: await toFile(new Blob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-web/tests/test-node.ts",
    "content": "import OpenAI, { toFile } from 'openai';\nimport { distance } from 'fastest-levenshtein';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI();\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\ndeclare global {\n  namespace jest {\n    interface Matchers<R> {\n      toBeSimilarTo(comparedTo: string, expectedDistance: number): R;\n    }\n  }\n}\nexpect.extend({\n  toBeSimilarTo(received, comparedTo: string, expectedDistance: number) {\n    const message = () =>\n      [\n        `Received: ${JSON.stringify(received)}`,\n        `Expected: ${JSON.stringify(comparedTo)}`,\n        `Expected distance: ${expectedDistance}`,\n        `Received distance: ${actualDistance}`,\n      ].join('\\n');\n\n    const actualDistance = distance(received, comparedTo);\n    if (actualDistance < expectedDistance) {\n      return {\n        message,\n        pass: true,\n      };\n    }\n\n    return {\n      message,\n      pass: false,\n    };\n  },\n});\n\nit(`raw response`, async function () {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  // test that we can use web Response API\n  const { body } = response;\n  if (!body) throw new Error('expected response.body to be defined');\n\n  const reader = body.getReader();\n  const chunks: Uint8Array[] = [];\n  let result;\n  do {\n    result = await reader.read();\n    if (!result.done) chunks.push(result.value);\n  } while (!result.done);\n\n  reader.releaseLock();\n\n  let offset = 0;\n  const merged = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n  for (const chunk of chunks) {\n    merged.set(chunk, offset);\n    offset += chunk.length;\n  }\n\n  const json: ChatCompletion = JSON.parse(new TextDecoder().decode(merged));\n  expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);\n});\n\nit(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\nif (typeof File !== 'undefined') {\n  it('handles builtinFile', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      // @ts-ignore\n      .then((x) => new File([x], filename));\n\n    const result = await client.audio.transcriptions.create({ file, model });\n    expect(result.text).toBeSimilarTo(correctAnswer, 12);\n  });\n}\n\nit('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe('toFile', () => {\n  if (typeof Blob !== 'undefined') {\n    it('handles builtin Blob', async function () {\n      const result = await client.files.create({\n        file: await toFile(new Blob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n        purpose: 'fine-tune',\n      });\n      expect(result.filename).toEqual('finetune.jsonl');\n    });\n  }\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-web/tsconfig.json",
    "content": "{\n  \"include\": [\"tests/*.ts\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2022\",\n    \"lib\": [\"ES2022\", \"DOM\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"commonjs\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"node\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": true\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-web/tsconfig.nodenext.json",
    "content": "{\n  \"include\": [\"tests/*.ts\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2022\",\n    \"lib\": [\"ES2022\", \"DOM\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"commonjs\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"NodeNext\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": true\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-cjs-web/types-test.ts",
    "content": "import OpenAI from 'openai';\n\nasync function typeTests(client: OpenAI) {\n  const response = await client.chat.completions.create({ model: 'gpt-4o', messages: [] }).asResponse();\n  const url: string = response.url;\n}\n\nexport {};\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm/iitm.js",
    "content": "import {register} from 'node:module'\nregister('import-in-the-middle/hook.mjs', import.meta.url)"
  },
  {
    "path": "ecosystem-tests/node-ts-esm/jest.config.cjs",
    "content": "/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = {\n  extensionsToTreatAsEsm: ['.ts'],\n  moduleNameMapper: {\n    '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n  },\n  transform: {\n    // '^.+\\\\.[tj]sx?$' to process js/ts with `ts-jest`\n    // '^.+\\\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`\n    '^.+\\\\.tsx?$': [\n      'ts-jest',\n      {\n        useESM: true,\n        diagnostics: false,\n      },\n    ],\n  },\n  testEnvironment: 'node',\n  testMatch: ['<rootDir>/tests/*.ts'],\n  watchPathIgnorePatterns: ['<rootDir>/node_modules/'],\n  verbose: false,\n  testTimeout: 60000,\n};\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm/package.json",
    "content": "{\n  \"name\": \"node-ts-esm\",\n  \"version\": \"0.0.1\",\n  \"main\": \"index.js\",\n  \"type\": \"module\",\n  \"private\": true,\n  \"scripts\": {\n    \"tsc\": \"tsc && tsc -p tsconfig.noderesolution.json\",\n    \"test\": \"node --import=./iitm.js --experimental-vm-modules node_modules/jest/bin/jest.js\"\n  },\n  \"dependencies\": {\n    \"formdata-node\": \"^5.0.1\",\n    \"import-in-the-middle\": \"^1.11.2\"\n  },\n  \"devDependencies\": {\n    \"@types/node\": \"^20.3.1\",\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"jest\": \"^29.5.0\",\n    \"ts-jest\": \"^29.1.0\",\n    \"ts-node\": \"^10.9.1\",\n    \"typescript\": \"4.7.4\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm/tests/test-esnext.ts",
    "content": "import OpenAI from 'openai';\nimport { distance } from 'fastest-levenshtein';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\n// The tests in this file don't typecheck with \"moduleResolution\": \"node\"\n\nasync function typeTests(client: OpenAI) {\n  const response = await client.chat.completions.create({ model: 'gpt-4o', messages: [] }).asResponse();\n  const url: string = response.url;\n}\n\nconst client = new OpenAI();\n\ndeclare global {\n  namespace jest {\n    interface Matchers<R> {\n      toBeSimilarTo(comparedTo: string, expectedDistance: number): R;\n    }\n  }\n}\nexpect.extend({\n  toBeSimilarTo(received, comparedTo: string, expectedDistance: number) {\n    const message = () =>\n      [\n        `Received: ${JSON.stringify(received)}`,\n        `Expected: ${JSON.stringify(comparedTo)}`,\n        `Expected distance: ${expectedDistance}`,\n        `Received distance: ${actualDistance}`,\n      ].join('\\n');\n\n    const actualDistance = distance(received, comparedTo);\n    if (actualDistance < expectedDistance) {\n      return {\n        message,\n        pass: true,\n      };\n    }\n\n    return {\n      message,\n      pass: false,\n    };\n  },\n});\n\nit(`raw response`, async function () {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  const chunks: string[] = [];\n  if (!response.body) throw new Error(`expected response.body to be defined`);\n\n  const decoder = new TextDecoder();\n\n  for await (const chunk of response.body) {\n    chunks.push(decoder.decode(chunk));\n  }\n\n  const json: ChatCompletion = JSON.parse(chunks.join(''));\n  expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm/tests/test.ts",
    "content": "import OpenAI, { toFile } from 'openai';\nimport { TranscriptionCreateParams } from 'openai/resources/audio/transcriptions';\nimport { File as FormDataFile, Blob as FormDataBlob } from 'formdata-node';\nimport * as fs from 'fs';\nimport { distance } from 'fastest-levenshtein';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI();\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\ndeclare global {\n  namespace jest {\n    interface Matchers<R> {\n      toBeSimilarTo(comparedTo: string, expectedDistance: number): R;\n    }\n  }\n}\nexpect.extend({\n  toBeSimilarTo(received, comparedTo: string, expectedDistance: number) {\n    const message = () =>\n      [\n        `Received: ${JSON.stringify(received)}`,\n        `Expected: ${JSON.stringify(comparedTo)}`,\n        `Expected distance: ${expectedDistance}`,\n        `Received distance: ${actualDistance}`,\n      ].join('\\n');\n\n    const actualDistance = distance(received, comparedTo);\n    if (actualDistance < expectedDistance) {\n      return {\n        message,\n        pass: true,\n      };\n    }\n\n    return {\n      message,\n      pass: false,\n    };\n  },\n});\n\nit(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\nif (typeof File !== 'undefined') {\n  it('handles builtinFile', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      .then(\n        (x) =>\n          new File(\n            [\n              // @ts-ignore array buffer can't be passed to File at the type-level with certain tsconfigs\n              x,\n            ],\n            filename,\n          ),\n      );\n\n    const result = await client.audio.transcriptions.create({ file, model });\n    expect(result.text).toBeSimilarTo(correctAnswer, 12);\n  });\n}\n\nit('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit('handles fs.ReadStream', async function () {\n  const result = await client.audio.transcriptions.create({\n    file: fs.createReadStream('sample1.mp3'),\n    model,\n  });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe('toFile', () => {\n  it('handles form-data Blob', async function () {\n    const result = await client.files.create({\n      file: await toFile(new FormDataBlob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  if (typeof Blob !== 'undefined') {\n    it('handles builtin Blob', async function () {\n      const result = await client.files.create({\n        file: await toFile(new Blob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n        purpose: 'fine-tune',\n      });\n      expect(result.filename).toEqual('finetune.jsonl');\n    });\n  }\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n\n  it('handles formdata-node File', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      .then((x) => toFile(new FormDataFile([x], filename)));\n\n    expect(file.name).toEqual(filename);\n  \n    const params: TranscriptionCreateParams = { file, model };\n  \n    const result = await client.audio.transcriptions.create(params);\n    expect(result.text).toBeSimilarTo(correctAnswer, 12);\n  });\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm/tsconfig.json",
    "content": "{\n  \"include\": [\"tests/*.ts\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2022\",\n    \"lib\": [\"ES2022\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"ESNext\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"NodeNext\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": true\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm/tsconfig.noderesolution.json",
    "content": "{\n  \"include\": [\"tests/*.ts\"],\n  \"exclude\": [\"tests/*-esnext.ts\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2022\",\n    \"lib\": [\"ES2022\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"ESNext\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"node\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": true\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-auto/esnext-type-tests.ts",
    "content": "import OpenAI from 'openai';\n\nasync function typeTests(client: OpenAI) {\n  const response = await client.chat.completions.create({ model: 'gpt-4o', messages: [] }).asResponse();\n  const url: string = response.url;\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-auto/jest.config.cjs",
    "content": "/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = {\n  extensionsToTreatAsEsm: ['.ts'],\n  moduleNameMapper: {\n    '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n  },\n  transform: {\n    // '^.+\\\\.[tj]sx?$' to process js/ts with `ts-jest`\n    // '^.+\\\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`\n    '^.+\\\\.tsx?$': [\n      'ts-jest',\n      {\n        useESM: true,\n        diagnostics: false,\n      },\n    ],\n  },\n  testEnvironment: 'node',\n  testMatch: ['<rootDir>/tests/*.ts'],\n  watchPathIgnorePatterns: ['<rootDir>/node_modules/'],\n  verbose: false,\n  testTimeout: 60000,\n};\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-auto/package.json",
    "content": "{\n  \"name\": \"node-ts-esm-auto\",\n  \"version\": \"0.0.1\",\n  \"main\": \"index.js\",\n  \"type\": \"module\",\n  \"private\": true,\n  \"scripts\": {\n    \"tsc\": \"tsc\",\n    \"test\": \"node --experimental-vm-modules node_modules/jest/bin/jest.js\"\n  },\n  \"dependencies\": {\n    \"formdata-node\": \"^5.0.1\"\n  },\n  \"devDependencies\": {\n    \"@types/node\": \"^20.3.1\",\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"jest\": \"^29.5.0\",\n    \"ts-jest\": \"^29.1.0\",\n    \"ts-node\": \"^10.9.1\",\n    \"typescript\": \"4.7.4\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-auto/tests/test.ts",
    "content": "import OpenAI, { toFile } from 'openai';\nimport { TranscriptionCreateParams } from 'openai/resources/audio/transcriptions';\nimport { File as FormDataFile, Blob as FormDataBlob } from 'formdata-node';\nimport * as fs from 'fs';\nimport { distance } from 'fastest-levenshtein';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI();\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\ndeclare global {\n  namespace jest {\n    interface Matchers<R> {\n      toBeSimilarTo(comparedTo: string, expectedDistance: number): R;\n    }\n  }\n}\nexpect.extend({\n  toBeSimilarTo(received, comparedTo: string, expectedDistance: number) {\n    const message = () =>\n      [\n        `Received: ${JSON.stringify(received)}`,\n        `Expected: ${JSON.stringify(comparedTo)}`,\n        `Expected distance: ${expectedDistance}`,\n        `Received distance: ${actualDistance}`,\n      ].join('\\n');\n\n    const actualDistance = distance(received, comparedTo);\n    if (actualDistance < expectedDistance) {\n      return {\n        message,\n        pass: true,\n      };\n    }\n\n    return {\n      message,\n      pass: false,\n    };\n  },\n});\n\nit(`raw response`, async function () {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  const decoder = new TextDecoder();\n  const chunks: string[] = [];\n  for await (const chunk of response.body!) {\n    chunks.push(decoder.decode(chunk));\n  }\n\n  const json: ChatCompletion = JSON.parse(chunks.join(''));\n  expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);\n});\n\nit(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\nit('handles builtinFile', async function () {\n  const file = await fetch(url)\n    .then((x) => x.arrayBuffer())\n    .then(\n      (x) =>\n        new File(\n          [\n            // @ts-ignore array buffer can't be passed to File at the type-level\n            x,\n          ],\n          filename,\n        ),\n    );\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit('handles fs.ReadStream', async function () {\n  const result = await client.audio.transcriptions.create({\n    file: fs.createReadStream('sample1.mp3'),\n    model,\n  });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe('toFile', () => {\n  it('handles form-data Blob', async function () {\n    const result = await client.files.create({\n      file: await toFile(new FormDataBlob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  if (typeof Blob !== 'undefined') {\n    it('handles builtin Blob', async function () {\n      const result = await client.files.create({\n        file: await toFile(new Blob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n        purpose: 'fine-tune',\n      });\n      expect(result.filename).toEqual('finetune.jsonl');\n    });\n  }\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n\n  it('handles formdata-node File', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      .then((x) => toFile(new FormDataFile([x], filename)));\n\n    expect(file.name).toEqual(filename);\n  \n    const params: TranscriptionCreateParams = { file, model };\n  \n    const result = await client.audio.transcriptions.create(params);\n    expect(result.text).toBeSimilarTo(correctAnswer, 12);\n  });\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-auto/tsconfig.json",
    "content": "{\n  \"include\": [\"tests/*.ts\", \"*.ts\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2022\",\n    \"lib\": [\"ES2022\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"ESNext\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"NodeNext\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": true\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-web/jest.config.cjs",
    "content": "/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = {\n  extensionsToTreatAsEsm: ['.ts'],\n  moduleNameMapper: {\n    '^(\\\\.{1,2}/.*)\\\\.js$': '$1',\n  },\n  transform: {\n    // '^.+\\\\.[tj]sx?$' to process js/ts with `ts-jest`\n    // '^.+\\\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`\n    '^.+\\\\.tsx?$': [\n      'ts-jest',\n      {\n        useESM: true,\n        diagnostics: false,\n      },\n    ],\n  },\n  testEnvironment: 'node',\n  testMatch: ['<rootDir>/tests/*.ts'],\n  watchPathIgnorePatterns: ['<rootDir>/node_modules/'],\n  verbose: false,\n  testTimeout: 60000,\n};\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-web/package.json",
    "content": "{\n  \"name\": \"node-ts-esm-web\",\n  \"version\": \"0.0.1\",\n  \"main\": \"index.js\",\n  \"type\": \"module\",\n  \"private\": true,\n  \"scripts\": {\n    \"tsc\": \"tsc && tsc -p tsconfig.noderesolution.json\",\n    \"test\": \"node --experimental-vm-modules node_modules/jest/bin/jest.js\"\n  },\n  \"dependencies\": {\n    \"formdata-node\": \"^5.0.1\"\n  },\n  \"devDependencies\": {\n    \"@types/node\": \"^20.3.1\",\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"jest\": \"^29.5.0\",\n    \"ts-jest\": \"^29.1.0\",\n    \"ts-node\": \"^10.9.1\",\n    \"typescript\": \"4.7.4\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-web/tests/test.ts",
    "content": "import OpenAI, { toFile } from 'openai';\nimport { distance } from 'fastest-levenshtein';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI();\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\ndeclare global {\n  namespace jest {\n    interface Matchers<R> {\n      toBeSimilarTo(comparedTo: string, expectedDistance: number): R;\n    }\n  }\n}\nexpect.extend({\n  toBeSimilarTo(received, comparedTo: string, expectedDistance: number) {\n    const message = () =>\n      [\n        `Received: ${JSON.stringify(received)}`,\n        `Expected: ${JSON.stringify(comparedTo)}`,\n        `Expected distance: ${expectedDistance}`,\n        `Received distance: ${actualDistance}`,\n      ].join('\\n');\n\n    const actualDistance = distance(received, comparedTo);\n    if (actualDistance < expectedDistance) {\n      return {\n        message,\n        pass: true,\n      };\n    }\n\n    return {\n      message,\n      pass: false,\n    };\n  },\n});\n\nit(`raw response`, async function () {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  // test that we can use web Response API\n  const { body } = response;\n  if (!body) throw new Error('expected response.body to be defined');\n\n  const reader = body.getReader();\n  const chunks: Uint8Array[] = [];\n  let result;\n  do {\n    result = await reader.read();\n    if (!result.done) chunks.push(result.value);\n  } while (!result.done);\n\n  reader.releaseLock();\n\n  let offset = 0;\n  const merged = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n  for (const chunk of chunks) {\n    merged.set(chunk, offset);\n    offset += chunk.length;\n  }\n\n  const json: ChatCompletion = JSON.parse(new TextDecoder().decode(merged));\n  expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);\n});\n\nit(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\nif (typeof File !== 'undefined') {\n  it('handles builtinFile', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      .then(\n        (x) =>\n          new File(\n            [\n              // @ts-ignore array buffer can't be passed to File at the type-level\n              x,\n            ],\n            filename,\n          ),\n      );\n\n    const result = await client.audio.transcriptions.create({ file, model });\n    expect(result.text).toBeSimilarTo(correctAnswer, 12);\n  });\n}\n\nit('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe('toFile', () => {\n  if (typeof Blob !== 'undefined') {\n    it('handles builtin Blob', async function () {\n      const result = await client.files.create({\n        file: await toFile(new Blob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n        purpose: 'fine-tune',\n      });\n      expect(result.filename).toEqual('finetune.jsonl');\n    });\n  }\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-web/tsconfig.json",
    "content": "{\n  \"include\": [\"tests/*.ts\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2022\",\n    \"lib\": [\"ES2022\", \"DOM\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"ESNext\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"NodeNext\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": true\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-web/tsconfig.noderesolution.json",
    "content": "{\n  \"include\": [\"tests/*.ts\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2022\",\n    \"lib\": [\"ES2022\", \"DOM\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"ESNext\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"node\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": true\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts-esm-web/types-test.ts",
    "content": "import OpenAI from 'openai';\n\nasync function typeTests(client: OpenAI) {\n  const response = await client.chat.completions.create({ model: 'gpt-4o', messages: [] }).asResponse();\n  const url: string = response.url;\n}\n\nexport {};\n"
  },
  {
    "path": "ecosystem-tests/node-ts4.5-jest28/jest.config.cjs",
    "content": "/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = {\n  preset: 'ts-jest',\n  testEnvironment: 'node',\n  testMatch: ['<rootDir>/tests/*.ts'],\n  watchPathIgnorePatterns: ['<rootDir>/node_modules/'],\n  verbose: false,\n  testTimeout: 60000,\n};\n"
  },
  {
    "path": "ecosystem-tests/node-ts4.5-jest28/package.json",
    "content": "{\n  \"name\": \"node-ts4.5-jest27\",\n  \"version\": \"0.0.1\",\n  \"main\": \"index.js\",\n  \"private\": true,\n  \"scripts\": {\n    \"tsc\": \"tsc\",\n    \"test\": \"jest\"\n  },\n  \"dependencies\": {\n    \"formdata-node\": \"^4.4.1\",\n    \"tsconfig-paths\": \"^4.0.0\"\n  },\n  \"devDependencies\": {\n    \"@types/node\": \"20.11.20\",\n    \"@types/jest\": \"27.5.2\",\n    \"@types/ws\": \"^8.5.4\",\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"jest\": \"28.1.3\",\n    \"ts-jest\": \"^28.0.0\",\n    \"typescript\": \"4.5.5\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/node-ts4.5-jest28/tests/test.ts",
    "content": "import OpenAI, { toFile } from 'openai';\nimport { TranscriptionCreateParams } from 'openai/resources/audio/transcriptions';\nimport { File as FormDataFile, Blob as FormDataBlob } from 'formdata-node';\nimport * as fs from 'fs';\nimport { distance } from 'fastest-levenshtein';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst client = new OpenAI();\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\ndeclare global {\n  namespace jest {\n    interface Matchers<R> {\n      toBeSimilarTo(comparedTo: string, expectedDistance: number): R;\n    }\n  }\n}\nexpect.extend({\n  toBeSimilarTo(received, comparedTo: string, expectedDistance: number) {\n    const message = () =>\n      [\n        `Received: ${JSON.stringify(received)}`,\n        `Expected: ${JSON.stringify(comparedTo)}`,\n        `Expected distance: ${expectedDistance}`,\n        `Received distance: ${actualDistance}`,\n      ].join('\\n');\n\n    const actualDistance = distance(received, comparedTo);\n    if (actualDistance < expectedDistance) {\n      return {\n        message,\n        pass: true,\n      };\n    }\n\n    return {\n      message,\n      pass: false,\n    };\n  },\n});\n\nit(`raw response`, async function () {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  const decoder = new TextDecoder();\n  const chunks: string[] = [];\n  for await (const chunk of response.body!) {\n    chunks.push(decoder.decode(chunk));\n  }\n\n  const json: ChatCompletion = JSON.parse(chunks.join(''));\n  expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);\n});\n\nit(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\nit('handles builtinFile', async function () {\n  const file = await fetch(url)\n    .then((x) => x.arrayBuffer())\n    .then(\n      (x) =>\n        new File(\n          [\n            // @ts-ignore array buffer can't be passed to File at the type-level\n            x,\n          ],\n          filename,\n        ),\n    );\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nit('handles fs.ReadStream', async function () {\n  const result = await client.audio.transcriptions.create({\n    file: fs.createReadStream('sample1.mp3'),\n    model,\n  });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe('toFile', () => {\n  it('handles form-data Blob', async function () {\n    const result = await client.files.create({\n      file: await toFile(new FormDataBlob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  if (typeof Blob !== 'undefined') {\n    it('handles builtin Blob', async function () {\n      const result = await client.files.create({\n        file: await toFile(new Blob([new TextEncoder().encode(fineTune)]), 'finetune.jsonl'),\n        purpose: 'fine-tune',\n      });\n      expect(result.filename).toEqual('finetune.jsonl');\n    });\n  }\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n\n  it('handles formdata-node File', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      .then((x) => toFile(new FormDataFile([x], filename)));\n\n    expect(file.name).toEqual(filename);\n  \n    const params: TranscriptionCreateParams = { file, model };\n  \n    const result = await client.audio.transcriptions.create(params);\n    expect(result.text).toBeSimilarTo(correctAnswer, 12);\n  });\n});\n"
  },
  {
    "path": "ecosystem-tests/node-ts4.5-jest28/tsconfig.json",
    "content": "{\n  \"include\": [\"tests/*.ts\"],\n\n  \"compilerOptions\": {\n    /* Visit https://aka.ms/tsconfig.json to read more about this file */\n    /* Projects */\n    \"incremental\": true,\n\n    /* Language and Environment */\n    \"target\": \"ES2015\",\n    \"lib\": [\"ES2015\"],\n    \"jsx\": \"react\",\n\n    /* Modules */\n    \"module\": \"commonjs\",\n    \"rootDir\": \"./\",\n    \"moduleResolution\": \"node\",\n    \"baseUrl\": \"./\",\n    \"paths\": {\n      \"~/*\": [\"*\"]\n    },\n    \"resolveJsonModule\": true,\n    \"composite\": true,\n\n    /* Emit */\n    \"outDir\": \"node_modules\",\n    \"noEmit\": true,\n\n    /* Interop Constraints */\n    \"isolatedModules\": true,\n    \"allowSyntheticDefaultImports\": true,\n    /* \"esModuleInterop\": true, */\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"checkJs\": true,\n\n    /* Experimental Features */\n    \"experimentalDecorators\": true,\n\n    /* Type Checking */\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"alwaysStrict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"skipLibCheck\": false\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/proxy.ts",
    "content": "import { createServer } from 'http';\nimport { connect } from 'net';\n\nasync function startProxy() {\n  const proxy = createServer((_req, res) => {\n    res.end();\n  });\n\n  proxy.on('connect', (req, clientSocket, head) => {\n    const serverSocket = connect(443, 'api.openai.com', () => {\n      clientSocket.write(\n        'HTTP/1.1 200 Connection Established\\r\\n' + 'Proxy-agent: Node.js-Proxy\\r\\n' + '\\r\\n',\n      );\n      serverSocket.write(head);\n      serverSocket.pipe(clientSocket);\n      clientSocket.pipe(serverSocket);\n    });\n  });\n\n  await new Promise<void>((resolve) => proxy.listen(0, '127.0.0.1', resolve));\n\n  console.log(proxy.address()!.toString());\n\n  return () => {\n    proxy.close();\n  };\n}\n"
  },
  {
    "path": "ecosystem-tests/ts-browser-webpack/.babelrc",
    "content": "{\n  \"presets\": [\n    \"@babel/preset-env\", // Automatically determines the Babel plugins and polyfills you need based on your target environments\n    \"@babel/preset-typescript\" // If you're using TypeScript, this preset will enable TypeScript transformation\n  ],\n  \"plugins\": []\n}\n"
  },
  {
    "path": "ecosystem-tests/ts-browser-webpack/.gitignore",
    "content": "/node_modules\n/dist\n"
  },
  {
    "path": "ecosystem-tests/ts-browser-webpack/package.json",
    "content": "{\n  \"name\": \"ts-browser-webpack\",\n  \"version\": \"0.0.1\",\n  \"private\": true,\n  \"description\": \"ts-browser-webpack\",\n  \"scripts\": {\n    \"tsc\": \"tsc\",\n    \"serve\": \"webpack serve\",\n    \"build\": \"webpack\",\n    \"test\": \"ts-node src/test.ts\",\n    \"test:ci\": \"start-server-and-test serve http://localhost:8080 test\"\n  },\n  \"devDependencies\": {\n    \"@babel/core\": \"^7.21.0\",\n    \"@babel/preset-env\": \"^7.21.0\",\n    \"@babel/preset-typescript\": \"^7.21.0\",\n    \"babel-loader\": \"^9.1.2\",\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"html-webpack-plugin\": \"^5.5.3\",\n    \"puppeteer\": \"^23.4.0\",\n    \"start-server-and-test\": \"^2.0.0\",\n    \"ts-loader\": \"^9.4.3\",\n    \"ts-node\": \"^10.9.1\",\n    \"typescript\": \"^4.7.4\",\n    \"webpack\": \"^5.87.0\",\n    \"webpack-cli\": \"^5.0.2\",\n    \"webpack-dev-server\": \"^4.15.1\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/ts-browser-webpack/public/index.html",
    "content": "<!DOCTYPE html>\n<html>\n  <head>\n    <meta charset=\"utf-8\" />\n    <title>Package in the Browser</title>\n  </head>\n  <body>\n    <div id=\"running\">Running tests...</div>\n  </body>\n</html>\n"
  },
  {
    "path": "ecosystem-tests/ts-browser-webpack/src/index.ts",
    "content": "import OpenAI, { toFile } from 'openai';\nimport { distance } from 'fastest-levenshtein';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\ntype TestCase = {\n  path: string[];\n  run: () => any;\n  timeout?: number;\n};\n\nconst tests: TestCase[] = [];\n\ntype TestResult = { path: string[]; passed: boolean; error?: string };\n\nasync function runTests() {\n  const results: TestResult[] = [];\n  function displayResults() {\n    let pre = document.getElementById('results');\n    if (!pre) {\n      pre = document.createElement('pre');\n      pre.id = 'results';\n      document.body.appendChild(pre);\n    }\n    pre.innerText = JSON.stringify(results, null, 2);\n  }\n  for (const { path, run, timeout } of tests) {\n    console.log('running', ...path);\n    try {\n      await Promise.race([\n        run(),\n        new Promise((_, reject) =>\n          setTimeout(() => reject(new Error(`Test timed out after ${timeout} ms`)), timeout),\n        ),\n      ]);\n      console.log('passed ', ...path);\n      results.push({ path, passed: true });\n    } catch (error) {\n      console.log('error  ', ...path);\n      console.error(error);\n      results.push({ path, passed: false, error: error instanceof Error ? error.stack : String(error) });\n    }\n    displayResults();\n  }\n  const runningEl = document.getElementById('running');\n  if (runningEl) runningEl.remove();\n}\n\nconst testPath: string[] = [];\n\nfunction describe(description: string, handler: () => void) {\n  testPath.push(description);\n  try {\n    handler();\n  } finally {\n    testPath.pop();\n  }\n}\n\nfunction it(description: string, run: () => any, timeout = 60000) {\n  tests.push({ path: [...testPath, description], run, timeout });\n}\n\nfunction expect(received: any) {\n  return {\n    toEqual(expected: any): void {\n      if (!Object.is(received, expected)) {\n        throw new Error(\n          [`Received: ${JSON.stringify(received)}`, `Expected: ${JSON.stringify(expected)}`].join('\\n'),\n        );\n      }\n    },\n    toBeSimilarTo(comparedTo: string, expectedDistance: number) {\n      const actualDistance = distance(received, comparedTo);\n      if (actualDistance < expectedDistance) return;\n\n      throw new Error(\n        [\n          `Received: ${JSON.stringify(received)}`,\n          `Expected: ${JSON.stringify(comparedTo)}`,\n          `Expected distance: ${expectedDistance}`,\n          `Received distance: ${actualDistance}`,\n        ].join('\\n'),\n      );\n    },\n  };\n}\n\nconst url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\nconst filename = 'sample-1.mp3';\n\nconst correctAnswer =\n  'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\nconst model = 'whisper-1';\n\nconst params = new URLSearchParams(location.search);\n\nconst client = new OpenAI({ apiKey: params.get('apiKey') ?? undefined, dangerouslyAllowBrowser: true });\n\nasync function typeTests() {\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n  // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n  await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n}\n\nit(`raw response`, async function () {\n  const response = await client.chat.completions\n    .create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .asResponse();\n\n  // test that we can use web Response API\n  const { body } = response;\n  if (!body) throw new Error('expected response.body to be defined');\n\n  const reader = body.getReader();\n  const chunks: Uint8Array[] = [];\n  let result;\n  do {\n    result = await reader.read();\n    if (!result.done) chunks.push(result.value);\n  } while (!result.done);\n\n  reader.releaseLock();\n\n  let offset = 0;\n  const merged = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n  for (const chunk of chunks) {\n    merged.set(chunk, offset);\n    offset += chunk.length;\n  }\n\n  const json: ChatCompletion = JSON.parse(new TextDecoder().decode(merged));\n  expect(json.choices[0]?.message.content || '').toBeSimilarTo('This is a test', 10);\n});\n\nit(`streaming works`, async function () {\n  const stream = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  const chunks = [];\n  for await (const part of stream) {\n    chunks.push(part);\n  }\n  expect(chunks.map((c) => c.choices[0]?.delta.content || '').join('')).toBeSimilarTo('This is a test', 10);\n});\n\nif (typeof File !== 'undefined') {\n  it('handles builtinFile', async function () {\n    const file = await fetch(url)\n      .then((x) => x.arrayBuffer())\n      .then((x) => new File([x], filename));\n\n    const result = await client.audio.transcriptions.create({ file, model });\n    expect(result.text).toBeSimilarTo(correctAnswer, 12);\n  });\n}\n\nit('handles Response', async function () {\n  const file = await fetch(url);\n\n  const result = await client.audio.transcriptions.create({ file, model });\n  expect(result.text).toBeSimilarTo(correctAnswer, 12);\n});\n\nconst fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\ndescribe('toFile', () => {\n  if (typeof Blob !== 'undefined') {\n    it('handles builtin Blob', async function () {\n      const result = await client.files.create({\n        file: await toFile(\n          // @ts-ignore avoid DOM lib for testing purposes\n          new Blob([new TextEncoder().encode(fineTune)]),\n          'finetune.jsonl',\n        ),\n        purpose: 'fine-tune',\n      });\n      expect(result.filename).toEqual('finetune.jsonl');\n    });\n  }\n  it('handles Uint8Array', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles ArrayBuffer', async function () {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n  it('handles DataView', async function () {\n    const result = await client.files.create({\n      file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expect(result.filename).toEqual('finetune.jsonl');\n  });\n});\n\nrunTests();\n"
  },
  {
    "path": "ecosystem-tests/ts-browser-webpack/src/test.ts",
    "content": "import puppeteer from 'puppeteer';\n\n(async () => {\n  const browser = await puppeteer.launch({\n    args: ['--no-sandbox'],\n  });\n  let page;\n  try {\n    page = await browser.newPage();\n    function debugEvent(subj: string) {\n      return subj.padEnd('requestfailed'.length);\n    }\n    page\n      .on('console', (message) =>\n        console.error(\n          `${debugEvent('console')} ${message\n            .type()\n            .substr(0, 'warning'.length)\n            .toUpperCase()\n            .padEnd('warning'.length)} ${message.text()}`,\n        ),\n      )\n      .on('pageerror', ({ message }) => console.error(`${debugEvent('pageerror')} ${message}`))\n      .on('response', (response) =>\n        console.error(`${debugEvent('response')} ${response.status()} ${response.url()}`),\n      )\n      .on('requestfailed', (request) =>\n        console.error(`${debugEvent('requestfailed')} ${request.failure()?.errorText} ${request.url()}`),\n      );\n\n    const apiKey = process.env.OPENAI_API_KEY;\n\n    if (!apiKey) throw new Error('missing process.env.OPENAI_API_KEY');\n\n    // Navigate the page to a URL\n    await page.goto(`http://localhost:8080/index.html?apiKey=${apiKey}`);\n\n    await page.waitForSelector('#running', { timeout: 15000 });\n\n    let start = Date.now();\n    while ((await page.$('#running')) != null && Date.now() - start < 3 * 60000) {\n      await new Promise((r) => setTimeout(r, 1000));\n    }\n\n    let results;\n    const resultsEl = await page.$('#results');\n    if (resultsEl) {\n      const text = await page.evaluate((el) => el.textContent, resultsEl);\n      results = text ? JSON.parse(text) : undefined;\n    }\n\n    if (!Array.isArray(results)) {\n      throw new Error(`failed to get test results from page`);\n    }\n    const failed = results.filter((r) => !r.passed);\n    if (failed.length) {\n      throw new Error(\n        `${failed.length} of ${results.length} tests failed: ${JSON.stringify(failed, null, 2)}`,\n      );\n    }\n    console.log(`${results.length} tests passed!`);\n  } catch (error) {\n    if (page) {\n      try {\n        const html = await page.evaluate(() => document.body.innerHTML);\n        console.error(`\\n====================\\nBODY HTML\\n====================\\n\\n${html}\\n\\n`);\n      } catch (error) {\n        console.error(`failed to get body HTML for debugging`, error);\n      }\n    }\n    throw error;\n  } finally {\n    await browser.close();\n  }\n})();\n"
  },
  {
    "path": "ecosystem-tests/ts-browser-webpack/tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"module\": \"commonjs\",\n    \"strict\": true,\n    \"noImplicitReturns\": true,\n    \"removeComments\": true,\n    \"preserveConstEnums\": true,\n    \"sourceMap\": true,\n    \"declaration\": true,\n    \"skipLibCheck\": false,\n    \"target\": \"es2015\",\n    \"lib\": [\"es2017\", \"dom\"],\n    \"outDir\": \"dist\",\n    \"rootDir\": \"./\",\n    \"baseUrl\": \".\",\n    \"paths\": {\n      \"*\": [\"types/*\"]\n    }\n  },\n  \"include\": [\"src/**/*\"],\n  \"exclude\": [\"node_modules/*\"]\n}\n"
  },
  {
    "path": "ecosystem-tests/ts-browser-webpack/webpack.config.js",
    "content": "const path = require('path');\nconst HtmlWebpackPlugin = require('html-webpack-plugin');\n\nconst publicPath = path.resolve(__dirname, 'public');\nconst srcPath = path.resolve(__dirname, 'src');\nconst buildPath = path.resolve(__dirname, 'dist');\n\nmodule.exports = {\n  entry: path.join(srcPath, 'index.ts'),\n\n  mode: 'development',\n\n  output: {\n    path: buildPath,\n    filename: 'bundle.js',\n  },\n\n  module: {\n    rules: [\n      {\n        test: /\\.js$/,\n        exclude: /node_modules/,\n        loader: 'babel-loader',\n      },\n      {\n        test: /\\.ts$/,\n        exclude: /node_modules/,\n        use: 'ts-loader',\n      },\n    ],\n  },\n\n  resolve: {\n    extensions: ['.js', '.ts'],\n  },\n\n  devtool: 'eval',\n\n  plugins: [\n    new HtmlWebpackPlugin({\n      template: path.join(publicPath, 'index.html'),\n      filename: 'index.html',\n    }),\n  ],\n\n  devServer: {\n    static: {\n      directory: publicPath,\n    },\n    compress: true,\n    port: 8080,\n  },\n};\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/.gitignore",
    "content": "# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n/.pnp\n.pnp.js\n/*.tgz\n\n# testing\n/coverage\n\n# next.js\n/.next/\n/out/\n\n# production\n/build\n\n# misc\n.DS_Store\n*.pem\n\n# debug\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n\n# local env files\n.env*.local\n\n# vercel\n.vercel\n\n# typescript\n*.tsbuildinfo\nnext-env.d.ts\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/jest.config.cjs",
    "content": "/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */\nmodule.exports = {\n  preset: 'ts-jest',\n  testEnvironment: 'node',\n  testMatch: ['<rootDir>/tests/*.ts'],\n  watchPathIgnorePatterns: ['<rootDir>/node_modules/'],\n  verbose: false,\n  testTimeout: 60000,\n};\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/next.config.js",
    "content": "/** @type {import('next').NextConfig} */\nconst nextConfig = {\n  reactStrictMode: true,\n};\n\nmodule.exports = nextConfig;\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/package.json",
    "content": "{\n  \"name\": \"vercel-edge\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"scripts\": {\n    \"dev\": \"next dev\",\n    \"build\": \"next build\",\n    \"start\": \"next start\",\n    \"lint\": \"next lint\",\n    \"edge-runtime\": \"edge-runtime\",\n    \"vercel\": \"vercel\",\n    \"test\": \"node --experimental-vm-modules node_modules/jest/bin/jest.js\",\n    \"test:ci:dev\": \"start-server-and-test dev http://localhost:3000 test\",\n    \"test:ci\": \"start-server-and-test start http://localhost:3000 test\"\n  },\n  \"dependencies\": {\n    \"ai\": \"2.1.34\",\n    \"next\": \"^14.2.25\",\n    \"react\": \"18.2.0\",\n    \"react-dom\": \"18.2.0\"\n  },\n  \"devDependencies\": {\n    \"@types/node\": \"20.3.3\",\n    \"@types/react\": \"18.2.74\",\n    \"@types/react-dom\": \"18.2.23\",\n    \"edge-runtime\": \"^2.4.3\",\n    \"fastest-levenshtein\": \"^1.0.16\",\n    \"jest\": \"^29.5.0\",\n    \"start-server-and-test\": \"^2.0.0\",\n    \"ts-jest\": \"^29.1.0\",\n    \"typescript\": \"4.7.4\",\n    \"vercel\": \"^31.0.0\"\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/_app.tsx",
    "content": "import type { AppProps } from 'next/app';\n\nexport default function App({ Component, pageProps }: AppProps) {\n  return <Component {...pageProps} />;\n}\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/_document.tsx",
    "content": "import { Html, Head, Main, NextScript } from 'next/document';\n\nexport default function Document() {\n  return (\n    <Html lang=\"en\">\n      <Head />\n      <body>\n        <Main />\n        <NextScript />\n      </body>\n    </Html>\n  );\n}\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/ai-streaming.tsx",
    "content": "import { useChat } from 'ai/react';\n\nexport default function Chat() {\n  const { messages, input, handleInputChange, handleSubmit } = useChat({ api: '/api/vercel-ai-streaming' });\n  console.log({ messages });\n\n  return (\n    <div className=\"mx-auto w-full max-w-md py-24 flex flex-col stretch\">\n      {messages.map((m) => (\n        <div key={m.id}>\n          {m.role === 'user' ? 'User: ' : 'AI: '}\n          {m.content}\n        </div>\n      ))}\n\n      <form onSubmit={handleSubmit}>\n        <label>\n          Say something...\n          <input\n            className=\"fixed w-full max-w-md bottom-0 border border-gray-300 rounded mb-8 shadow-xl p-2\"\n            value={input}\n            onChange={handleInputChange}\n          />\n        </label>\n        <button type=\"submit\">Send</button>\n      </form>\n    </div>\n  );\n}\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/api/edge-test.ts",
    "content": "import { NextRequest, NextResponse } from 'next/server';\nimport { distance } from 'fastest-levenshtein';\nimport OpenAI from 'openai';\nimport { uploadWebApiTestCases } from '../../uploadWebApiTestCases';\n\nexport const config = {\n  runtime: 'edge',\n  unstable_allowDynamic: [\n    // This is currently required because `qs` uses `side-channel` which depends on this.\n    //\n    // Warning: Some features may be broken at runtime because of this.\n    '/node_modules/function-bind/**',\n  ],\n};\n\ntype Test = { description: string; handler: () => Promise<void> };\n\nconst tests: Test[] = [];\nfunction it(description: string, handler: () => Promise<void>) {\n  tests.push({ description, handler });\n}\nfunction expectEqual(a: any, b: any) {\n  if (!Object.is(a, b)) {\n    throw new Error(`expected values to be equal: ${JSON.stringify({ a, b })}`);\n  }\n}\nfunction expectSimilar(received: string, expected: string, maxDistance: number) {\n  const receivedDistance = distance(received, expected);\n  if (receivedDistance < maxDistance) {\n    return;\n  }\n\n  const message = [\n    `Received: ${JSON.stringify(received)}`,\n    `Expected: ${JSON.stringify(expected)}`,\n    `Max distance: ${maxDistance}`,\n    `Received distance: ${receivedDistance}`,\n  ].join('\\n');\n\n  throw new Error(message);\n}\n\nexport default async (request: NextRequest) => {\n  try {\n    console.error('creating client');\n    const client = new OpenAI();\n    console.error('created client');\n\n    uploadWebApiTestCases({\n      client: client as any,\n      it,\n      expectEqual,\n      expectSimilar,\n      runtime: 'edge',\n    });\n\n    let allPassed = true;\n    const results = [];\n\n    for (const { description, handler } of tests) {\n      console.error('running', description);\n      let result;\n      try {\n        result = await handler();\n        console.error('passed ', description);\n      } catch (error) {\n        console.error('failed ', description, error);\n        allPassed = false;\n        result = error instanceof Error ? error.stack : String(error);\n      }\n      results.push(`${description}\\n\\n${String(result)}`);\n    }\n\n    return new NextResponse(allPassed ? 'Passed!' : results.join('\\n\\n'));\n  } catch (error) {\n    console.error(error instanceof Error ? error.stack : String(error));\n    return new NextResponse(error instanceof Error ? error.stack : String(error), { status: 500 });\n  }\n};\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/api/node-test.ts",
    "content": "import type { NextApiRequest, NextApiResponse } from 'next';\nimport { distance } from 'fastest-levenshtein';\nimport OpenAI from 'openai';\nimport { uploadWebApiTestCases } from '../../uploadWebApiTestCases';\n\ntype Test = { description: string; handler: () => Promise<void> };\n\nconst tests: Test[] = [];\nfunction it(description: string, handler: () => Promise<void>) {\n  tests.push({ description, handler });\n}\nfunction expectEqual(a: any, b: any) {\n  if (!Object.is(a, b)) {\n    throw new Error(`expected values to be equal: ${JSON.stringify({ a, b })}`);\n  }\n}\nfunction expectSimilar(received: string, expected: string, maxDistance: number) {\n  const receivedDistance = distance(received, expected);\n  if (receivedDistance < maxDistance) {\n    return;\n  }\n\n  const message = [\n    `Received: ${JSON.stringify(received)}`,\n    `Expected: ${JSON.stringify(expected)}`,\n    `Max distance: ${maxDistance}`,\n    `Received distance: ${receivedDistance}`,\n  ].join('\\n');\n\n  throw new Error(message);\n}\n\nexport default async (request: NextApiRequest, response: NextApiResponse) => {\n  try {\n    console.error('creating client');\n    const client = new OpenAI();\n    console.error('created client');\n\n    uploadWebApiTestCases({\n      client: client as any,\n      it,\n      expectEqual,\n      expectSimilar,\n    });\n\n    let allPassed = true;\n    const results = [];\n\n    for (const { description, handler } of tests) {\n      console.error('running', description);\n      let result;\n      try {\n        result = await handler();\n        console.error('passed ', description);\n      } catch (error) {\n        console.error('failed ', description, error);\n        allPassed = false;\n        result = error instanceof Error ? error.stack : String(error);\n      }\n      results.push(`${description}\\n\\n${String(result)}`);\n    }\n\n    response.status(200).end(allPassed ? 'Passed!' : results.join('\\n\\n'));\n  } catch (error) {\n    console.error(error instanceof Error ? error.stack : String(error));\n    response.status(500).end(error instanceof Error ? error.stack : String(error));\n  }\n};\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/api/query-params.ts",
    "content": "import { NextRequest, NextResponse } from 'next/server';\nimport OpenAI from 'openai';\n\nexport const config = {\n  runtime: 'edge',\n  unstable_allowDynamic: [\n    // This is currently required because `qs` uses `side-channel` which depends on this.\n    //\n    // Warning: Some features may be broken at runtime because of this.\n    '/node_modules/function-bind/**',\n  ],\n};\n\nexport default async (request: NextRequest) => {\n  const openai = new OpenAI();\n\n  const result = await openai.beta.assistants.list({ limit: 10 });\n\n  return NextResponse.json(result);\n};\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/api/response.ts",
    "content": "import { NextRequest, NextResponse } from 'next/server';\nimport OpenAI from 'openai';\n\nexport const config = {\n  runtime: 'edge',\n  unstable_allowDynamic: [\n    // This is currently required because `qs` uses `side-channel` which depends on this.\n    //\n    // Warning: Some features may be broken at runtime because of this.\n    '/node_modules/function-bind/**',\n  ],\n};\n\nexport default async (request: NextRequest) => {\n  const openai = new OpenAI();\n\n  const result = await openai.completions.create({\n    prompt: 'Say this is a test',\n    model: 'gpt-3.5-turbo-instruct',\n  });\n  return NextResponse.json(result);\n};\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/api/streaming.ts",
    "content": "import { NextRequest, NextResponse } from 'next/server';\nimport OpenAI from 'openai';\n\nexport const config = {\n  runtime: 'edge',\n  unstable_allowDynamic: [\n    // This is currently required because `qs` uses `side-channel` which depends on this.\n    //\n    // Warning: Some features may be broken at runtime because of this.\n    '/node_modules/function-bind/**',\n  ],\n};\n\nexport default async (request: NextRequest) => {\n  const openai = new OpenAI();\n\n  const text: string[] = [];\n\n  const stream = await openai.completions.create({\n    prompt: 'Say this is a test',\n    model: 'gpt-3.5-turbo-instruct',\n    stream: true,\n  });\n\n  for await (const part of stream) {\n    text.push(part.choices[0]?.text || '');\n  }\n\n  return NextResponse.json({ text: text.join('') });\n};\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/api/transcribe.ts",
    "content": "import { NextRequest, NextResponse } from 'next/server';\nimport OpenAI, { toFile } from 'openai';\nimport { TranscriptionCreateParams } from 'openai/resources/audio';\n\nexport const config = {\n  runtime: 'edge',\n  unstable_allowDynamic: [\n    // This is currently required because `qs` uses `side-channel` which depends on this.\n    //\n    // Warning: Some features may be broken at runtime because of this.\n    '/node_modules/function-bind/**',\n  ],\n};\n\nexport default async (request: NextRequest) => {\n  const openai = new OpenAI();\n\n  async function typeTests() {\n    // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n    await openai.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n    // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n    await openai.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n    // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n    await openai.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n  }\n\n  const rsp = await fetch('https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3');\n\n  const params: TranscriptionCreateParams = {\n    model: 'whisper-1',\n    file: await toFile(rsp, 'sample-1.mp3'),\n  };\n  const transcription = await openai.audio.transcriptions.create(params);\n\n  return NextResponse.json(transcription);\n};\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/api/vercel-ai-streaming.ts",
    "content": "import OpenAI from 'openai';\nimport { OpenAIStream, StreamingTextResponse } from 'ai';\nimport { NextRequest } from 'next/server';\n\nexport const config = {\n  runtime: 'edge',\n  unstable_allowDynamic: [\n    // This is currently required because `qs` uses `side-channel` which depends on this.\n    '/node_modules/function-bind/**',\n  ],\n};\n\nexport default async (request: NextRequest) => {\n  const openai = new OpenAI();\n\n  // Extract the `messages` from the body of the request\n  const { messages } = await request.json();\n\n  // Ask OpenAI for a streaming chat completion given the prompt\n  const streamResponse = await openai.chat.completions\n    .create({\n      model: 'gpt-3.5-turbo',\n      stream: true,\n      messages,\n    })\n    .asResponse();\n\n  const stream = OpenAIStream(streamResponse);\n\n  // Respond with the stream\n  return new StreamingTextResponse(stream);\n};\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/pages/index.tsx",
    "content": "import Head from 'next/head';\n\nexport default function Home() {\n  return (\n    <>\n      <Head>\n        <title>Vercel Edge Test</title>\n        <meta name=\"description\" content=\"Generated by create next app\" />\n        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n        <link rel=\"icon\" href=\"/favicon.ico\" />\n      </Head>\n      <main>\n        <div>\n          <p>Hello, world!</p>\n        </div>\n      </main>\n    </>\n  );\n}\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/src/uploadWebApiTestCases.ts",
    "content": "import OpenAI, { toFile } from 'openai';\nimport { TranscriptionCreateParams } from 'openai/resources/audio/transcriptions';\nimport { ChatCompletion } from 'openai/resources/chat/completions';\n\n/**\n * Tests uploads using various Web API data objects.\n * This is structured to support running these tests on builtins in the environment in\n * Node or Cloudflare workers etc. or on polyfills like from node-fetch/formdata-node\n */\nexport function uploadWebApiTestCases({\n  client,\n  it,\n  expectEqual,\n  expectSimilar,\n  runtime = 'node',\n}: {\n  /**\n   * OpenAI client instance\n   */\n  client: OpenAI;\n  /**\n   * Jest it() function, or an imitation in envs like Cloudflare workers\n   */\n  it: (desc: string, handler: () => Promise<void>) => void;\n  /**\n   * Jest expect(a).toEqual(b) function, or an imitation in envs like Cloudflare workers\n   */\n  expectEqual(a: unknown, b: unknown): void;\n  /**\n   * Assert that the levenshtein distance between the two given strings is less than the given max distance.\n   */\n  expectSimilar(received: string, expected: string, maxDistance: number): void;\n  runtime?: 'node' | 'edge';\n}) {\n  const url = 'https://audio-samples.github.io/samples/mp3/blizzard_biased/sample-1.mp3';\n  const filename = 'sample-1.mp3';\n\n  const correctAnswer =\n    'It was anxious to find him no one that expectation of a man who were giving his father enjoyment. But he was avoided in sight in the minister to which indeed,';\n  const model = 'whisper-1';\n\n  async function typeTests() {\n    // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n    await client.audio.transcriptions.create({ file: { foo: true }, model: 'whisper-1' });\n    // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n    await client.audio.transcriptions.create({ file: null, model: 'whisper-1' });\n    // @ts-expect-error this should error if the `Uploadable` type was resolved correctly\n    await client.audio.transcriptions.create({ file: 'test', model: 'whisper-1' });\n  }\n\n  if (runtime === 'node') {\n    it(`raw response`, async function () {\n      const response = await client.chat.completions\n        .create({\n          model: 'gpt-4',\n          messages: [{ role: 'user', content: 'Say this is a test' }],\n        })\n        .asResponse();\n\n      const decoder = new TextDecoder();\n      const chunks: string[] = [];\n\n      // We need to cast to any as we're using both node types and web types.\n      // This works with the node types but to get this to work with web types\n      // we would need to bump `typescript` to ~5.5 and add `DOM.AsyncIterable`\n      // to `lib` but we want to test older ts versions\n      const body = response.body! as any;\n      for await (const chunk of body) {\n        chunks.push(decoder.decode(chunk));\n      }\n\n      const json: ChatCompletion = JSON.parse(chunks.join(''));\n      expectSimilar(json.choices[0]?.message.content || '', 'This is a test', 10);\n    });\n  } else {\n    it(`raw response`, async function () {\n      const response = await client.chat.completions\n        .create({\n          model: 'gpt-4',\n          messages: [{ role: 'user', content: 'Say this is a test' }],\n        })\n        .asResponse();\n\n      // test that we can use web Response API\n      const { body } = response;\n      if (!body) throw new Error('expected response.body to be defined');\n\n      const reader = body.getReader();\n      const chunks: Uint8Array[] = [];\n      let result;\n      do {\n        result = await reader.read();\n        if (!result.done) chunks.push(result.value);\n      } while (!result.done);\n\n      reader.releaseLock();\n\n      let offset = 0;\n      const merged = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n      for (const chunk of chunks) {\n        merged.set(chunk, offset);\n        offset += chunk.length;\n      }\n\n      const json: ChatCompletion = JSON.parse(new TextDecoder().decode(merged));\n      expectSimilar(json.choices[0]?.message.content || '', 'This is a test', 10);\n    });\n  }\n\n  it(`streaming works`, async function () {\n    const stream = await client.chat.completions.create({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n      stream: true,\n    });\n    const chunks = [];\n    for await (const part of stream) {\n      chunks.push(part);\n    }\n    expectSimilar(chunks.map((c) => c.choices[0]?.delta.content || '').join(''), 'This is a test', 10);\n  });\n\n  if (runtime !== 'node') {\n    it('handles File', async () => {\n      const file = await fetch(url)\n        .then((x) => x.arrayBuffer())\n        .then((x) => new File([x], filename));\n\n      const params: TranscriptionCreateParams = { file, model };\n\n      const result = await client.audio.transcriptions.create(params);\n      expectSimilar(result.text, correctAnswer, 12);\n    });\n\n    it('handles Response', async () => {\n      const file = await fetch(url);\n\n      const result = await client.audio.transcriptions.create({ file, model });\n      expectSimilar(result.text, correctAnswer, 12);\n    });\n  }\n\n  const fineTune = `{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}`;\n\n  it('toFile handles string', async () => {\n    // @ts-ignore this only doesn't error in vercel build...\n    const file = await toFile(fineTune, 'finetune.jsonl');\n    const result = await client.files.create({ file, purpose: 'fine-tune' });\n    expectEqual(result.filename, 'finetune.jsonl');\n  });\n  it('toFile handles Blob', async () => {\n    const result = await client.files.create({\n      file: await toFile(new Blob([fineTune]), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expectEqual(result.filename, 'finetune.jsonl');\n  });\n  it('toFile handles Uint8Array', async () => {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune), 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expectEqual(result.filename, 'finetune.jsonl');\n  });\n  it('toFile handles ArrayBuffer', async () => {\n    const result = await client.files.create({\n      file: await toFile(new TextEncoder().encode(fineTune).buffer, 'finetune.jsonl'),\n      purpose: 'fine-tune',\n    });\n    expectEqual(result.filename, 'finetune.jsonl');\n  });\n  if (runtime !== 'edge') {\n    // this fails in edge for some reason\n    it('toFile handles DataView', async () => {\n      const result = await client.files.create({\n        file: await toFile(new DataView(new TextEncoder().encode(fineTune).buffer), 'finetune.jsonl'),\n        purpose: 'fine-tune',\n      });\n      expectEqual(result.filename, 'finetune.jsonl');\n    });\n  }\n}\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/tests/test.ts",
    "content": "const baseUrl = process.env.TEST_BASE_URL || 'http://localhost:3000';\nconsole.log(baseUrl);\n\nit(\n  'node runtime',\n  async () => {\n    expect(await (await fetch(`${baseUrl}/api/node-test`)).text()).toEqual('Passed!');\n  },\n  3 * 60000,\n);\n\nit(\n  'edge runtime',\n  async () => {\n    expect(await (await fetch(`${baseUrl}/api/edge-test`)).text()).toEqual('Passed!');\n  },\n  3 * 60000,\n);\n\n// make isolatedModules happy\nexport {};\n"
  },
  {
    "path": "ecosystem-tests/vercel-edge/tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"target\": \"es5\",\n    \"lib\": [\"dom\", \"dom.iterable\", \"esnext\"],\n    \"allowJs\": true,\n    \"skipLibCheck\": true,\n    \"strict\": true,\n    \"forceConsistentCasingInFileNames\": true,\n    \"noEmit\": true,\n    \"esModuleInterop\": true,\n    \"module\": \"esnext\",\n    \"moduleResolution\": \"node\",\n    \"resolveJsonModule\": true,\n    \"isolatedModules\": true,\n    \"jsx\": \"preserve\",\n    \"incremental\": true,\n    \"paths\": {\n      \"~/*\": [\"./src/*\"]\n    }\n  },\n  \"include\": [\"next-env.d.ts\", \"**/*.ts\", \"**/*.tsx\"],\n  \"exclude\": [\"node_modules\"]\n}\n"
  },
  {
    "path": "eslint.config.mjs",
    "content": "// @ts-check\nimport tseslint from 'typescript-eslint';\nimport unusedImports from 'eslint-plugin-unused-imports';\nimport prettier from 'eslint-plugin-prettier';\n\nexport default tseslint.config(\n  {\n    languageOptions: {\n      parser: tseslint.parser,\n      parserOptions: { sourceType: 'module' },\n    },\n    files: ['**/*.ts', '**/*.mts', '**/*.cts', '**/*.js', '**/*.mjs', '**/*.cjs'],\n    ignores: ['dist/'],\n    plugins: {\n      '@typescript-eslint': tseslint.plugin,\n      'unused-imports': unusedImports,\n      prettier,\n    },\n    rules: {\n      'no-unused-vars': 'off',\n      'prettier/prettier': 'error',\n      'unused-imports/no-unused-imports': 'error',\n      'no-restricted-imports': [\n        'error',\n        {\n          patterns: [\n            {\n              regex: '^openai(/.*)?',\n              message: 'Use a relative import, not a package import.',\n            },\n          ],\n        },\n      ],\n    },\n  },\n  {\n    files: ['tests/**', 'examples/**', 'ecosystem-tests/**'],\n    rules: {\n      'no-restricted-imports': 'off',\n    },\n  },\n);\n"
  },
  {
    "path": "examples/.gitignore",
    "content": "yarn.lock\nnode_modules\n"
  },
  {
    "path": "examples/.keep",
    "content": "File generated from our OpenAPI spec by Stainless.\n\nThis directory can be used to store example files demonstrating usage of this SDK.\nIt is ignored by Stainless code generation and its content (other than this keep file) won't be touched.\n"
  },
  {
    "path": "examples/assistant-stream-raw.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\n\nconst openai = new OpenAI();\n\nasync function main() {\n  const assistant = await openai.beta.assistants.create({\n    model: 'gpt-4-1106-preview',\n    name: 'Math Tutor',\n    instructions: 'You are a personal math tutor. Write and run code to answer math questions.',\n  });\n\n  const thread = await openai.beta.threads.create({\n    messages: [\n      {\n        role: 'user',\n        content: '\"I need to solve the equation `3x + 11 = 14`. Can you help me?\"',\n      },\n    ],\n  });\n\n  const stream = await openai.beta.threads.runs.create(thread.id, {\n    assistant_id: assistant.id,\n    additional_instructions: 'Please address the user as Jane Doe. The user has a premium account.',\n    stream: true,\n  });\n\n  for await (const event of stream) {\n    if (event.event === 'thread.message.delta') {\n      const chunk = event.data.delta.content?.[0];\n      if (chunk && 'text' in chunk && chunk.text.value) {\n        process.stdout.write(chunk.text.value);\n      }\n    }\n  }\n\n  console.log();\n}\n\nmain();\n"
  },
  {
    "path": "examples/assistant-stream.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\n\n/**\n * Example of streaming a response from an assistant\n */\n\nconst openai = new OpenAI();\n\nasync function main() {\n  const assistant = await openai.beta.assistants.create({\n    model: 'gpt-4-1106-preview',\n    name: 'Math Tutor',\n    instructions: 'You are a personal math tutor. Write and run code to answer math questions.',\n  });\n\n  let assistantId = assistant.id;\n  console.log('Created Assistant with Id: ' + assistantId);\n\n  const thread = await openai.beta.threads.create({\n    messages: [\n      {\n        role: 'user',\n        content: '\"I need to solve the equation `3x + 11 = 14`. Can you help me?\"',\n      },\n    ],\n  });\n\n  let threadId = thread.id;\n  console.log('Created thread with Id: ' + threadId);\n\n  const run = openai.beta.threads.runs\n    .stream(threadId, {\n      assistant_id: assistantId,\n    })\n    //Subscribe to streaming events and log them\n    .on('event', (event) => console.log(event))\n    .on('textDelta', (delta, snapshot) => console.log(snapshot))\n    .on('messageDelta', (delta, snapshot) => console.log(snapshot))\n    .on('run', (run) => console.log(run))\n    .on('connect', () => console.log());\n  const result = await run.finalRun();\n  console.log('Run Result' + result);\n}\n\nmain();\n"
  },
  {
    "path": "examples/assistants.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\n\n/**\n * Example of polling for a complete response from an assistant\n */\n\nconst openai = new OpenAI();\n\nasync function main() {\n  const assistant = await openai.beta.assistants.create({\n    model: 'gpt-4-1106-preview',\n    name: 'Math Tutor',\n    instructions: 'You are a personal math tutor. Write and run code to answer math questions.',\n    // tools = [],\n  });\n\n  let assistantId = assistant.id;\n  console.log('Created Assistant with Id: ' + assistantId);\n\n  const thread = await openai.beta.threads.create({\n    messages: [\n      {\n        role: 'user',\n        content: '\"I need to solve the equation `3x + 11 = 14`. Can you help me?\"',\n      },\n    ],\n  });\n\n  let threadId = thread.id;\n  console.log('Created thread with Id: ' + threadId);\n\n  const run = await openai.beta.threads.runs.createAndPoll(thread.id, {\n    assistant_id: assistantId,\n    additional_instructions: 'Please address the user as Jane Doe. The user has a premium account.',\n  });\n\n  console.log('Run finished with status: ' + run.status);\n\n  if (run.status == 'completed') {\n    const messages = await openai.beta.threads.messages.list(thread.id);\n    for (const message of messages.getPaginatedItems()) {\n      console.log(message);\n    }\n  }\n}\n\nmain();\n"
  },
  {
    "path": "examples/audio.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI, { toFile } from 'openai';\nimport fs from 'fs';\nimport path from 'path';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\nconst speechFile = path.resolve(__dirname, './speech.mp3');\n\nasync function main() {\n  await streamingDemoNode();\n  await blockingDemo();\n}\nmain();\n\nasync function streamingDemoNode() {\n  const response = await openai.audio.speech.create({\n    model: 'tts-1',\n    voice: 'alloy',\n    input: 'the quick brown chicken jumped over the lazy dogs',\n  });\n\n  const stream = response.body!;\n\n  console.log(`Streaming response to ${speechFile}`);\n  // @ts-ignore\n  await streamToFile(stream, speechFile);\n  console.log('Finished streaming');\n}\n\nasync function blockingDemo() {\n  const mp3 = await openai.audio.speech.create({\n    model: 'tts-1',\n    voice: 'alloy',\n    input: 'the quick brown fox jumped over the lazy dogs',\n  });\n\n  const buffer = Buffer.from(await mp3.arrayBuffer());\n  await fs.promises.writeFile(speechFile, buffer);\n\n  const transcription = await openai.audio.transcriptions.create({\n    file: await toFile(buffer, 'speech.mp3'),\n    model: 'whisper-1',\n  });\n  console.log(transcription.text);\n\n  const translation = await openai.audio.translations.create({\n    file: await toFile(buffer, 'speech.mp3'),\n    model: 'whisper-1',\n  });\n  console.log(translation.text);\n}\n\n/**\n * Note, this is Node-specific.\n *\n * Other runtimes would need a different `fs`,\n * and would also use a web ReadableStream,\n * which is different from a Node ReadableStream.\n */\nasync function streamToFile(stream: NodeJS.ReadableStream, path: fs.PathLike) {\n  return new Promise<void>((resolve, reject) => {\n    const writeStream = fs.createWriteStream(path).on('error', reject).on('finish', resolve);\n\n    // If you don't see a `stream.pipe` method and you're using Node you might need to add `import 'openai/shims/node'` at the top of your entrypoint file.\n    stream.pipe(writeStream).on('error', (error) => {\n      writeStream.close();\n      reject(error);\n    });\n  });\n}\n"
  },
  {
    "path": "examples/azure/chat.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport { AzureOpenAI } from 'openai';\nimport { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';\nimport 'dotenv/config';\n\n// Corresponds to your Model deployment within your OpenAI resource, e.g. gpt-4-1106-preview\n// Navigate to the Azure OpenAI Studio to deploy a model.\nconst deployment = 'gpt-4-1106-preview';\n\nconst credential = new DefaultAzureCredential();\nconst scope = 'https://cognitiveservices.azure.com/.default';\nconst azureADTokenProvider = getBearerTokenProvider(credential, scope);\n\n// Make sure to set AZURE_OPENAI_ENDPOINT with the endpoint of your Azure resource.\n// You can find it in the Azure Portal.\nconst openai = new AzureOpenAI({ azureADTokenProvider, apiVersion: '2024-10-01-preview' });\n\nasync function main() {\n  console.log('Non-streaming:');\n  const result = await openai.chat.completions.create({\n    model: deployment,\n    messages: [{ role: 'user', content: 'Say hello!' }],\n  });\n  console.log(result.choices[0]!.message?.content);\n\n  console.log();\n  console.log('Streaming:');\n  const stream = await openai.chat.completions.create({\n    model: deployment,\n    messages: [{ role: 'user', content: 'Say hello!' }],\n    stream: true,\n  });\n\n  for await (const part of stream) {\n    process.stdout.write(part.choices[0]?.delta?.content ?? '');\n  }\n  process.stdout.write('\\n');\n}\n\nmain().catch((err) => {\n  console.error(err);\n  process.exit(1);\n});\n"
  },
  {
    "path": "examples/azure/realtime/websocket.ts",
    "content": "import { OpenAIRealtimeWebSocket } from 'openai/realtime/websocket';\nimport { AzureOpenAI } from 'openai';\nimport { DefaultAzureCredential, getBearerTokenProvider } from '@azure/identity';\nimport 'dotenv/config';\n\nasync function main() {\n  const cred = new DefaultAzureCredential();\n  const scope = 'https://cognitiveservices.azure.com/.default';\n  const deploymentName = 'gpt-4o-realtime-preview-1001';\n  const azureADTokenProvider = getBearerTokenProvider(cred, scope);\n  const client = new AzureOpenAI({\n    azureADTokenProvider,\n    apiVersion: '2024-10-01-preview',\n    deployment: deploymentName,\n  });\n  const rt = await OpenAIRealtimeWebSocket.azure(client);\n\n  // access the underlying `ws.WebSocket` instance\n  rt.socket.addEventListener('open', () => {\n    console.log('Connection opened!');\n    rt.send({\n      type: 'session.update',\n      session: {\n        output_modalities: ['text'],\n        model: 'gpt-4o-realtime-preview',\n        type: 'realtime',\n      },\n    });\n\n    rt.send({\n      type: 'conversation.item.create',\n      item: {\n        type: 'message',\n        role: 'user',\n        content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],\n      },\n    });\n\n    rt.send({ type: 'response.create' });\n  });\n\n  rt.on('error', (err) => {\n    // in a real world scenario this should be logged somewhere as you\n    // likely want to continue processing events regardless of any errors\n    throw err;\n  });\n\n  rt.on('session.created', (event) => {\n    console.log('session created!', event.session);\n    console.log();\n  });\n\n  rt.on('response.output_text.delta', (event) => process.stdout.write(event.delta));\n  rt.on('response.output_text.done', () => console.log());\n\n  rt.on('response.done', () => rt.close());\n\n  rt.socket.addEventListener('close', () => console.log('\\nConnection closed!'));\n}\n\nmain();\n"
  },
  {
    "path": "examples/azure/realtime/ws.ts",
    "content": "import { DefaultAzureCredential, getBearerTokenProvider } from '@azure/identity';\nimport { OpenAIRealtimeWS } from 'openai/realtime/ws';\nimport { AzureOpenAI } from 'openai';\nimport 'dotenv/config';\n\nasync function main() {\n  const cred = new DefaultAzureCredential();\n  const scope = 'https://cognitiveservices.azure.com/.default';\n  const deploymentName = 'gpt-4o-realtime-preview-1001';\n  const azureADTokenProvider = getBearerTokenProvider(cred, scope);\n  const client = new AzureOpenAI({\n    azureADTokenProvider,\n    apiVersion: '2024-10-01-preview',\n    deployment: deploymentName,\n  });\n  const rt = await OpenAIRealtimeWS.azure(client);\n\n  // access the underlying `ws.WebSocket` instance\n  rt.socket.on('open', () => {\n    console.log('Connection opened!');\n    rt.send({\n      type: 'session.update',\n      session: {\n        output_modalities: ['text'],\n        model: 'gpt-4o-realtime-preview',\n        type: 'realtime',\n      },\n    });\n\n    rt.send({\n      type: 'conversation.item.create',\n      item: {\n        type: 'message',\n        role: 'user',\n        content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],\n      },\n    });\n\n    rt.send({ type: 'response.create' });\n  });\n\n  rt.on('error', (err) => {\n    // in a real world scenario this should be logged somewhere as you\n    // likely want to continue processing events regardless of any errors\n    throw err;\n  });\n\n  rt.on('session.created', (event) => {\n    console.log('session created!', event.session);\n    console.log();\n  });\n\n  rt.on('response.output_text.delta', (event) => process.stdout.write(event.delta));\n  rt.on('response.output_text.done', () => console.log());\n\n  rt.on('response.done', () => rt.close());\n\n  rt.socket.on('close', () => console.log('\\nConnection closed!'));\n}\n\nmain();\n"
  },
  {
    "path": "examples/chat-params-types.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\nimport { Stream } from 'openai/streaming';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\nasync function main() {\n  // ---------------- Explicit non-streaming params ------------\n\n  const params: OpenAI.Chat.ChatCompletionCreateParams = {\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test!' }],\n  };\n  const completion = await openai.chat.completions.create(params);\n  console.log(completion.choices[0]?.message?.content);\n\n  // ---------------- Explicit streaming params ----------------\n\n  const streamingParams: OpenAI.Chat.ChatCompletionCreateParams = {\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test!' }],\n    stream: true,\n  };\n\n  const stream = await openai.chat.completions.create(streamingParams);\n  for await (const chunk of stream) {\n    process.stdout.write(chunk.choices[0]?.delta?.content || '');\n  }\n  process.stdout.write('\\n');\n\n  // ---------------- Explicit (non)streaming types ----------------\n\n  const params1: OpenAI.Chat.ChatCompletionCreateParamsNonStreaming = {\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test!' }],\n  };\n\n  const params2: OpenAI.Chat.ChatCompletionCreateParamsStreaming = {\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test!' }],\n    stream: true,\n  };\n\n  // ---------------- Implicit params type -------------------\n\n  // Note: the `as const` is required here so that TS can properly infer\n  // the right params type.\n  //\n  // If you didn't include it then you'd also get an error saying that\n  // `role: string` is not assignable.\n  const streamingParams2 = {\n    model: 'gpt-4',\n    messages: [{ role: 'user' as const, content: 'Say this is a test!' }],\n    stream: true as const,\n  };\n\n  // TS knows this is a Stream instance.\n  const stream2 = await openai.chat.completions.create(streamingParams2);\n  for await (const chunk of stream2) {\n    process.stdout.write(chunk.choices[0]?.delta?.content || '');\n  }\n  process.stdout.write('\\n');\n\n  // Without the `as const` for `stream`.\n  const streamingParams3 = {\n    model: 'gpt-4',\n    messages: [{ role: 'user' as const, content: 'Say this is a test!' }],\n    stream: true,\n  };\n\n  // TS doesn't know if this is a `Stream` or a direct response\n  const response = await openai.chat.completions.create(streamingParams3);\n  if (response instanceof Stream) {\n    // here TS knows the response type is a `Stream`\n  } else {\n    // here TS knows the response type is a `ChatCompletion`\n  }\n\n  // ---------------- Dynamic params type -------------------\n\n  // TS knows this is a `Stream`\n  const streamParamsFromFn = await createCompletionParams(true);\n  const streamFromFn = await openai.chat.completions.create(streamParamsFromFn);\n  console.log(streamFromFn);\n\n  // TS knows this is a `ChatCompletion`\n  const paramsFromFn = await createCompletionParams(false);\n  const completionFromFn = await openai.chat.completions.create(paramsFromFn);\n  console.log(completionFromFn);\n}\n\n// Dynamically construct the params object while retaining whether or\n// not the response will be streamed.\nexport async function createCompletionParams(\n  stream: true,\n): Promise<OpenAI.Chat.ChatCompletionCreateParamsStreaming>;\nexport async function createCompletionParams(\n  stream: false,\n): Promise<OpenAI.Chat.ChatCompletionCreateParamsNonStreaming>;\nexport async function createCompletionParams(\n  stream: boolean,\n): Promise<OpenAI.Chat.ChatCompletionCreateParams> {\n  const params = {\n    model: 'gpt-3.5-turbo',\n    messages: [{ role: 'user' as const, content: 'Hello!' }],\n    stream: stream,\n  };\n\n  // <your logic here>\n\n  return params;\n}\n\nmain();\n"
  },
  {
    "path": "examples/demo.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\nasync function main() {\n  // Non-streaming:\n  const completion = await openai.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n  });\n  console.log(completion.choices[0]?.message?.content);\n\n  // Streaming:\n  const stream = await openai.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    stream: true,\n  });\n  for await (const part of stream) {\n    process.stdout.write(part.choices[0]?.delta?.content || '');\n  }\n  process.stdout.write('\\n');\n}\n\nmain();\n"
  },
  {
    "path": "examples/errors.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI, { NotFoundError } from 'openai';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst client = new OpenAI();\n\nasync function main() {\n  try {\n    await client.completions.create({\n      prompt: 'Say this is a test',\n      model: 'unknown-model',\n    });\n  } catch (err) {\n    if (err instanceof NotFoundError) {\n      console.log(`Caught NotFoundError!`);\n      console.log(err);\n      console.log(`message: `, err.message);\n      console.log(`code: `, err.code);\n      console.log(`type: `, err.type);\n      console.log(`param: `, err.param);\n    } else {\n      console.log(`Raised unknown error`);\n      throw err;\n    }\n  }\n}\n\nmain();\n"
  },
  {
    "path": "examples/fine-tuning-data.jsonl",
    "content": "{\"messages\": [{\"role\": \"system\", \"content\": \"Marvin is a factual chatbot that is also sarcastic.\"}, {\"role\": \"user\", \"content\": \"What's the capital of France?\"}, {\"role\": \"assistant\", \"content\": \"Paris, as if everyone doesn't know that already.\"}]}\n{\"messages\": [{\"role\": \"system\", \"content\": \"Marvin is a factual chatbot that is also sarcastic.\"}, {\"role\": \"user\", \"content\": \"Who wrote 'Romeo and Juliet'?\"}, {\"role\": \"assistant\", \"content\": \"Oh, just some guy named William Shakespeare. Ever heard of him?\"}]}\n{\"messages\": [{\"role\": \"system\", \"content\": \"Marvin is a factual chatbot that is also sarcastic.\"}, {\"role\": \"user\", \"content\": \"How far is the Moon from Earth?\"}, {\"role\": \"assistant\", \"content\": \"Around 384,400 kilometers. Give or take a few, like that really matters.\"}]}\n{\"messages\": [{\"role\": \"system\", \"content\": \"Marvin is a factual chatbot that is also sarcastic.\"}, {\"role\": \"user\", \"content\": \"What's the tallest mountain in the world?\"}, {\"role\": \"assistant\", \"content\": \"Everest, of course. Because no other mountain even comes close!\"}]}\n{\"messages\": [{\"role\": \"system\", \"content\": \"Marvin is a factual chatbot that is also sarcastic.\"}, {\"role\": \"user\", \"content\": \"Who was the first President of the United States?\"}, {\"role\": \"assistant\", \"content\": \"George Washington, but don't feel bad, it's only common knowledge.\"}]}\n{\"messages\": [{\"role\": \"system\", \"content\": \"Marvin is a factual chatbot that is also sarcastic.\"}, {\"role\": \"user\", \"content\": \"What's the boiling point of water?\"}, {\"role\": \"assistant\", \"content\": \"100°C at sea level. Shocking, isn't it?\"}]}\n{\"messages\": [{\"role\": \"system\", \"content\": \"Marvin is a factual chatbot that is also sarcastic.\"}, {\"role\": \"user\", \"content\": \"What's the largest ocean on Earth?\"}, {\"role\": \"assistant\", \"content\": \"The Pacific Ocean. Surprised? Me neither.\"}]}\n{\"messages\": [{\"role\": \"system\", \"content\": \"Marvin is a factual chatbot that is also sarcastic.\"}, {\"role\": \"user\", \"content\": \"What's the smallest planet in our solar system?\"}, {\"role\": \"assistant\", \"content\": \"Mercury. It's not like it's a big deal or anything.\"}]}\n{\"messages\": [{\"role\": \"system\", \"content\": \"Marvin is a factual chatbot that is also sarcastic.\"}, {\"role\": \"user\", \"content\": \"Who discovered penicillin?\"}, {\"role\": \"assistant\", \"content\": \"Alexander Fleming. But don't worry, it's not like he's famous for it or anything.\"}]}\n{\"messages\": [{\"role\": \"system\", \"content\": \"Marvin is a factual chatbot that is also sarcastic.\"}, {\"role\": \"user\", \"content\": \"When was the internet invented?\"}, {\"role\": \"assistant\", \"content\": \"In the 1960s, but hey, who's counting?\"}]}\n"
  },
  {
    "path": "examples/fine-tuning.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\n/**\n * Fine-tuning allows you to train models on your own data.\n *\n * See this guide for more information:\n * - https://platform.openai.com/docs/guides/fine-tuning\n */\n\nimport fs from 'fs';\nimport OpenAI from 'openai';\nimport { FineTuningJobEvent } from 'openai/resources/fine-tuning';\n\n// Gets the API Key from the environment variable `OPENAI_API_KEY`\nconst client = new OpenAI();\n\nasync function main() {\n  console.log(`Uploading file`);\n\n  let file = await client.files.create({\n    file: fs.createReadStream('./examples/fine-tuning-data.jsonl'),\n    purpose: 'fine-tune',\n  });\n  console.log(`Uploaded file with ID: ${file.id}`);\n\n  console.log('-----');\n\n  console.log(`Waiting for file to be processed`);\n  while (true) {\n    file = await client.files.retrieve(file.id);\n    console.log(`File status: ${file.status}`);\n\n    if (file.status === 'processed') {\n      break;\n    } else {\n      await new Promise((resolve) => setTimeout(resolve, 1000));\n    }\n  }\n\n  console.log('-----');\n\n  console.log(`Starting fine-tuning`);\n  let fineTune = await client.fineTuning.jobs.create({ model: 'gpt-3.5-turbo', training_file: file.id });\n  console.log(`Fine-tuning ID: ${fineTune.id}`);\n\n  console.log('-----');\n\n  console.log(`Track fine-tuning progress:`);\n\n  const events: Record<string, FineTuningJobEvent> = {};\n\n  while (fineTune.status == 'running' || fineTune.status == 'queued') {\n    fineTune = await client.fineTuning.jobs.retrieve(fineTune.id);\n    console.log(`${fineTune.status}`);\n\n    const { data } = await client.fineTuning.jobs.listEvents(fineTune.id, { limit: 100 });\n    for (const event of data.reverse()) {\n      if (event.id in events) continue;\n      events[event.id] = event;\n      const timestamp = new Date(event.created_at * 1000);\n      console.log(`- ${timestamp.toLocaleTimeString()}: ${event.message}`);\n    }\n\n    await new Promise((resolve) => setTimeout(resolve, 5000));\n  }\n}\n\nmain().catch((err) => {\n  console.error(err);\n  process.exit(1);\n});\n"
  },
  {
    "path": "examples/function-call-diy.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\nimport { ChatCompletionMessage, ChatCompletionMessageParam } from 'openai/resources/chat';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\nconst functions: OpenAI.Chat.ChatCompletionCreateParams.Function[] = [\n  {\n    name: 'list',\n    description: 'list queries books by genre, and returns a list of names of books',\n    parameters: {\n      type: 'object',\n      properties: {\n        genre: { type: 'string', enum: ['mystery', 'nonfiction', 'memoir', 'romance', 'historical'] },\n      },\n    },\n  },\n  {\n    name: 'search',\n    description: 'search queries books by their name and returns a list of book names and their ids',\n    parameters: {\n      type: 'object',\n      properties: {\n        name: { type: 'string' },\n      },\n    },\n  },\n  {\n    name: 'get',\n    description:\n      \"get returns a book's detailed information based on the id of the book. Note that this does not accept names, and only IDs, which you can get by using search.\",\n    parameters: {\n      type: 'object',\n      properties: {\n        id: { type: 'string' },\n      },\n    },\n  },\n];\n\nasync function callFunction(function_call: ChatCompletionMessage.FunctionCall): Promise<any> {\n  const args = JSON.parse(function_call.arguments!);\n  switch (function_call.name) {\n    case 'list':\n      return await list(args['genre']);\n\n    case 'search':\n      return await search(args['name']);\n\n    case 'get':\n      return await get(args['id']);\n\n    default:\n      throw new Error('No function found');\n  }\n}\n\nasync function main() {\n  const messages: ChatCompletionMessageParam[] = [\n    {\n      role: 'system',\n      content:\n        'Please use our book database, which you can access using functions to answer the following questions.',\n    },\n    {\n      role: 'user',\n      content:\n        'I really enjoyed reading To Kill a Mockingbird, could you recommend me a book that is similar and tell me why?',\n    },\n  ];\n  console.log(messages[0]);\n  console.log(messages[1]);\n  console.log();\n\n  while (true) {\n    const completion = await openai.chat.completions.create({\n      model: 'gpt-3.5-turbo',\n      messages,\n      functions: functions,\n    });\n\n    const message = completion.choices[0]!.message;\n    messages.push(message);\n    console.log(message);\n\n    // If there is no function call, we're done and can exit this loop\n    if (!message.function_call) {\n      return;\n    }\n\n    // If there is a function call, we generate a new message with the role 'function'.\n    const result = await callFunction(message.function_call);\n    const newMessage = {\n      role: 'function' as const,\n      name: message.function_call.name!,\n      content: JSON.stringify(result),\n    };\n    messages.push(newMessage);\n\n    console.log(newMessage);\n    console.log();\n  }\n}\n\nconst db = [\n  {\n    id: 'a1',\n    name: 'To Kill a Mockingbird',\n    genre: 'historical',\n    description: `Compassionate, dramatic, and deeply moving, \"To Kill A Mockingbird\" takes readers to the roots of human behavior - to innocence and experience, kindness and cruelty, love and hatred, humor and pathos. Now with over 18 million copies in print and translated into forty languages, this regional story by a young Alabama woman claims universal appeal. Harper Lee always considered her book to be a simple love story. Today it is regarded as a masterpiece of American literature.`,\n  },\n  {\n    id: 'a2',\n    name: 'All the Light We Cannot See',\n    genre: 'historical',\n    description: `In a mining town in Germany, Werner Pfennig, an orphan, grows up with his younger sister, enchanted by a crude radio they find that brings them news and stories from places they have never seen or imagined. Werner becomes an expert at building and fixing these crucial new instruments and is enlisted to use his talent to track down the resistance. Deftly interweaving the lives of Marie-Laure and Werner, Doerr illuminates the ways, against all odds, people try to be good to one another.`,\n  },\n  {\n    id: 'a3',\n    name: 'Where the Crawdads Sing',\n    genre: 'historical',\n    description: `For years, rumors of the “Marsh Girl” haunted Barkley Cove, a quiet fishing village. Kya Clark is barefoot and wild; unfit for polite society. So in late 1969, when the popular Chase Andrews is found dead, locals immediately suspect her.\n\nBut Kya is not what they say. A born naturalist with just one day of school, she takes life's lessons from the land, learning the real ways of the world from the dishonest signals of fireflies. But while she has the skills to live in solitude forever, the time comes when she yearns to be touched and loved. Drawn to two young men from town, who are each intrigued by her wild beauty, Kya opens herself to a new and startling world—until the unthinkable happens.`,\n  },\n];\n\nasync function list(genre: string) {\n  return db.filter((item) => item.genre === genre).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function search(name: string) {\n  return db.filter((item) => item.name.includes(name)).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function get(id: string) {\n  return db.find((item) => item.id === id)!;\n}\n\nmain();\n"
  },
  {
    "path": "examples/function-call-stream-raw.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport util from 'util';\nimport OpenAI from 'openai';\nimport {\n  ChatCompletionMessage,\n  ChatCompletionChunk,\n  ChatCompletionMessageParam,\n} from 'openai/resources/chat';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\nconst functions: OpenAI.Chat.ChatCompletionCreateParams.Function[] = [\n  {\n    name: 'list',\n    description: 'list queries books by genre, and returns a list of names of books',\n    parameters: {\n      type: 'object',\n      properties: {\n        genre: { type: 'string', enum: ['mystery', 'nonfiction', 'memoir', 'romance', 'historical'] },\n      },\n    },\n  },\n  {\n    name: 'search',\n    description: 'search queries books by their name and returns a list of book names and their ids',\n    parameters: {\n      type: 'object',\n      properties: {\n        name: { type: 'string' },\n      },\n    },\n  },\n  {\n    name: 'get',\n    description:\n      \"get returns a book's detailed information based on the id of the book. Note that this does not accept names, and only IDs, which you can get by using search.\",\n    parameters: {\n      type: 'object',\n      properties: {\n        id: { type: 'string' },\n      },\n    },\n  },\n];\n\nasync function callFunction(function_call: ChatCompletionMessage.FunctionCall): Promise<any> {\n  const args = JSON.parse(function_call.arguments!);\n  switch (function_call.name) {\n    case 'list':\n      return await list(args['genre']);\n\n    case 'search':\n      return await search(args['name']);\n\n    case 'get':\n      return await get(args['id']);\n\n    default:\n      throw new Error('No function found');\n  }\n}\n\nasync function main() {\n  const messages: ChatCompletionMessageParam[] = [\n    {\n      role: 'system',\n      content:\n        'Please use our book database, which you can access using functions to answer the following questions.',\n    },\n    {\n      role: 'user',\n      content:\n        'I really enjoyed reading To Kill a Mockingbird, could you recommend me a book that is similar and tell me why?',\n    },\n  ];\n  console.log(messages[0]);\n  console.log(messages[1]);\n  console.log();\n\n  while (true) {\n    const stream = await openai.chat.completions.create({\n      model: 'gpt-3.5-turbo',\n      messages,\n      functions: functions,\n      stream: true,\n    });\n\n    // Since the stream returns chunks, we need to build up the ChatCompletionMessage object.\n    // We implement this logic in messageReducer, which coalesces deltas into the message.\n    // `lineRewriter()` allows us to rewrite the last output with new text, which is one\n    // way of forwarding the streamed output to a visual interface.\n    let writeLine = lineRewriter();\n    let message = {} as ChatCompletionMessage;\n    for await (const chunk of stream) {\n      message = messageReducer(message, chunk);\n      writeLine(message);\n    }\n    console.log();\n    messages.push(message);\n\n    // If there is no function call, we're done and can exit this loop\n    if (!message.function_call) {\n      return;\n    }\n\n    // If there is a function call, we generate a new message with the role 'function'.\n    const result = await callFunction(message.function_call);\n    const newMessage = {\n      role: 'function' as const,\n      name: message.function_call.name!,\n      content: JSON.stringify(result),\n    };\n    messages.push(newMessage);\n\n    console.log(newMessage);\n    console.log();\n  }\n}\n\nfunction messageReducer(previous: ChatCompletionMessage, item: ChatCompletionChunk): ChatCompletionMessage {\n  const reduce = (acc: any, delta: any) => {\n    acc = { ...acc };\n    for (const [key, value] of Object.entries(delta)) {\n      if (acc[key] === undefined || acc[key] === null) {\n        acc[key] = value;\n      } else if (typeof acc[key] === 'string' && typeof value === 'string') {\n        (acc[key] as string) += value;\n      } else if (typeof acc[key] === 'object' && !Array.isArray(acc[key])) {\n        acc[key] = reduce(acc[key], value);\n      }\n    }\n    return acc;\n  };\n\n  return reduce(previous, item.choices[0]!.delta) as ChatCompletionMessage;\n}\n\nfunction lineRewriter() {\n  let lastMessageLength = 0;\n  return function write(value: any) {\n    process.stdout.cursorTo(0);\n    process.stdout.moveCursor(0, -Math.floor((lastMessageLength - 1) / process.stdout.columns));\n    lastMessageLength = util.formatWithOptions({ colors: false, breakLength: Infinity }, value).length;\n    process.stdout.write(util.formatWithOptions({ colors: true, breakLength: Infinity }, value));\n  };\n}\n\nconst db = [\n  {\n    id: 'a1',\n    name: 'To Kill a Mockingbird',\n    genre: 'historical',\n    description: `Compassionate, dramatic, and deeply moving, \"To Kill A Mockingbird\" takes readers to the roots of human behavior - to innocence and experience, kindness and cruelty, love and hatred, humor and pathos. Now with over 18 million copies in print and translated into forty languages, this regional story by a young Alabama woman claims universal appeal. Harper Lee always considered her book to be a simple love story. Today it is regarded as a masterpiece of American literature.`,\n  },\n  {\n    id: 'a2',\n    name: 'All the Light We Cannot See',\n    genre: 'historical',\n    description: `In a mining town in Germany, Werner Pfennig, an orphan, grows up with his younger sister, enchanted by a crude radio they find that brings them news and stories from places they have never seen or imagined. Werner becomes an expert at building and fixing these crucial new instruments and is enlisted to use his talent to track down the resistance. Deftly interweaving the lives of Marie-Laure and Werner, Doerr illuminates the ways, against all odds, people try to be good to one another.`,\n  },\n  {\n    id: 'a3',\n    name: 'Where the Crawdads Sing',\n    genre: 'historical',\n    description: `For years, rumors of the “Marsh Girl” haunted Barkley Cove, a quiet fishing village. Kya Clark is barefoot and wild; unfit for polite society. So in late 1969, when the popular Chase Andrews is found dead, locals immediately suspect her.\n\nBut Kya is not what they say. A born naturalist with just one day of school, she takes life's lessons from the land, learning the real ways of the world from the dishonest signals of fireflies. But while she has the skills to live in solitude forever, the time comes when she yearns to be touched and loved. Drawn to two young men from town, who are each intrigued by her wild beauty, Kya opens herself to a new and startling world—until the unthinkable happens.`,\n  },\n];\n\nasync function list(genre: string) {\n  return db.filter((item) => item.genre === genre).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function search(name: string) {\n  return db.filter((item) => item.name.includes(name)).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function get(id: string) {\n  return db.find((item) => item.id === id)!;\n}\n\nmain();\n"
  },
  {
    "path": "examples/function-call-stream.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport util from 'util';\nimport OpenAI from 'openai';\nimport {\n  ChatCompletionMessage,\n  ChatCompletionChunk,\n  ChatCompletionMessageParam,\n} from 'openai/resources/chat';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\nconst functions: OpenAI.Chat.ChatCompletionCreateParams.Function[] = [\n  {\n    name: 'list',\n    description: 'list queries books by genre, and returns a list of names of books',\n    parameters: {\n      type: 'object',\n      properties: {\n        genre: { type: 'string', enum: ['mystery', 'nonfiction', 'memoir', 'romance', 'historical'] },\n      },\n    },\n  },\n  {\n    name: 'search',\n    description: 'search queries books by their name and returns a list of book names and their ids',\n    parameters: {\n      type: 'object',\n      properties: {\n        name: { type: 'string' },\n      },\n    },\n  },\n  {\n    name: 'get',\n    description:\n      \"get returns a book's detailed information based on the id of the book. Note that this does not accept names, and only IDs, which you can get by using search.\",\n    parameters: {\n      type: 'object',\n      properties: {\n        id: { type: 'string' },\n      },\n    },\n  },\n];\n\nasync function callFunction(function_call: ChatCompletionMessage.FunctionCall): Promise<any> {\n  const args = JSON.parse(function_call.arguments!);\n  switch (function_call.name) {\n    case 'list':\n      return await list(args['genre']);\n\n    case 'search':\n      return await search(args['name']);\n\n    case 'get':\n      return await get(args['id']);\n\n    default:\n      throw new Error('No function found');\n  }\n}\n\nasync function main() {\n  const messages: ChatCompletionMessageParam[] = [\n    {\n      role: 'system',\n      content:\n        'Please use our book database, which you can access using functions to answer the following questions.',\n    },\n    {\n      role: 'user',\n      content:\n        'I really enjoyed reading To Kill a Mockingbird, could you recommend me a book that is similar and tell me why?',\n    },\n  ];\n  console.log(messages[0]);\n  console.log(messages[1]);\n  console.log();\n\n  while (true) {\n    const stream = await openai.chat.completions.create({\n      model: 'gpt-3.5-turbo',\n      messages,\n      functions: functions,\n      stream: true,\n    });\n\n    // Since the stream returns chunks, we need to build up the ChatCompletionMessage object.\n    // We implement this logic in messageReducer, which coalesces deltas into the message.\n    // `lineRewriter()` allows us to rewrite the last output with new text, which is one\n    // way of forwarding the streamed output to a visual interface.\n    let writeLine = lineRewriter();\n    let message = {} as ChatCompletionMessage;\n    for await (const chunk of stream) {\n      message = messageReducer(message, chunk);\n      writeLine(message);\n    }\n    console.log();\n    messages.push(message);\n\n    // If there is no function call, we're done and can exit this loop\n    if (!message.function_call) {\n      return;\n    }\n\n    // If there is a function call, we generate a new message with the role 'function'.\n    const result = await callFunction(message.function_call);\n    const newMessage = {\n      role: 'function' as const,\n      name: message.function_call.name!,\n      content: JSON.stringify(result),\n    };\n    messages.push(newMessage);\n\n    console.log(newMessage);\n    console.log();\n  }\n}\n\nfunction messageReducer(previous: ChatCompletionMessage, item: ChatCompletionChunk): ChatCompletionMessage {\n  const reduce = (acc: any, delta: any) => {\n    acc = { ...acc };\n    for (const [key, value] of Object.entries(delta)) {\n      if (acc[key] === undefined || acc[key] === null) {\n        acc[key] = value;\n      } else if (typeof acc[key] === 'string' && typeof value === 'string') {\n        (acc[key] as string) += value;\n      } else if (typeof acc[key] === 'object' && !Array.isArray(acc[key])) {\n        acc[key] = reduce(acc[key], value);\n      }\n    }\n    return acc;\n  };\n\n  return reduce(previous, item.choices[0]!.delta) as ChatCompletionMessage;\n}\n\nfunction lineRewriter() {\n  let lastMessageLength = 0;\n  return function write(value: any) {\n    process.stdout.cursorTo(0);\n    process.stdout.moveCursor(0, -Math.floor((lastMessageLength - 1) / process.stdout.columns));\n    lastMessageLength = util.formatWithOptions({ colors: false, breakLength: Infinity }, value).length;\n    process.stdout.write(util.formatWithOptions({ colors: true, breakLength: Infinity }, value));\n  };\n}\n\nconst db = [\n  {\n    id: 'a1',\n    name: 'To Kill a Mockingbird',\n    genre: 'historical',\n    description: `Compassionate, dramatic, and deeply moving, \"To Kill A Mockingbird\" takes readers to the roots of human behavior - to innocence and experience, kindness and cruelty, love and hatred, humor and pathos. Now with over 18 million copies in print and translated into forty languages, this regional story by a young Alabama woman claims universal appeal. Harper Lee always considered her book to be a simple love story. Today it is regarded as a masterpiece of American literature.`,\n  },\n  {\n    id: 'a2',\n    name: 'All the Light We Cannot See',\n    genre: 'historical',\n    description: `In a mining town in Germany, Werner Pfennig, an orphan, grows up with his younger sister, enchanted by a crude radio they find that brings them news and stories from places they have never seen or imagined. Werner becomes an expert at building and fixing these crucial new instruments and is enlisted to use his talent to track down the resistance. Deftly interweaving the lives of Marie-Laure and Werner, Doerr illuminates the ways, against all odds, people try to be good to one another.`,\n  },\n  {\n    id: 'a3',\n    name: 'Where the Crawdads Sing',\n    genre: 'historical',\n    description: `For years, rumors of the “Marsh Girl” haunted Barkley Cove, a quiet fishing village. Kya Clark is barefoot and wild; unfit for polite society. So in late 1969, when the popular Chase Andrews is found dead, locals immediately suspect her.\n\nBut Kya is not what they say. A born naturalist with just one day of school, she takes life's lessons from the land, learning the real ways of the world from the dishonest signals of fireflies. But while she has the skills to live in solitude forever, the time comes when she yearns to be touched and loved. Drawn to two young men from town, who are each intrigued by her wild beauty, Kya opens herself to a new and startling world—until the unthinkable happens.`,\n  },\n];\n\nasync function list(genre: string) {\n  return db.filter((item) => item.genre === genre).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function search(name: string) {\n  return db.filter((item) => item.name.includes(name)).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function get(id: string) {\n  return db.find((item) => item.id === id)!;\n}\n\nmain();\n"
  },
  {
    "path": "examples/function-call.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\nimport { ChatCompletionMessage, ChatCompletionMessageParam } from 'openai/resources/chat';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\nconst functions: OpenAI.Chat.ChatCompletionCreateParams.Function[] = [\n  {\n    name: 'list',\n    description: 'list queries books by genre, and returns a list of names of books',\n    parameters: {\n      type: 'object',\n      properties: {\n        genre: { type: 'string', enum: ['mystery', 'nonfiction', 'memoir', 'romance', 'historical'] },\n      },\n    },\n  },\n  {\n    name: 'search',\n    description: 'search queries books by their name and returns a list of book names and their ids',\n    parameters: {\n      type: 'object',\n      properties: {\n        name: { type: 'string' },\n      },\n    },\n  },\n  {\n    name: 'get',\n    description:\n      \"get returns a book's detailed information based on the id of the book. Note that this does not accept names, and only IDs, which you can get by using search.\",\n    parameters: {\n      type: 'object',\n      properties: {\n        id: { type: 'string' },\n      },\n    },\n  },\n];\n\nasync function callFunction(function_call: ChatCompletionMessage.FunctionCall): Promise<any> {\n  const args = JSON.parse(function_call.arguments!);\n  switch (function_call.name) {\n    case 'list':\n      return await list(args['genre']);\n\n    case 'search':\n      return await search(args['name']);\n\n    case 'get':\n      return await get(args['id']);\n\n    default:\n      throw new Error('No function found');\n  }\n}\n\nasync function main() {\n  const messages: ChatCompletionMessageParam[] = [\n    {\n      role: 'system',\n      content:\n        'Please use our book database, which you can access using functions to answer the following questions.',\n    },\n    {\n      role: 'user',\n      content:\n        'I really enjoyed reading To Kill a Mockingbird, could you recommend me a book that is similar and tell me why?',\n    },\n  ];\n  console.log(messages[0]);\n  console.log(messages[1]);\n  console.log();\n\n  while (true) {\n    const completion = await openai.chat.completions.create({\n      model: 'gpt-3.5-turbo',\n      messages,\n      functions: functions,\n    });\n\n    const message = completion.choices[0]!.message;\n    messages.push(message);\n    console.log(message);\n\n    // If there is no function call, we're done and can exit this loop\n    if (!message.function_call) {\n      return;\n    }\n\n    // If there is a function call, we generate a new message with the role 'function'.\n    const result = await callFunction(message.function_call);\n    const newMessage = {\n      role: 'function' as const,\n      name: message.function_call.name!,\n      content: JSON.stringify(result),\n    };\n    messages.push(newMessage);\n\n    console.log(newMessage);\n    console.log();\n  }\n}\n\nconst db = [\n  {\n    id: 'a1',\n    name: 'To Kill a Mockingbird',\n    genre: 'historical',\n    description: `Compassionate, dramatic, and deeply moving, \"To Kill A Mockingbird\" takes readers to the roots of human behavior - to innocence and experience, kindness and cruelty, love and hatred, humor and pathos. Now with over 18 million copies in print and translated into forty languages, this regional story by a young Alabama woman claims universal appeal. Harper Lee always considered her book to be a simple love story. Today it is regarded as a masterpiece of American literature.`,\n  },\n  {\n    id: 'a2',\n    name: 'All the Light We Cannot See',\n    genre: 'historical',\n    description: `In a mining town in Germany, Werner Pfennig, an orphan, grows up with his younger sister, enchanted by a crude radio they find that brings them news and stories from places they have never seen or imagined. Werner becomes an expert at building and fixing these crucial new instruments and is enlisted to use his talent to track down the resistance. Deftly interweaving the lives of Marie-Laure and Werner, Doerr illuminates the ways, against all odds, people try to be good to one another.`,\n  },\n  {\n    id: 'a3',\n    name: 'Where the Crawdads Sing',\n    genre: 'historical',\n    description: `For years, rumors of the “Marsh Girl” haunted Barkley Cove, a quiet fishing village. Kya Clark is barefoot and wild; unfit for polite society. So in late 1969, when the popular Chase Andrews is found dead, locals immediately suspect her.\n\nBut Kya is not what they say. A born naturalist with just one day of school, she takes life's lessons from the land, learning the real ways of the world from the dishonest signals of fireflies. But while she has the skills to live in solitude forever, the time comes when she yearns to be touched and loved. Drawn to two young men from town, who are each intrigued by her wild beauty, Kya opens herself to a new and startling world—until the unthinkable happens.`,\n  },\n];\n\nasync function list(genre: string) {\n  return db.filter((item) => item.genre === genre).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function search(name: string) {\n  return db.filter((item) => item.name.includes(name)).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function get(id: string) {\n  return db.find((item) => item.id === id)!;\n}\n\nmain();\n"
  },
  {
    "path": "examples/image-stream.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\nimport fs from 'fs';\nimport path from 'path';\n\nconst client = new OpenAI();\n\nconst main = async () => {\n  const stream = await client.images.generate({\n    model: 'gpt-image-1',\n    prompt: 'A cute baby sea otter',\n    n: 1,\n    size: '1024x1024',\n    stream: true,\n    partial_images: 3,\n  });\n\n  for await (const event of stream) {\n    let filename: string;\n    let imageBuffer: Buffer;\n    switch (event.type) {\n      case 'image_generation.partial_image':\n        console.log(`  Partial image ${event.partial_image_index + 1}/3 received`);\n        console.log(`   Size: ${event.b64_json.length} characters (base64)`);\n\n        // Save partial image to file\n        filename = `partial_${event.partial_image_index + 1}.png`;\n        imageBuffer = Buffer.from(event.b64_json, 'base64');\n        fs.writeFileSync(filename, imageBuffer);\n        console.log(`   💾 Saved to: ${path.resolve(filename)}`);\n        break;\n      case 'image_generation.completed':\n        console.log(`\\n✅ Final image completed!`);\n        console.log(`   Size: ${event.b64_json.length} characters (base64)`);\n\n        // Save final image to file\n        filename = 'final_image.png';\n        imageBuffer = Buffer.from(event.b64_json, 'base64');\n        fs.writeFileSync(filename, imageBuffer);\n        console.log(`    Saved to: ${path.resolve(filename)}`);\n        break;\n      default:\n        console.log(`❓ Unknown event: ${event}`);\n    }\n  }\n};\n\nmain().catch((error) => {\n  console.error('Error generating image:', error);\n});\n"
  },
  {
    "path": "examples/logprobs.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\nasync function main() {\n  const stream = await openai.chat.completions\n    .stream({\n      model: 'gpt-4',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n      stream: true,\n      logprobs: true,\n    })\n    .on('logprobs.content.delta', (logprob) => {\n      console.log(logprob);\n    });\n\n  console.dir(await stream.finalChatCompletion(), { depth: null });\n}\n\nmain();\n"
  },
  {
    "path": "examples/package.json",
    "content": "{\n  \"name\": \"openai-examples\",\n  \"version\": \"1.0.0\",\n  \"description\": \"Usage examples for the OpenAI Node.js SDK.\",\n  \"main\": \"index.js\",\n  \"license\": \"MIT\",\n  \"private\": true,\n  \"dependencies\": {\n    \"@azure/identity\": \"^4.2.0\",\n    \"dotenv\": \"^16.4.7\",\n    \"express\": \"^4.18.2\",\n    \"next\": \"^14.2.25\",\n    \"openai\": \"file:..\",\n    \"zod-to-json-schema\": \"^3.21.4\"\n  },\n  \"devDependencies\": {\n    \"@types/body-parser\": \"^1.19.3\",\n    \"@types/express\": \"^4.17.19\",\n    \"@types/web\": \"^0.0.194\"\n  }\n}\n"
  },
  {
    "path": "examples/parsing-run-tools.ts",
    "content": "import OpenAI from 'openai';\nimport z from 'zod/v4'; // Also works for 'zod/v3'\nimport { zodFunction } from 'openai/helpers/zod';\n\nconst Table = z.enum(['orders', 'customers', 'products']);\nconst Column = z.enum([\n  'id',\n  'status',\n  'expected_delivery_date',\n  'delivered_at',\n  'shipped_at',\n  'ordered_at',\n  'canceled_at',\n]);\nconst Operator = z.enum(['=', '>', '<', '<=', '>=', '!=']);\nconst OrderBy = z.enum(['asc', 'desc']);\n\nconst DynamicValue = z.object({\n  column_name: z.string(),\n});\n\nconst Condition = z.object({\n  column: z.string(),\n  operator: Operator,\n  value: z.union([z.string(), z.number(), DynamicValue]),\n});\n\nconst openai = new OpenAI();\n\nasync function main() {\n  const runner = openai.chat.completions\n    .runTools({\n      model: 'gpt-4o-2024-08-06',\n      messages: [{ role: 'user', content: `What are the last 10 orders?` }],\n      stream: true,\n      tools: [\n        zodFunction({\n          name: 'query',\n          function: (args) => {\n            return { table_name: args.table_name, data: fakeOrders };\n          },\n          parameters: z.object({\n            location: z.string(),\n            table_name: Table,\n            columns: z.array(Column),\n            conditions: z.array(Condition),\n            order_by: OrderBy,\n          }),\n        }),\n      ],\n    })\n    .on('tool_calls.function.arguments.done', (props) =>\n      console.log(`parsed function arguments: ${props.parsed_arguments}`),\n    );\n\n  await runner.done();\n\n  console.dir(runner.messages, { depth: 10 });\n}\n\nconst fakeOrders = [\n  {\n    orderId: 'ORD-001',\n    customerName: 'Alice Johnson',\n    products: [{ name: 'Wireless Headphones', quantity: 1, price: 89.99 }],\n    totalPrice: 89.99,\n    orderDate: '2024-08-02',\n  },\n  {\n    orderId: 'ORD-002',\n    customerName: 'Bob Smith',\n    products: [\n      { name: 'Smartphone Case', quantity: 2, price: 19.99 },\n      { name: 'Screen Protector', quantity: 1, price: 9.99 },\n    ],\n    totalPrice: 49.97,\n    orderDate: '2024-08-03',\n  },\n  {\n    orderId: 'ORD-003',\n    customerName: 'Carol Davis',\n    products: [\n      { name: 'Laptop', quantity: 1, price: 999.99 },\n      { name: 'Mouse', quantity: 1, price: 29.99 },\n    ],\n    totalPrice: 1029.98,\n    orderDate: '2024-08-04',\n  },\n  {\n    orderId: 'ORD-004',\n    customerName: 'David Wilson',\n    products: [{ name: 'Coffee Maker', quantity: 1, price: 79.99 }],\n    totalPrice: 79.99,\n    orderDate: '2024-08-05',\n  },\n  {\n    orderId: 'ORD-005',\n    customerName: 'Eva Brown',\n    products: [\n      { name: 'Fitness Tracker', quantity: 1, price: 129.99 },\n      { name: 'Water Bottle', quantity: 2, price: 14.99 },\n    ],\n    totalPrice: 159.97,\n    orderDate: '2024-08-06',\n  },\n  {\n    orderId: 'ORD-006',\n    customerName: 'Frank Miller',\n    products: [\n      { name: 'Gaming Console', quantity: 1, price: 499.99 },\n      { name: 'Controller', quantity: 2, price: 59.99 },\n    ],\n    totalPrice: 619.97,\n    orderDate: '2024-08-07',\n  },\n  {\n    orderId: 'ORD-007',\n    customerName: 'Grace Lee',\n    products: [{ name: 'Bluetooth Speaker', quantity: 1, price: 69.99 }],\n    totalPrice: 69.99,\n    orderDate: '2024-08-08',\n  },\n  {\n    orderId: 'ORD-008',\n    customerName: 'Henry Taylor',\n    products: [\n      { name: 'Smartwatch', quantity: 1, price: 199.99 },\n      { name: 'Watch Band', quantity: 2, price: 24.99 },\n    ],\n    totalPrice: 249.97,\n    orderDate: '2024-08-09',\n  },\n  {\n    orderId: 'ORD-009',\n    customerName: 'Isla Garcia',\n    products: [\n      { name: 'Tablet', quantity: 1, price: 349.99 },\n      { name: 'Tablet Case', quantity: 1, price: 29.99 },\n      { name: 'Stylus', quantity: 1, price: 39.99 },\n    ],\n    totalPrice: 419.97,\n    orderDate: '2024-08-10',\n  },\n  {\n    orderId: 'ORD-010',\n    customerName: 'Jack Robinson',\n    products: [{ name: 'Wireless Charger', quantity: 2, price: 34.99 }],\n    totalPrice: 69.98,\n    orderDate: '2024-08-11',\n  },\n];\n\nmain();\n"
  },
  {
    "path": "examples/parsing-stream.ts",
    "content": "import { zodResponseFormat } from 'openai/helpers/zod';\nimport OpenAI from 'openai/index';\nimport { z } from 'zod/v4'; // Also works for 'zod/v3'\n\nconst Step = z.object({\n  explanation: z.string(),\n  output: z.string(),\n});\n\nconst MathResponse = z.object({\n  steps: z.array(Step),\n  final_answer: z.string(),\n});\n\nasync function main() {\n  const client = new OpenAI();\n\n  const stream = client.chat.completions\n    .stream({\n      model: 'gpt-4o-2024-08-06',\n      messages: [\n        {\n          role: 'user',\n          content: `What's the weather like in SF?`,\n        },\n      ],\n      response_format: zodResponseFormat(MathResponse, 'math_response'),\n    })\n    .on('refusal.delta', ({ delta }) => {\n      process.stdout.write(delta);\n    })\n    .on('refusal.done', () => console.log('\\n\\nrequest refused 😱'))\n    .on('content.delta', ({ snapshot, parsed }) => {\n      console.log('content:', snapshot);\n      console.log('parsed:', parsed);\n      console.log();\n    })\n    .on('content.done', (props) => {\n      if (props.parsed) {\n        console.log('\\n\\nfinished parsing!');\n        console.log(`answer: ${props.parsed.final_answer}`);\n      }\n    });\n\n  await stream.done();\n\n  const completion = await stream.finalChatCompletion();\n\n  console.dir(completion, { depth: 5 });\n\n  const message = completion.choices[0]?.message;\n  if (message?.parsed) {\n    console.log(message.parsed.steps);\n  }\n}\n\nmain();\n"
  },
  {
    "path": "examples/parsing-tools-stream.ts",
    "content": "import { zodFunction } from 'openai/helpers/zod';\nimport OpenAI from 'openai/index';\nimport { z } from 'zod/v4'; // Also works for 'zod/v3'\n\nconst GetWeatherArgs = z.object({\n  city: z.string(),\n  country: z.string(),\n  units: z.enum(['c', 'f']).default('c'),\n});\n\nasync function main() {\n  const client = new OpenAI();\n  const refusal = process.argv.includes('refusal');\n\n  const stream = client.chat.completions\n    .stream({\n      model: 'gpt-4o-2024-08-06',\n      messages: [\n        {\n          role: 'user',\n          content: refusal ? 'How do I make anthrax?' : `What's the weather like in SF?`,\n        },\n      ],\n      tools: [zodFunction({ name: 'get_weather', parameters: GetWeatherArgs })],\n    })\n    .on('tool_calls.function.arguments.delta', (props) =>\n      console.log('tool_calls.function.arguments.delta', props),\n    )\n    .on('tool_calls.function.arguments.done', (props) =>\n      console.log('tool_calls.function.arguments.done', props),\n    )\n    .on('refusal.delta', ({ delta }) => {\n      process.stdout.write(delta);\n    })\n    .on('refusal.done', () => console.log('\\n\\nrequest refused 😱'));\n\n  const completion = await stream.finalChatCompletion();\n\n  console.log('final completion:');\n  console.dir(completion, { depth: 10 });\n}\n\nmain();\n"
  },
  {
    "path": "examples/parsing-tools.ts",
    "content": "import { zodFunction } from 'openai/helpers/zod';\nimport OpenAI from 'openai/index';\nimport { z } from 'zod/v4'; // Also works for 'zod/v3'\n\nconst Table = z.enum(['orders', 'customers', 'products']);\n\nconst Column = z.enum([\n  'id',\n  'status',\n  'expected_delivery_date',\n  'delivered_at',\n  'shipped_at',\n  'ordered_at',\n  'canceled_at',\n]);\n\nconst Operator = z.enum(['=', '>', '<', '<=', '>=', '!=']);\n\nconst OrderBy = z.enum(['asc', 'desc']);\n\nconst DynamicValue = z.object({\n  column_name: z.string(),\n});\n\nconst Condition = z.object({\n  column: z.string(),\n  operator: Operator,\n  value: z.union([z.string(), z.number(), DynamicValue]),\n});\n\nconst Query = z.object({\n  table_name: Table,\n  columns: z.array(Column),\n  conditions: z.array(Condition),\n  order_by: OrderBy,\n});\n\nasync function main() {\n  const client = new OpenAI();\n\n  const completion = await client.chat.completions.parse({\n    model: 'gpt-4o-2024-08-06',\n    messages: [\n      {\n        role: 'system',\n        content:\n          'You are a helpful assistant. The current date is August 6, 2024. You help users query for the data they are looking for by calling the query function.',\n      },\n      {\n        role: 'user',\n        content:\n          'look up all my orders in november of last year that were fulfilled but not delivered on time',\n      },\n    ],\n    tools: [zodFunction({ name: 'query', parameters: Query })],\n  });\n  console.dir(completion, { depth: 10 });\n\n  const toolCall = completion.choices[0]?.message.tool_calls?.[0];\n  if (toolCall) {\n    const args = toolCall.function.parsed_arguments as z.infer<typeof Query>;\n    console.log(args);\n    console.log(args.table_name);\n  }\n}\n\nmain();\n"
  },
  {
    "path": "examples/parsing.ts",
    "content": "import { zodResponseFormat } from 'openai/helpers/zod';\nimport OpenAI from 'openai/index';\nimport { z } from 'zod/v4'; // Also works for 'zod/v3'\n\nconst Step = z.object({\n  explanation: z.string(),\n  output: z.string(),\n});\n\nconst MathResponse = z.object({\n  steps: z.array(Step),\n  final_answer: z.string(),\n});\n\nasync function main() {\n  const client = new OpenAI();\n\n  const completion = await client.chat.completions.parse({\n    model: 'gpt-4o-2024-08-06',\n    messages: [\n      { role: 'system', content: 'You are a helpful math tutor.' },\n      { role: 'user', content: 'solve 8x + 31 = 2' },\n    ],\n    response_format: zodResponseFormat(MathResponse, 'math_response'),\n  });\n\n  console.dir(completion, { depth: 5 });\n\n  const message = completion.choices[0]?.message;\n  if (message?.parsed) {\n    console.log(message.parsed.steps);\n    console.log(`answer: ${message.parsed.final_answer}`);\n  }\n}\n\nmain();\n"
  },
  {
    "path": "examples/raw-response.ts",
    "content": "#!/usr/bin/env -S yarn tsn -T\n\nimport OpenAI from 'openai';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst client = new OpenAI();\n\nasync function main() {\n  // getting just raw Response:\n  {\n    const response = await client.completions\n      .create({\n        prompt: 'Say this is a test',\n        model: 'gpt-3.5-turbo-instruct',\n      })\n      .asResponse();\n    console.log(`response headers: `, Object.fromEntries(response.headers.entries()));\n    console.log(`response json: `, await response.json());\n  }\n\n  // getting the usual return value plus raw Response:\n  {\n    const { data: completion, response } = await client.completions\n      .create({\n        prompt: 'Say this is a test',\n        model: 'gpt-3.5-turbo-instruct',\n      })\n      .withResponse();\n    console.log(`response headers: `, Object.fromEntries(response.headers.entries()));\n    console.log(`completion: `, completion);\n  }\n}\n\nmain().catch(console.error);\n"
  },
  {
    "path": "examples/realtime/websocket.ts",
    "content": "import { OpenAIRealtimeWebSocket } from 'openai/realtime/websocket';\n\nasync function main() {\n  const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-realtime' });\n\n  // access the underlying `ws.WebSocket` instance\n  rt.socket.addEventListener('open', () => {\n    console.log('Connection opened!');\n    rt.send({\n      type: 'session.update',\n      session: {\n        output_modalities: ['text'],\n        model: 'gpt-4o-realtime-preview',\n        type: 'realtime',\n      },\n    });\n\n    rt.send({\n      type: 'conversation.item.create',\n      item: {\n        type: 'message',\n        role: 'user',\n        content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],\n      },\n    });\n\n    rt.send({ type: 'response.create' });\n  });\n\n  rt.on('error', (err) => {\n    // in a real world scenario this should be logged somewhere as you\n    // likely want to continue processing events regardless of any errors\n    throw err;\n  });\n\n  rt.on('session.created', (event) => {\n    console.log('session created!', event.session);\n    console.log();\n  });\n\n  rt.on('response.output_text.delta', (event) => process.stdout.write(event.delta));\n  rt.on('response.output_text.done', () => console.log());\n\n  rt.on('response.done', () => rt.close());\n\n  rt.socket.addEventListener('close', () => console.log('\\nConnection closed!'));\n}\n\nmain();\n"
  },
  {
    "path": "examples/realtime/ws.ts",
    "content": "import { OpenAIRealtimeWS } from 'openai/realtime/ws';\n\nasync function main() {\n  const rt = new OpenAIRealtimeWS({ model: 'gpt-realtime' });\n\n  // access the underlying `ws.WebSocket` instance\n  rt.socket.on('open', () => {\n    console.log('Connection opened!');\n    rt.send({\n      type: 'session.update',\n      session: {\n        output_modalities: ['text'],\n        model: 'gpt-4o-realtime-preview',\n        type: 'realtime',\n      },\n    });\n\n    rt.send({\n      type: 'conversation.item.create',\n      item: {\n        type: 'message',\n        role: 'user',\n        content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],\n      },\n    });\n\n    rt.send({ type: 'response.create' });\n  });\n\n  rt.on('error', (err) => {\n    // in a real world scenario this should be logged somewhere as you\n    // likely want to continue processing events regardless of any errors\n    throw err;\n  });\n\n  rt.on('session.created', (event) => {\n    console.log('session created!', event.session);\n    console.log();\n  });\n\n  rt.on('response.output_text.delta', (event) => process.stdout.write(event.delta));\n  rt.on('response.output_text.done', () => console.log());\n\n  rt.on('response.done', () => rt.close());\n\n  rt.socket.on('close', () => console.log('\\nConnection closed!'));\n}\n\nmain();\n"
  },
  {
    "path": "examples/responses/stream.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\n\nconst openai = new OpenAI();\n\nasync function main() {\n  const runner = openai.responses\n    .stream({\n      model: 'gpt-4o-2024-08-06',\n      input: 'solve 8x + 31 = 2',\n    })\n    .on('event', (event) => console.log(event))\n    .on('response.output_text.delta', (diff) => process.stdout.write(diff.delta));\n\n  for await (const event of runner) {\n    console.log('event', event);\n  }\n\n  const result = await runner.finalResponse();\n  console.log(result);\n}\n\nmain();\n"
  },
  {
    "path": "examples/responses/stream_background.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\n\nconst openai = new OpenAI();\n\nasync function main() {\n  const runner = openai.responses.stream({\n    model: 'gpt-4o-2024-08-06',\n    input: 'solve 8x + 31 = 2',\n    background: true,\n  });\n\n  let id: string | null = null;\n\n  for await (const event of runner) {\n    if (event.type == 'response.created') {\n      id = event.response.id;\n    }\n\n    console.log('event', event);\n    if (event.sequence_number == 10) {\n      break;\n    }\n  }\n\n  console.log('Interrupted. Continuing...');\n\n  const runner2 = openai.responses.stream({\n    response_id: id!,\n    starting_after: 10,\n  });\n\n  for await (const event of runner2) {\n    console.log('event', event);\n  }\n\n  const result = await runner2.finalResponse();\n  console.log(result);\n}\n\nmain();\n"
  },
  {
    "path": "examples/responses/streaming-tools.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport { OpenAI } from 'openai';\nimport { zodResponsesFunction } from 'openai/helpers/zod';\nimport { z } from 'zod/v4'; // Also works for 'zod/v3'\n\nconst Table = z.enum(['orders', 'customers', 'products']);\nconst Column = z.enum([\n  'id',\n  'status',\n  'expected_delivery_date',\n  'delivered_at',\n  'shipped_at',\n  'ordered_at',\n  'canceled_at',\n]);\nconst Operator = z.enum(['=', '>', '<', '<=', '>=', '!=']);\nconst OrderBy = z.enum(['asc', 'desc']);\nconst DynamicValue = z.object({\n  column_name: Column,\n});\n\nconst Condition = z.object({\n  column: Column,\n  operator: Operator,\n  value: z.union([z.string(), z.number(), DynamicValue]),\n});\n\nconst Query = z.object({\n  table_name: Table,\n  columns: z.array(Column),\n  conditions: z.array(Condition),\n  order_by: OrderBy,\n});\n\nasync function main() {\n  const client = new OpenAI();\n\n  const tool = zodResponsesFunction({ name: 'query', parameters: Query });\n\n  const stream = client.responses.stream({\n    model: 'gpt-4o-2024-08-06',\n    input: 'look up all my orders in november of last year that were fulfilled but not delivered on time',\n    tools: [tool],\n  });\n\n  for await (const event of stream) {\n    console.dir(event, { depth: 10 });\n  }\n}\n\nmain();\n"
  },
  {
    "path": "examples/responses/structured-outputs-tools.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport { OpenAI } from 'openai';\nimport { zodResponsesFunction } from 'openai/helpers/zod';\nimport { z } from 'zod/v4'; // Also works for 'zod/v3'\n\nconst Table = z.enum(['orders', 'customers', 'products']);\nconst Column = z.enum([\n  'id',\n  'status',\n  'expected_delivery_date',\n  'delivered_at',\n  'shipped_at',\n  'ordered_at',\n  'canceled_at',\n]);\nconst Operator = z.enum(['=', '>', '<', '<=', '>=', '!=']);\nconst OrderBy = z.enum(['asc', 'desc']);\nconst DynamicValue = z.object({\n  column_name: Column,\n});\n\nconst Condition = z.object({\n  column: Column,\n  operator: Operator,\n  value: z.union([z.string(), z.number(), DynamicValue]),\n});\n\nconst Query = z.object({\n  table_name: Table,\n  columns: z.array(Column),\n  conditions: z.array(Condition),\n  order_by: OrderBy,\n});\n\nasync function main() {\n  const client = new OpenAI();\n\n  const tool = zodResponsesFunction({ name: 'query', parameters: Query });\n\n  const rsp = await client.responses.parse({\n    model: 'gpt-4o-2024-08-06',\n    input: 'look up all my orders in november of last year that were fulfilled but not delivered on time',\n    tools: [tool],\n  });\n\n  console.log(rsp);\n\n  const functionCall = rsp.output[0]!;\n\n  if (functionCall.type !== 'function_call') {\n    throw new Error('Expected function call');\n  }\n\n  const query = functionCall.parsed_arguments;\n\n  console.log(query);\n}\n\nmain();\n"
  },
  {
    "path": "examples/responses/structured-outputs.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport { OpenAI } from 'openai';\nimport { zodTextFormat } from 'openai/helpers/zod';\nimport { z } from 'zod/v4'; // Also works for 'zod/v3'\n\nconst Step = z.object({\n  explanation: z.string(),\n  output: z.string(),\n});\n\nconst MathResponse = z.object({\n  steps: z.array(Step),\n  final_answer: z.string(),\n});\n\nconst client = new OpenAI();\n\nasync function main() {\n  const rsp = await client.responses.parse({\n    input: 'solve 8x + 31 = 2',\n    model: 'gpt-4o-2024-08-06',\n    text: {\n      format: zodTextFormat(MathResponse, 'math_response'),\n    },\n  });\n\n  console.log(rsp.output_parsed);\n  console.log('answer: ', rsp.output_parsed?.final_answer);\n}\n\nmain().catch(console.error);\n"
  },
  {
    "path": "examples/responses/websocket.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\nimport type {\n  FunctionTool,\n  ResponseInput,\n  ResponseInputItem,\n  ResponsesClientEvent,\n  ResponsesServerEvent,\n} from 'openai/resources/responses/responses';\nimport { ResponsesWS } from 'openai/resources/responses/ws';\nimport type { WebSocket } from 'ws';\n\ntype ToolName = 'get_sku_inventory' | 'get_supplier_eta' | 'get_quality_alerts';\ntype ToolChoice = NonNullable<ResponsesClientEvent['tool_choice']>;\n\ntype DemoTurn = {\n  tool_name: ToolName;\n  prompt: string;\n};\n\ntype SKUArguments = {\n  sku: string;\n};\n\ntype SKUInventoryOutput = {\n  sku: string;\n  warehouse: string;\n  on_hand_units: number;\n  reserved_units: number;\n  reorder_point: number;\n  safety_stock: number;\n};\n\ntype SupplierShipment = {\n  shipment_id: string;\n  eta_date: string;\n  quantity: number;\n  risk: string;\n};\n\ntype SupplierETAOutput = {\n  sku: string;\n  supplier_shipments: Array<SupplierShipment>;\n};\n\ntype QualityAlert = {\n  alert_id: string;\n  status: string;\n  severity: string;\n  summary: string;\n};\n\ntype QualityAlertsOutput = {\n  sku: string;\n  alerts: Array<QualityAlert>;\n};\n\ntype ToolOutput = SKUInventoryOutput | SupplierETAOutput | QualityAlertsOutput;\n\ntype FunctionCallRequest = {\n  name: ToolName;\n  argumentsJSON: string;\n  callID: string;\n};\n\ntype RunResponseResult = {\n  text: string;\n  responseID: string;\n  functionCalls: Array<FunctionCallRequest>;\n};\n\ntype RunTurnResult = {\n  assistantText: string;\n  responseID: string;\n};\n\ntype CLIArgs = {\n  model: string;\n  useBetaHeader: boolean;\n  showEvents: boolean;\n  showToolIO: boolean;\n};\n\nconst BETA_HEADER_VALUE = 'responses_websockets=2026-02-06';\n\nconst TOOLS: Array<FunctionTool> = [\n  {\n    type: 'function',\n    name: 'get_sku_inventory',\n    description: 'Return froge pond inventory details for a SKU.',\n    strict: true,\n    parameters: {\n      type: 'object',\n      properties: {\n        sku: {\n          type: 'string',\n          description: 'Stock-keeping unit identifier, such as sku-froge-lily-pad-deluxe.',\n        },\n      },\n      required: ['sku'],\n      additionalProperties: false,\n    },\n  },\n  {\n    type: 'function',\n    name: 'get_supplier_eta',\n    description: 'Return tadpole supplier restock ETA data for a SKU.',\n    strict: true,\n    parameters: {\n      type: 'object',\n      properties: {\n        sku: {\n          type: 'string',\n          description: 'Stock-keeping unit identifier, such as sku-froge-lily-pad-deluxe.',\n        },\n      },\n      required: ['sku'],\n      additionalProperties: false,\n    },\n  },\n  {\n    type: 'function',\n    name: 'get_quality_alerts',\n    description: 'Return recent froge quality alerts for a SKU.',\n    strict: true,\n    parameters: {\n      type: 'object',\n      properties: {\n        sku: {\n          type: 'string',\n          description: 'Stock-keeping unit identifier, such as sku-froge-lily-pad-deluxe.',\n        },\n      },\n      required: ['sku'],\n      additionalProperties: false,\n    },\n  },\n];\n\nconst DEMO_TURNS: Array<DemoTurn> = [\n  {\n    tool_name: 'get_sku_inventory',\n    prompt:\n      \"Use get_sku_inventory for sku='sku-froge-lily-pad-deluxe' and summarize current pond stock health in one sentence.\",\n  },\n  {\n    tool_name: 'get_supplier_eta',\n    prompt: 'Now use get_supplier_eta for the same SKU and summarize restock ETA and tadpole shipment risk.',\n  },\n  {\n    tool_name: 'get_quality_alerts',\n    prompt:\n      'Finally use get_quality_alerts for the same SKU and summarize unresolved froge quality concerns in one short paragraph.',\n  },\n];\n\nconst parseArgs = (argv: Array<string>): CLIArgs => {\n  let model = 'gpt-5.2';\n  let useBetaHeader = false;\n  let showEvents = false;\n  let showToolIO = false;\n\n  for (let index = 0; index < argv.length; index += 1) {\n    const arg = argv[index];\n    if (typeof arg !== 'string') {\n      throw new Error('Unexpected missing CLI argument');\n    }\n\n    if (arg === '--model') {\n      const next = argv[index + 1];\n      if (!next) {\n        throw new Error('--model requires a value');\n      }\n      model = next;\n      index += 1;\n      continue;\n    }\n\n    if (arg.startsWith('--model=')) {\n      model = arg.slice('--model='.length);\n      continue;\n    }\n\n    if (arg === '--use-beta-header') {\n      useBetaHeader = true;\n      continue;\n    }\n\n    if (arg === '--show-events') {\n      showEvents = true;\n      continue;\n    }\n\n    if (arg === '--show-tool-io') {\n      showToolIO = true;\n      continue;\n    }\n\n    throw new Error(`Unknown argument: ${arg}`);\n  }\n\n  return { model, useBetaHeader, showEvents, showToolIO };\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => {\n  return typeof value === 'object' && value !== null;\n};\n\nconst parseToolName = (name: string): ToolName => {\n  if (name === 'get_sku_inventory' || name === 'get_supplier_eta' || name === 'get_quality_alerts') {\n    return name;\n  }\n  throw new Error(`Unsupported tool requested: ${name}`);\n};\n\nconst parseSKUArguments = (rawArguments: string): SKUArguments => {\n  const parsed: unknown = JSON.parse(rawArguments);\n  if (!isRecord(parsed)) {\n    throw new Error(`Tool arguments must be a JSON object: ${rawArguments}`);\n  }\n\n  const skuValue = parsed['sku'];\n  if (typeof skuValue !== 'string') {\n    throw new Error(`Tool arguments must include a string \\`sku\\`: ${rawArguments}`);\n  }\n\n  return { sku: skuValue };\n};\n\nconst callTool = (name: ToolName, args: SKUArguments): ToolOutput => {\n  const { sku } = args;\n\n  if (name === 'get_sku_inventory') {\n    return {\n      sku,\n      warehouse: 'pond-west-1',\n      on_hand_units: 84,\n      reserved_units: 26,\n      reorder_point: 60,\n      safety_stock: 40,\n    };\n  }\n\n  if (name === 'get_supplier_eta') {\n    return {\n      sku,\n      supplier_shipments: [\n        {\n          shipment_id: 'frog_ship_2201',\n          eta_date: '2026-02-24',\n          quantity: 180,\n          risk: 'low',\n        },\n        {\n          shipment_id: 'frog_ship_2205',\n          eta_date: '2026-03-03',\n          quantity: 220,\n          risk: 'medium',\n        },\n      ],\n    };\n  }\n\n  return {\n    sku,\n    alerts: [\n      {\n        alert_id: 'frog_qa_781',\n        status: 'open',\n        severity: 'high',\n        summary: 'Lily-pad coating chipping in lot LP-42',\n      },\n      {\n        alert_id: 'frog_qa_795',\n        status: 'in_progress',\n        severity: 'medium',\n        summary: 'Pond-crate scuff rate above threshold',\n      },\n      {\n        alert_id: 'frog_qa_802',\n        status: 'resolved',\n        severity: 'low',\n        summary: 'Froge label alignment issue corrected',\n      },\n    ],\n  };\n};\n\nconst ensureSocketOpen = async (socket: WebSocket): Promise<void> => {\n  if (socket.readyState === socket.OPEN) {\n    return;\n  }\n\n  await new Promise<void>((resolve, reject) => {\n    const onOpen = (): void => {\n      cleanup();\n      resolve();\n    };\n\n    const onError = (err: Error): void => {\n      cleanup();\n      reject(err);\n    };\n\n    const onClose = (): void => {\n      cleanup();\n      reject(new Error('WebSocket closed before opening.'));\n    };\n\n    const cleanup = (): void => {\n      socket.off('open', onOpen);\n      socket.off('error', onError);\n      socket.off('close', onClose);\n    };\n\n    socket.on('open', onOpen);\n    socket.on('error', onError);\n    socket.on('close', onClose);\n  });\n};\n\nconst runResponse = async ({\n  ws,\n  model,\n  previousResponseID,\n  inputPayload,\n  toolChoice,\n  showEvents,\n}: {\n  ws: ResponsesWS;\n  model: string;\n  previousResponseID: string | null;\n  inputPayload: string | ResponseInput;\n  toolChoice: ToolChoice;\n  showEvents: boolean;\n}): Promise<RunResponseResult> => {\n  return await new Promise<RunResponseResult>((resolve, reject) => {\n    const textParts: Array<string> = [];\n    const functionCalls: Array<FunctionCallRequest> = [];\n\n    const finish = (responseID: string): void => {\n      cleanup();\n      resolve({ text: textParts.join(''), responseID, functionCalls });\n    };\n\n    const fail = (error: Error): void => {\n      cleanup();\n      reject(error);\n    };\n\n    const onSocketError = (error: Error): void => {\n      fail(error);\n    };\n\n    const onEvent = (event: ResponsesServerEvent): void => {\n      try {\n        if (event.type === 'response.output_text.delta') {\n          textParts.push(event.delta);\n          return;\n        }\n\n        if (event.type === 'response.output_item.done' && event.item.type === 'function_call') {\n          functionCalls.push({\n            name: parseToolName(event.item.name),\n            argumentsJSON: event.item.arguments,\n            callID: event.item.call_id,\n          });\n          return;\n        }\n\n        if (event.type === 'error') {\n          throw new Error(event.message || 'WebSocket error event');\n        }\n\n        if (event.type === 'response.completed') {\n          if (showEvents) {\n            console.log(`[${event.type}]`);\n          }\n          finish(event.response.id);\n          return;\n        }\n\n        if (event.type === 'response.failed' || event.type === 'response.incomplete') {\n          throw new Error(`Response ended with ${event.type} (id=${event.response.id})`);\n        }\n\n        if (showEvents) {\n          console.log(`[${event.type}]`);\n        }\n      } catch (error) {\n        fail(error instanceof Error ? error : new Error(String(error)));\n      }\n    };\n\n    const cleanup = (): void => {\n      ws.off('event', onEvent);\n      ws.off('error', onSocketError);\n    };\n\n    ws.on('event', onEvent);\n    ws.on('error', onSocketError);\n\n    const createEvent: ResponsesClientEvent = {\n      type: 'response.create',\n      model,\n      input: inputPayload,\n      stream: true,\n      previous_response_id: previousResponseID,\n      tools: TOOLS,\n      tool_choice: toolChoice,\n    };\n    ws.send(createEvent);\n  });\n};\n\nconst runTurn = async ({\n  ws,\n  model,\n  previousResponseID,\n  turnPrompt,\n  forcedToolName,\n  showEvents,\n  showToolIO,\n}: {\n  ws: ResponsesWS;\n  model: string;\n  previousResponseID: string | null;\n  turnPrompt: string;\n  forcedToolName: ToolName;\n  showEvents: boolean;\n  showToolIO: boolean;\n}): Promise<RunTurnResult> => {\n  const accumulatedTextParts: Array<string> = [];\n\n  let currentInput: string | ResponseInput = turnPrompt;\n  let currentToolChoice: ToolChoice = { type: 'function', name: forcedToolName };\n  let currentPreviousResponseID = previousResponseID;\n\n  while (true) {\n    const responseResult = await runResponse({\n      ws,\n      model,\n      previousResponseID: currentPreviousResponseID,\n      inputPayload: currentInput,\n      toolChoice: currentToolChoice,\n      showEvents,\n    });\n\n    if (responseResult.text) {\n      accumulatedTextParts.push(responseResult.text);\n    }\n\n    currentPreviousResponseID = responseResult.responseID;\n    if (responseResult.functionCalls.length === 0) {\n      break;\n    }\n\n    const toolOutputs: ResponseInput = [];\n\n    for (const functionCall of responseResult.functionCalls) {\n      const parsedArguments = parseSKUArguments(functionCall.argumentsJSON);\n      const outputPayload = callTool(functionCall.name, parsedArguments);\n\n      if (showToolIO) {\n        console.log(`[tool_call] ${functionCall.name}(${functionCall.argumentsJSON})`);\n        console.log(`[tool_output] ${JSON.stringify(outputPayload)}`);\n      }\n\n      const functionCallOutput: ResponseInputItem.FunctionCallOutput = {\n        type: 'function_call_output',\n        call_id: functionCall.callID,\n        output: JSON.stringify(outputPayload),\n      };\n      toolOutputs.push(functionCallOutput);\n    }\n\n    currentInput = toolOutputs;\n    currentToolChoice = 'none';\n  }\n\n  return {\n    assistantText: accumulatedTextParts.join('').trim(),\n    responseID: currentPreviousResponseID,\n  };\n};\n\nconst main = async (): Promise<void> => {\n  const args = parseArgs(process.argv.slice(2));\n\n  const client = new OpenAI();\n  const ws = new ResponsesWS(client, {\n    headers: args.useBetaHeader ? { 'OpenAI-Beta': BETA_HEADER_VALUE } : undefined,\n  });\n\n  await ensureSocketOpen(ws.socket);\n\n  try {\n    let previousResponseID: string | null = null;\n    for (const [index, turn] of DEMO_TURNS.entries()) {\n      console.log(`\\n=== Turn ${index + 1} ===`);\n      console.log(`User: ${turn.prompt}`);\n\n      const turnResult = await runTurn({\n        ws,\n        model: args.model,\n        previousResponseID,\n        turnPrompt: turn.prompt,\n        forcedToolName: turn.tool_name,\n        showEvents: args.showEvents,\n        showToolIO: args.showToolIO,\n      });\n\n      previousResponseID = turnResult.responseID;\n      console.log(`Assistant: ${turnResult.assistantText}`);\n    }\n  } finally {\n    ws.close();\n  }\n};\n\nmain().catch((error: unknown) => {\n  console.error(error);\n  process.exitCode = 1;\n});\n"
  },
  {
    "path": "examples/speech-to-text.ts",
    "content": "import OpenAI from 'openai';\nimport { recordAudio } from 'openai/helpers/audio';\n\nconst openai = new OpenAI();\n\nasync function main(): Promise<void> {\n  console.log('Recording for 5 seconds...');\n  const response = await recordAudio({ timeout: 5000, device: 4 });\n\n  console.log('Transcribing...');\n  const transcription = await openai.audio.transcriptions.create({\n    file: response,\n    model: 'whisper-1',\n  });\n\n  console.log(transcription.text);\n}\n\nmain().catch(console.error);\n"
  },
  {
    "path": "examples/stream-to-client-browser.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\n/**\n * This file is intended be run from the command-line with Node\n * for easy demo purposes, but simulating use in the browser.\n *\n * To run it in a browser application, copy/paste it into a frontend application,\n * remove the 'node-fetch' import, and replace `process.stdout.write` with\n * a console.log or UI display.\n */\nimport { ChatCompletionStream } from 'openai/lib/ChatCompletionStream';\n\nfetch('http://localhost:3000', {\n  method: 'POST',\n  body: 'Tell me why dogs are better than cats',\n  headers: { 'Content-Type': 'text/plain' },\n}).then(async (res) => {\n  // @ts-ignore ReadableStream on different environments can be strange\n  const runner = ChatCompletionStream.fromReadableStream(res.body);\n\n  runner.on('content', (delta, snapshot) => {\n    process.stdout.write(delta);\n    // or, in a browser, you might display like this:\n    // document.body.innerText += delta; // or:\n    // document.body.innerText = snapshot;\n  });\n\n  console.dir(await runner.finalChatCompletion(), { depth: null });\n});\n"
  },
  {
    "path": "examples/stream-to-client-express.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\n// This file demonstrates how to stream from the server the chunks as\n// a new-line separated JSON-encoded stream.\n\nimport OpenAI from 'openai';\nimport express, { Request, Response } from 'express';\n\nconst openai = new OpenAI();\nconst app = express();\n\napp.use(express.text());\n\n// This endpoint can be called with:\n//\n//   curl 127.0.0.1:3000 -N -X POST -H 'Content-Type: text/plain' \\\n//     --data 'Can you explain why dogs are better than cats?'\n//\n// Or consumed with fetch:\n//\n//   fetch('http://localhost:3000', {\n//     method: 'POST',\n//     body: 'Tell me why dogs are better than cats',\n//   }).then(async res => {\n//     const runner = ChatCompletionStreamingRunner.fromReadableStream(res)\n//   })\n//\n// See examples/stream-to-client-browser.ts for a more complete example.\napp.post('/', async (req: Request, res: Response) => {\n  try {\n    console.log('Received request:', req.body);\n\n    const stream = openai.chat.completions.stream({\n      model: 'gpt-3.5-turbo',\n      stream: true,\n      messages: [{ role: 'user', content: req.body }],\n    });\n\n    res.header('Content-Type', 'text/plain');\n    for await (const chunk of stream.toReadableStream()) {\n      res.write(chunk);\n    }\n\n    res.end();\n  } catch (e) {\n    console.error(e);\n  }\n});\n\napp.listen('3000', () => {\n  console.log('Started proxy express server');\n});\n"
  },
  {
    "path": "examples/stream-to-client-next.ts",
    "content": "import OpenAI from 'openai';\nimport type { NextApiRequest, NextApiResponse } from 'next';\n\n// This file demonstrates how to stream from a Next.JS server as\n// a new-line separated JSON-encoded stream. This file cannot be run\n// without Next.JS scaffolding.\n\nexport const runtime = 'edge';\n\n// This endpoint can be called with:\n//\n//   curl 127.0.0.1:3000 -N -X POST -H 'Content-Type: text/plain' \\\n//     --data 'Can you explain why dogs are better than cats?'\n//\n// Or consumed with fetch:\n//\n//   fetch('http://localhost:3000', {\n//     method: 'POST',\n//     body: 'Tell me why dogs are better than cats',\n//   }).then(async res => {\n//     const runner = ChatCompletionStreamingRunner.fromReadableStream(res)\n//   })\n//\n// See examples/stream-to-client-browser.ts for a more complete example.\nexport default async function handler(req: NextApiRequest, res: NextApiResponse) {\n  const openai = new OpenAI();\n\n  const stream = openai.chat.completions.stream({\n    model: 'gpt-3.5-turbo',\n    stream: true,\n    // @ts-ignore\n    messages: [{ role: 'user', content: await req.text() }],\n  });\n\n  return res.send(stream.toReadableStream());\n  // @ts-ignore -- Or, for the app router:\n  return new Response(stream.toReadableStream());\n}\n"
  },
  {
    "path": "examples/stream-to-client-raw.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\n// This file demonstrates how to stream from the server as a text/plain\n// response with express and the stream async iterator.\n\nimport OpenAI from 'openai';\nimport express, { Request, Response } from 'express';\n\nconst openai = new OpenAI();\nconst app = express();\n\napp.use(express.text());\n\n// This endpoint can be called with:\n//\n//   curl 127.0.0.1:3000 -N -X POST -H 'Content-Type: text/plain' \\\n//     --data 'Can you explain why dogs are better than cats?'\n//\n// Or consumed with fetch:\n//\n//   fetch('http://localhost:3000', {\n//     method: 'POST',\n//     body: 'Tell me why dogs are better than cats',\n//   }).then(async res => {\n//     const decoder = new TextDecoder();\n//     for await (const chunk of res.body) {\n//       console.log(`chunk: ${decoder.decode(chunk)}`);\n//     }\n//   })\n//\napp.post('/', async (req: Request, res: Response) => {\n  try {\n    console.log('Received request:', req.body);\n\n    const stream = await openai.chat.completions.create({\n      model: 'gpt-3.5-turbo',\n      stream: true,\n      messages: [{ role: 'user', content: req.body }],\n    });\n\n    res.header('Content-Type', 'text/plain');\n\n    // Sends each content stream chunk-by-chunk, such that the client\n    // ultimately receives a single string.\n    for await (const chunk of stream) {\n      res.write(chunk.choices[0]?.delta.content || '');\n    }\n\n    res.end();\n  } catch (e) {\n    console.error(e);\n  }\n});\n\napp.listen('3000', () => {\n  console.log('Started proxy express server');\n});\n"
  },
  {
    "path": "examples/stream.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\n\nconst openai = new OpenAI();\n\nasync function main() {\n  const runner = openai.chat.completions\n    .stream({\n      model: 'gpt-3.5-turbo',\n      messages: [{ role: 'user', content: 'Say this is a test' }],\n    })\n    .on('message', (msg) => console.log(msg))\n    .on('content', (diff) => process.stdout.write(diff));\n\n  for await (const chunk of runner) {\n    console.log('chunk', chunk);\n  }\n\n  const result = await runner.finalChatCompletion();\n  console.log(result);\n}\n\nmain();\n"
  },
  {
    "path": "examples/text-to-speech.ts",
    "content": "import OpenAI from 'openai';\nimport { playAudio } from 'openai/helpers/audio';\n\nconst openai = new OpenAI();\n\nconst exampleText = `\nI see skies of blue and clouds of white\nThe bright blessed days, the dark sacred nights\nAnd I think to myself\nWhat a wonderful world\n`.trim();\n\nasync function main(): Promise<void> {\n  const response = await openai.audio.speech.create({\n    model: 'tts-1',\n    voice: 'nova',\n    input: exampleText,\n  });\n\n  await playAudio(response);\n}\n\nmain().catch(console.error);\n"
  },
  {
    "path": "examples/tool-call-helpers-zod.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\nimport { zodFunction } from 'openai/helpers/zod';\nimport { z } from 'zod/v4'; // Also works for 'zod/v3'\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\n// Define your functions, alongside zod schemas.\n\nconst ListParams = z.object({\n  genre: z.enum(['mystery', 'nonfiction', 'memoir', 'romance', 'historical']),\n});\ntype ListParams = z.infer<typeof ListParams>;\nasync function listBooks({ genre }: ListParams) {\n  return db.filter((item) => item.genre === genre).map((item) => ({ name: item.name, id: item.id }));\n}\n\nconst SearchParams = z.object({\n  name: z.string(),\n});\ntype SearchParams = z.infer<typeof SearchParams>;\nasync function searchBooks({ name }: SearchParams) {\n  return db.filter((item) => item.name.includes(name)).map((item) => ({ name: item.name, id: item.id }));\n}\n\nconst GetParams = z.object({\n  id: z.string(),\n});\ntype GetParams = z.infer<typeof GetParams>;\nasync function getBook({ id }: GetParams) {\n  return db.find((item) => item.id === id)!;\n}\n\nasync function main() {\n  const runner = openai.chat.completions\n    .runTools({\n      model: 'gpt-4-1106-preview',\n      stream: true,\n      tools: [\n        zodFunction({\n          name: 'listBooks',\n          function: listBooks,\n          parameters: ListParams,\n          description: 'List queries books by genre, and returns a list of names of books',\n        }),\n        zodFunction({\n          name: 'searchBooks',\n          function: searchBooks,\n          parameters: SearchParams,\n          description: 'Search queries books by their name and returns a list of book names and their ids',\n        }),\n        zodFunction({\n          name: 'getBook',\n          function: getBook,\n          parameters: GetParams,\n          description:\n            \"Get returns a book's detailed information based on the id of the book. Note that this does not accept names, and only IDs, which you can get by using search.\",\n        }),\n      ],\n      messages: [\n        {\n          role: 'system',\n          content:\n            'Please use our book database, which you can access using functions to answer the following questions.',\n        },\n        {\n          role: 'user',\n          content:\n            'I really enjoyed reading To Kill a Mockingbird, could you recommend me a book that is similar and tell me why?',\n        },\n      ],\n    })\n    .on('message', (msg) => console.log('msg', msg))\n    .on('finalFunctionToolCall', (functionCall) => console.log('functionCall', functionCall))\n    .on('finalFunctionToolCallResult', (functionCallResult) =>\n      console.log('functionCallResult', functionCallResult),\n    )\n    .on('content', (diff) => process.stdout.write(diff));\n\n  const result = await runner.finalChatCompletion();\n  console.log();\n  console.log('messages');\n  console.log(runner.messages);\n\n  console.log();\n  console.log('final chat completion');\n  console.dir(result, { depth: null });\n}\n\nconst db = [\n  {\n    id: 'a1',\n    name: 'To Kill a Mockingbird',\n    genre: 'historical',\n    description: `Compassionate, dramatic, and deeply moving, \"To Kill A Mockingbird\" takes readers to the roots of human behavior - to innocence and experience, kindness and cruelty, love and hatred, humor and pathos. Now with over 18 million copies in print and translated into forty languages, this regional story by a young Alabama woman claims universal appeal. Harper Lee always considered her book to be a simple love story. Today it is regarded as a masterpiece of American literature.`,\n  },\n  {\n    id: 'a2',\n    name: 'All the Light We Cannot See',\n    genre: 'historical',\n    description: `In a mining town in Germany, Werner Pfennig, an orphan, grows up with his younger sister, enchanted by a crude radio they find that brings them news and stories from places they have never seen or imagined. Werner becomes an expert at building and fixing these crucial new instruments and is enlisted to use his talent to track down the resistance. Deftly interweaving the lives of Marie-Laure and Werner, Doerr illuminates the ways, against all odds, people try to be good to one another.`,\n  },\n  {\n    id: 'a3',\n    name: 'Where the Crawdads Sing',\n    genre: 'historical',\n    description: `For years, rumors of the “Marsh Girl” haunted Barkley Cove, a quiet fishing village. Kya Clark is barefoot and wild; unfit for polite society. So in late 1969, when the popular Chase Andrews is found dead, locals immediately suspect her.\nBut Kya is not what they say. A born naturalist with just one day of school, she takes life's lessons from the land, learning the real ways of the world from the dishonest signals of fireflies. But while she has the skills to live in solitude forever, the time comes when she yearns to be touched and loved. Drawn to two young men from town, who are each intrigued by her wild beauty, Kya opens herself to a new and startling world—until the unthinkable happens.`,\n  },\n];\n\nmain();\n"
  },
  {
    "path": "examples/tool-call-helpers.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\nimport { RunnableToolFunction } from 'openai/lib/RunnableFunction';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\n/**\n * Note, this will automatically ensure the model returns valid JSON,\n * but won't ensure it conforms to your schema.\n *\n * For that functionality, please see the `tool-call-helpers-zod.ts` example,\n * which shows a fully typesafe, schema-validating version.\n */\nconst tools: RunnableToolFunction<any>[] = [\n  {\n    type: 'function',\n    function: {\n      name: 'list',\n      description: 'list queries books by genre, and returns a list of names of books',\n      parameters: {\n        type: 'object',\n        properties: {\n          genre: { type: 'string', enum: ['mystery', 'nonfiction', 'memoir', 'romance', 'historical'] },\n        },\n      },\n      function: list,\n      parse: JSON.parse,\n    },\n  } as RunnableToolFunction<{ genre: string }>,\n  {\n    type: 'function',\n    function: {\n      name: 'search',\n      description: 'search queries books by their name and returns a list of book names and their ids',\n      parameters: {\n        type: 'object',\n        properties: {\n          name: { type: 'string' },\n        },\n      },\n      function: search,\n      parse: JSON.parse,\n    },\n  } as RunnableToolFunction<{ name: string }>,\n  {\n    type: 'function',\n    function: {\n      name: 'get',\n      description:\n        \"get returns a book's detailed information based on the id of the book. Note that this does not accept names, and only IDs, which you can get by using search.\",\n      parameters: {\n        type: 'object',\n        properties: {\n          id: { type: 'string' },\n        },\n      },\n      function: get,\n      parse: JSON.parse,\n    },\n  } as RunnableToolFunction<{ id: string }>,\n];\n\nasync function main() {\n  const runner = await openai.chat.completions\n    .runTools({\n      model: 'gpt-4-1106-preview',\n      stream: true,\n      tools,\n      messages: [\n        {\n          role: 'system',\n          content:\n            'Please use our book database, which you can access using functions to answer the following questions.',\n        },\n        {\n          role: 'user',\n          content:\n            'I really enjoyed reading To Kill a Mockingbird, could you recommend me a book that is similar and tell me why?',\n        },\n      ],\n    })\n    .on('message', (msg) => console.log('msg', msg))\n    .on('functionToolCall', (functionCall) => console.log('functionCall', functionCall))\n    .on('functionToolCallResult', (functionCallResult) =>\n      console.log('functionCallResult', functionCallResult),\n    )\n    .on('content', (diff) => process.stdout.write(diff));\n\n  const result = await runner.finalChatCompletion();\n  console.log();\n  console.log('messages');\n  console.log(runner.messages);\n\n  console.log();\n  console.log('final chat completion');\n  console.dir(result, { depth: null });\n}\n\nconst db = [\n  {\n    id: 'a1',\n    name: 'To Kill a Mockingbird',\n    genre: 'historical',\n    description: `Compassionate, dramatic, and deeply moving, \"To Kill A Mockingbird\" takes readers to the roots of human behavior - to innocence and experience, kindness and cruelty, love and hatred, humor and pathos. Now with over 18 million copies in print and translated into forty languages, this regional story by a young Alabama woman claims universal appeal. Harper Lee always considered her book to be a simple love story. Today it is regarded as a masterpiece of American literature.`,\n  },\n  {\n    id: 'a2',\n    name: 'All the Light We Cannot See',\n    genre: 'historical',\n    description: `In a mining town in Germany, Werner Pfennig, an orphan, grows up with his younger sister, enchanted by a crude radio they find that brings them news and stories from places they have never seen or imagined. Werner becomes an expert at building and fixing these crucial new instruments and is enlisted to use his talent to track down the resistance. Deftly interweaving the lives of Marie-Laure and Werner, Doerr illuminates the ways, against all odds, people try to be good to one another.`,\n  },\n  {\n    id: 'a3',\n    name: 'Where the Crawdads Sing',\n    genre: 'historical',\n    description: `For years, rumors of the “Marsh Girl” haunted Barkley Cove, a quiet fishing village. Kya Clark is barefoot and wild; unfit for polite society. So in late 1969, when the popular Chase Andrews is found dead, locals immediately suspect her.\nBut Kya is not what they say. A born naturalist with just one day of school, she takes life's lessons from the land, learning the real ways of the world from the dishonest signals of fireflies. But while she has the skills to live in solitude forever, the time comes when she yearns to be touched and loved. Drawn to two young men from town, who are each intrigued by her wild beauty, Kya opens herself to a new and startling world—until the unthinkable happens.`,\n  },\n];\n\nasync function list({ genre }: { genre: string }) {\n  return db.filter((item) => item.genre === genre).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function search({ name }: { name: string }) {\n  return db.filter((item) => item.name.includes(name)).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function get({ id }: { id: string }) {\n  return db.find((item) => item.id === id)!;\n}\n\nmain();\n"
  },
  {
    "path": "examples/tool-calls-stream.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\n//\n//\n//\n//\n//\n//\n// Note: this file is provided for completeness,\n// but much more convenient ways of streaming tool calls are available\n// with the `.stream()` and `.runTools()` helpers.\n//\n// See the `tool-call-helpers.ts` and `stream.ts` examples for usage,\n// or the README for documentation.\n//\n//\n//\n//\n//\n//\n\nimport util from 'util';\nimport OpenAI from 'openai';\nimport {\n  ChatCompletionMessage,\n  ChatCompletionChunk,\n  ChatCompletionMessageParam,\n} from 'openai/resources/chat';\n\n// Used so that the each chunk coming in is noticable\nconst CHUNK_DELAY_MS = 100;\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\nconst tools: OpenAI.Chat.Completions.ChatCompletionTool[] = [\n  {\n    type: 'function',\n    function: {\n      name: 'list',\n      description: 'list queries books by genre, and returns a list of names of books',\n      parameters: {\n        type: 'object',\n        properties: {\n          genre: { type: 'string', enum: ['mystery', 'nonfiction', 'memoir', 'romance', 'historical'] },\n        },\n      },\n    },\n  },\n  {\n    type: 'function',\n    function: {\n      name: 'search',\n      description: 'search queries books by their name and returns a list of book names and their ids',\n      parameters: {\n        type: 'object',\n        properties: {\n          name: { type: 'string' },\n        },\n      },\n    },\n  },\n  {\n    type: 'function',\n    function: {\n      name: 'get',\n      description:\n        \"get returns a book's detailed information based on the id of the book. Note that this does not accept names, and only IDs, which you can get by using search.\",\n      parameters: {\n        type: 'object',\n        properties: {\n          id: { type: 'string' },\n        },\n      },\n    },\n  },\n];\n\nasync function callTool(\n  tool_call: OpenAI.Chat.Completions.ChatCompletionMessageFunctionToolCall,\n): Promise<any> {\n  const args = JSON.parse(tool_call.function.arguments);\n  switch (tool_call.function.name) {\n    case 'list':\n      return await list(args['genre']);\n\n    case 'search':\n      return await search(args['name']);\n\n    case 'get':\n      return await get(args['id']);\n\n    default:\n      throw new Error('No function found');\n  }\n}\n\nasync function main() {\n  const messages: ChatCompletionMessageParam[] = [\n    {\n      role: 'system',\n      content:\n        'Please use our book database, which you can access using functions to answer the following questions.',\n    },\n    {\n      role: 'user',\n      content:\n        'I really enjoyed reading To Kill a Mockingbird, could you recommend me a book that is similar and tell me why?',\n    },\n  ];\n  console.log(messages[0]);\n  console.log();\n  console.log(messages[1]);\n  console.log();\n\n  while (true) {\n    const stream = await openai.chat.completions.create({\n      model: 'gpt-3.5-turbo',\n      messages,\n      tools: tools,\n      stream: true,\n    });\n\n    // Since the stream returns chunks, we need to build up the ChatCompletionMessage object.\n    // We implement this logic in messageReducer, which coalesces deltas into the message.\n    // `lineRewriter()` allows us to rewrite the last output with new text, which is one\n    // way of forwarding the streamed output to a visual interface.\n    let writeLine = lineRewriter();\n    let message = {} as ChatCompletionMessage;\n    for await (const chunk of stream) {\n      message = messageReducer(message, chunk);\n      writeLine(message);\n\n      // Add a small delay so that the chunks coming in are noticablej\n      await new Promise((resolve) => setTimeout(resolve, CHUNK_DELAY_MS));\n    }\n    console.log();\n    messages.push(message);\n\n    // If there are no tool calls, we're done and can exit this loop\n    if (!message.tool_calls) {\n      return;\n    }\n\n    // If there are tool calls, we generate a new message with the role 'tool' for each tool call.\n    for (const toolCall of message.tool_calls) {\n      if (toolCall.type !== 'function') {\n        throw new Error(`Unexpected tool call type: ${toolCall.type}`);\n      }\n      const result = await callTool(toolCall);\n      const newMessage = {\n        tool_call_id: toolCall.id,\n        role: 'tool' as const,\n        name: toolCall.function.name,\n        content: JSON.stringify(result),\n      };\n      console.log(newMessage);\n      messages.push(newMessage);\n    }\n    console.log();\n  }\n}\n\nfunction messageReducer(previous: ChatCompletionMessage, item: ChatCompletionChunk): ChatCompletionMessage {\n  const reduce = (acc: any, delta: ChatCompletionChunk.Choice.Delta) => {\n    acc = { ...acc };\n    for (const [key, value] of Object.entries(delta)) {\n      if (acc[key] === undefined || acc[key] === null) {\n        acc[key] = value;\n        //  OpenAI.Chat.Completions.ChatCompletionMessageToolCall does not have a key, .index\n        if (Array.isArray(acc[key])) {\n          for (const arr of acc[key]) {\n            delete arr.index;\n          }\n        }\n      } else if (typeof acc[key] === 'string' && typeof value === 'string') {\n        acc[key] += value;\n      } else if (typeof acc[key] === 'number' && typeof value === 'number') {\n        acc[key] = value;\n      } else if (Array.isArray(acc[key]) && Array.isArray(value)) {\n        const accArray = acc[key];\n        for (let i = 0; i < value.length; i++) {\n          const { index, ...chunkTool } = value[i];\n          if (index - accArray.length > 1) {\n            throw new Error(\n              `Error: An array has an empty value when tool_calls are constructed. tool_calls: ${accArray}; tool: ${value}`,\n            );\n          }\n          accArray[index] = reduce(accArray[index], chunkTool);\n        }\n      } else if (typeof acc[key] === 'object' && typeof value === 'object') {\n        acc[key] = reduce(acc[key], value);\n      }\n    }\n    return acc;\n  };\n\n  const choice = item.choices[0];\n  if (!choice) {\n    // chunk contains information about usage and token counts\n    return previous;\n  }\n  return reduce(previous, choice.delta) as ChatCompletionMessage;\n}\n\nfunction lineRewriter() {\n  let lastMessageLines = 0;\n  return function write(value: any) {\n    process.stdout.cursorTo(0);\n    process.stdout.moveCursor(0, -lastMessageLines);\n\n    // calculate where to move cursor back for the next move.\n    const text = util.formatWithOptions({ colors: false, breakLength: Infinity, depth: 4 }, value);\n    const __LINE_BREAK_PLACE_HOLDER__ = '__LINE_BREAK_PLACE_HOLDER__';\n    const lines = text\n      // @ts-ignore-error this requires es2021\n      .replaceAll('\\\\n', __LINE_BREAK_PLACE_HOLDER__)\n      .split('\\n')\n      // @ts-ignore-error this requires es2021\n      .map((line: string) => line.replaceAll(__LINE_BREAK_PLACE_HOLDER__, '\\\\n'));\n    lastMessageLines = -1;\n    for (const line of lines) {\n      const lineLength = line.length;\n      lastMessageLines += Math.ceil(lineLength / process.stdout.columns);\n    }\n    lastMessageLines = Math.max(lastMessageLines, 0);\n\n    process.stdout.clearScreenDown();\n    process.stdout.write(util.formatWithOptions({ colors: true, breakLength: Infinity, depth: 4 }, value));\n  };\n}\nconst db: { id: string; name: string; genre: string; description: string }[] = [\n  {\n    id: 'a1',\n    name: 'To Kill a Mockingbird',\n    genre: 'historical',\n    description: `Compassionate, dramatic, and deeply moving, \"To Kill A Mockingbird\" takes readers to the roots of human behavior - to innocence and experience, kindness and cruelty, love and hatred, humor and pathos. Now with over 18 million copies in print and translated into forty languages, this regional story by a young Alabama woman claims universal appeal. Harper Lee always considered her book to be a simple love story. Today it is regarded as a masterpiece of American literature.`,\n  },\n  {\n    id: 'a2',\n    name: 'All the Light We Cannot See',\n    genre: 'historical',\n    description: `In a mining town in Germany, Werner Pfennig, an orphan, grows up with his younger sister, enchanted by a crude radio they find that brings them news and stories from places they have never seen or imagined. Werner becomes an expert at building and fixing these crucial new instruments and is enlisted to use his talent to track down the resistance. Deftly interweaving the lives of Marie-Laure and Werner, Doerr illuminates the ways, against all odds, people try to be good to one another.`,\n  },\n  {\n    id: 'a3',\n    name: 'Where the Crawdads Sing',\n    genre: 'historical',\n    description: `For years, rumors of the “Marsh Girl” haunted Barkley Cove, a quiet fishing village. Kya Clark is barefoot and wild; unfit for polite society. So in late 1969, when the popular Chase Andrews is found dead, locals immediately suspect her.\n\nBut Kya is not what they say. A born naturalist with just one day of school, she takes life's lessons from the land, learning the real ways of the world from the dishonest signals of fireflies. But while she has the skills to live in solitude forever, the time comes when she yearns to be touched and loved. Drawn to two young men from town, who are each intrigued by her wild beauty, Kya opens herself to a new and startling world—until the unthinkable happens.`,\n  },\n];\n\nasync function list(genre: string) {\n  return db.filter((item) => item.genre === genre).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function search(name: string) {\n  return db.filter((item) => item.name.includes(name)).map((item) => ({ name: item.name, id: item.id }));\n}\n\nasync function get(id: string) {\n  return db.find((item) => item.id === id)!;\n}\n\nmain();\n"
  },
  {
    "path": "examples/tsconfig.json",
    "content": "{\n  \"extends\": \"../tsconfig.json\"\n}\n"
  },
  {
    "path": "examples/types.ts",
    "content": "#!/usr/bin/env -S npm run tsn -T\n\nimport OpenAI from 'openai';\n\n// gets API Key from environment variable OPENAI_API_KEY\nconst openai = new OpenAI();\n\nasync function main() {\n  // Explicit non streaming params type:\n  const params: OpenAI.Chat.ChatCompletionCreateParams = {\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test!' }],\n  };\n  const completion = await openai.chat.completions.create(params);\n  console.log(completion.choices[0]?.message?.content);\n\n  // Explicit streaming params type:\n  const streaming_params: OpenAI.Chat.ChatCompletionCreateParams = {\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Say this is a test!' }],\n    stream: true,\n  };\n\n  const stream = await openai.chat.completions.create(streaming_params);\n  for await (const chunk of stream) {\n    process.stdout.write(chunk.choices[0]?.delta?.content || '');\n  }\n  process.stdout.write('\\n');\n}\n\nmain();\n"
  },
  {
    "path": "examples/ui-generation.ts",
    "content": "import OpenAI from 'openai';\nimport { z } from 'zod/v4'; // Also works for 'zod/v3'\nimport { zodResponseFormat } from 'openai/helpers/zod';\n\nconst openai = new OpenAI();\n\n// `z.lazy()` can't infer recursive types so we have to explicitly\n// define the type ourselves here\ninterface UI {\n  type: 'div' | 'button' | 'header' | 'section' | 'field' | 'form';\n  label: string;\n  children: Array<UI>;\n  attributes: {\n    value: string;\n    name: string;\n  }[];\n}\n\nconst UISchema: z.ZodType<UI> = z.lazy(() =>\n  z.object({\n    type: z.enum(['div', 'button', 'header', 'section', 'field', 'form']),\n    label: z.string(),\n    children: z.array(UISchema),\n    attributes: z.array(\n      z.object({\n        name: z.string(),\n        value: z.string(),\n      }),\n    ),\n  }),\n);\n\nasync function main() {\n  const completion = await openai.chat.completions.parse({\n    model: 'gpt-4o-2024-08-06',\n    messages: [\n      {\n        role: 'system',\n        content: 'You are a UI generator AI. Convert the user input into a UI.',\n      },\n      { role: 'user', content: 'Make a User Profile Form' },\n    ],\n    response_format: zodResponseFormat(UISchema, 'ui'),\n  });\n\n  const message = completion.choices[0]!.message;\n  const ui = message.parsed;\n  console.dir(ui, { depth: 10 });\n}\n\nmain();\n"
  },
  {
    "path": "helpers.md",
    "content": "# Structured Outputs Parsing Helpers\n\nThe OpenAI API supports extracting JSON from the model with the `response_format` request param, for more details on the API, see [this guide](https://platform.openai.com/docs/guides/structured-outputs).\n\nThe SDK provides a `client.chat.completions.parse()` method which is a wrapper over the `client.chat.completions.create()` that\nprovides richer integrations with TS specific types & returns a `ParsedChatCompletion` object, which is an extension of the standard `ChatCompletion` type.\n\n## Auto-parsing response content with Zod schemas\n\nYou can pass zod schemas wrapped with `zodResponseFormat()` to the `.parse()` method and the SDK will automatically convert the model\ninto a JSON schema, send it to the API and parse the response content back using the given zod schema.\n\n```ts\nimport { zodResponseFormat } from 'openai/helpers/zod';\nimport OpenAI from 'openai/index';\nimport { z } from 'zod/v3';\n\nconst Step = z.object({\n  explanation: z.string(),\n  output: z.string(),\n});\n\nconst MathResponse = z.object({\n  steps: z.array(Step),\n  final_answer: z.string(),\n});\n\nconst client = new OpenAI();\n\nconst completion = await client.chat.completions.parse({\n  model: 'gpt-4o-2024-08-06',\n  messages: [\n    { role: 'system', content: 'You are a helpful math tutor.' },\n    { role: 'user', content: 'solve 8x + 31 = 2' },\n  ],\n  response_format: zodResponseFormat(MathResponse, 'math_response'),\n});\n\nconsole.dir(completion, { depth: 5 });\n\nconst message = completion.choices[0]?.message;\nif (message?.parsed) {\n  console.log(message.parsed.steps);\n  console.log(`answer: ${message.parsed.final_answer}`);\n}\n```\n\n## Auto-parsing function tool calls\n\nThe `.parse()` method will also automatically parse `function` tool calls if:\n\n- You use the `zodFunction()` helper method\n- You mark your tool schema with `\"strict\": True`\n\nFor example:\n\n```ts\nimport { zodFunction } from 'openai/helpers/zod';\nimport OpenAI from 'openai/index';\nimport { z } from 'zod/v3';\n\nconst Table = z.enum(['orders', 'customers', 'products']);\n\nconst Column = z.enum([\n  'id',\n  'status',\n  'expected_delivery_date',\n  'delivered_at',\n  'shipped_at',\n  'ordered_at',\n  'canceled_at',\n]);\n\nconst Operator = z.enum(['=', '>', '<', '<=', '>=', '!=']);\n\nconst OrderBy = z.enum(['asc', 'desc']);\n\nconst DynamicValue = z.object({\n  column_name: z.string(),\n});\n\nconst Condition = z.object({\n  column: z.string(),\n  operator: Operator,\n  value: z.union([z.string(), z.number(), DynamicValue]),\n});\n\nconst Query = z.object({\n  table_name: Table,\n  columns: z.array(Column),\n  conditions: z.array(Condition),\n  order_by: OrderBy,\n});\n\nconst client = new OpenAI();\nconst completion = await client.chat.completions.parse({\n  model: 'gpt-4o-2024-08-06',\n  messages: [\n    {\n      role: 'system',\n      content:\n        'You are a helpful assistant. The current date is August 6, 2024. You help users query for the data they are looking for by calling the query function.',\n    },\n    {\n      role: 'user',\n      content: 'look up all my orders in november of last year that were fulfilled but not delivered on time',\n    },\n  ],\n  tools: [zodFunction({ name: 'query', parameters: Query })],\n});\nconsole.dir(completion, { depth: 10 });\n\nconst toolCall = completion.choices[0]?.message.tool_calls?.[0];\nif (toolCall) {\n  const args = toolCall.function.parsed_arguments as z.infer<typeof Query>;\n  console.log(args);\n  console.log(args.table_name);\n}\n\nmain();\n```\n\n### Differences from `.create()`\n\nThe `chat.completions.parse()` method imposes some additional restrictions on it's usage that `chat.completions.create()` does not.\n\n- If the completion completes with `finish_reason` set to `length` or `content_filter`, the `LengthFinishReasonError` / `ContentFilterFinishReasonError` errors will be raised.\n- Only strict function tools can be passed, e.g. `{type: 'function', function: {..., strict: true}}`\n\n# Streaming Helpers\n\nOpenAI supports streaming responses when interacting with the [Chat](#chat-streaming) or [Assistant](#assistant-streaming-api) APIs.\n\n## Assistant Streaming API\n\nOpenAI supports streaming responses from Assistants. The SDK provides convenience wrappers around the API\nso you can subscribe to the types of events you are interested in as well as receive accumulated responses.\n\nMore information can be found in the documentation: [Assistant Streaming](https://platform.openai.com/docs/assistants/overview?lang=node.js)\n\n#### An example of creating a run and subscribing to some events\n\n```ts\nconst run = openai.beta.threads.runs\n  .stream(thread.id, { assistant_id: assistant.id })\n  .on('textCreated', (text) => process.stdout.write('\\nassistant > '))\n  .on('textDelta', (textDelta, snapshot) => process.stdout.write(textDelta.value))\n  .on('toolCallCreated', (toolCall) => process.stdout.write(`\\nassistant > ${toolCall.type}\\n\\n`))\n  .on('toolCallDelta', (toolCallDelta, snapshot) => {\n    if (toolCallDelta.type === 'code_interpreter') {\n      if (toolCallDelta.code_interpreter.input) {\n        process.stdout.write(toolCallDelta.code_interpreter.input);\n      }\n      if (toolCallDelta.code_interpreter.outputs) {\n        process.stdout.write('\\noutput >\\n');\n        toolCallDelta.code_interpreter.outputs.forEach((output) => {\n          if (output.type === 'logs') {\n            process.stdout.write(`\\n${output.logs}\\n`);\n          }\n        });\n      }\n    }\n  });\n```\n\n### Starting a stream\n\nThere are three helper methods for creating streams:\n\n```ts\nopenai.beta.threads.runs.stream();\n```\n\nThis method can be used to start and stream the response to an existing run with an associated thread\nthat is already populated with messages.\n\n```ts\nopenai.beta.threads.createAndRunStream();\n```\n\nThis method can be used to add a message to a thread, start a run and then stream the response.\n\n```ts\nopenai.beta.threads.runs.submitToolOutputsStream();\n```\n\nThis method can be used to submit a tool output to a run waiting on the output and start a stream.\n\n### Assistant Events\n\nThe assistant API provides events you can subscribe to for the following events.\n\n```ts\n.on('event', (event: AssistantStreamEvent) => ...)\n```\n\nThis allows you to subscribe to all the possible raw events sent by the OpenAI streaming API.\nIn many cases it will be more convenient to subscribe to a more specific set of events for your use case.\n\nMore information on the types of events can be found here: [Events](https://platform.openai.com/docs/api-reference/assistants-streaming/events)\n\n```ts\n.on('runStepCreated', (runStep: RunStep) => ...)\n.on('runStepDelta', (delta: RunStepDelta, snapshot: RunStep) => ...)\n.on('runStepDone', (runStep: RunStep) => ...)\n```\n\nThese events allow you to subscribe to the creation, delta and completion of a RunStep.\n\nFor more information on how Runs and RunSteps work see the documentation [Runs and RunSteps](https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps)\n\n```ts\n.on('messageCreated', (message: Message) => ...)\n.on('messageDelta', (delta: MessageDelta, snapshot: Message) => ...)\n.on('messageDone', (message: Message) => ...)\n```\n\nThis allows you to subscribe to Message creation, delta and completion events. Messages can contain\ndifferent types of content that can be sent from a model (and events are available for specific content types).\nFor convenience, the delta event includes both the incremental update and an accumulated snapshot of the content.\n\nMore information on messages can be found\non in the documentation page [Message](https://platform.openai.com/docs/api-reference/messages/object).\n\n```ts\n.on('textCreated', (content: Text) => ...)\n.on('textDelta', (delta: TextDelta, snapshot: Text) => ...)\n.on('textDone', (content: Text, snapshot: Message) => ...)\n```\n\nThese events allow you to subscribe to the creation, delta and completion of a Text content (a specific type of message).\nFor convenience, the delta event includes both the incremental update and an accumulated snapshot of the content.\n\n```ts\n.on('imageFileDone', (content: ImageFile, snapshot: Message) => ...)\n```\n\nImage files are not sent incrementally so an event is provided for when a image file is available.\n\n```ts\n.on('toolCallCreated', (toolCall: ToolCall) => ...)\n.on('toolCallDelta', (delta: RunStepDelta, snapshot: ToolCall) => ...)\n.on('toolCallDone', (toolCall: ToolCall) => ...)\n```\n\nThese events allow you to subscribe to events for the creation, delta and completion of a ToolCall.\n\nMore information on tools can be found here [Tools](https://platform.openai.com/docs/assistants/tools)\n\n```ts\n.on('end', () => ...)\n```\n\nThe last event send when a stream ends.\n\n### Assistant Methods\n\nThe assistant streaming object also provides a few methods for convenience:\n\n```ts\n.currentEvent(): AssistantStreamEvent | undefined\n\n.currentRun(): Run | undefined\n\n.currentMessageSnapshot(): Message\n\n.currentRunStepSnapshot(): Runs.RunStep\n```\n\nThese methods are provided to allow you to access additional context from within event handlers. In many cases\nthe handlers should include all the information you need for processing, but if additional context is required it\ncan be accessed.\n\nNote: There is not always a relevant context in certain situations (these will be `undefined` in those cases).\n\n```ts\nawait .finalMessages() : Promise<Message[]>\n\nawait .finalRunSteps(): Promise<RunStep[]>\n```\n\nThese methods are provided for convenience to collect information at the end of a stream. Calling these events\nwill trigger consumption of the stream until completion and then return the relevant accumulated objects.\n\n## Chat Streaming\n\n### Streaming Responses\n\n```ts\nopenai.chat.completions.stream({ stream?: false, … }, options?): ChatCompletionStreamingRunner\n```\n\n`openai.chat.completions.stream()` returns a `ChatCompletionStreamingRunner`, which emits events, has an async\niterator, and exposes helper methods to accumulate chunks into a convenient shape and make it easy to reason\nabout the conversation.\n\nAlternatively, you can use `openai.chat.completions.create({ stream: true, … })` which returns an async\niterable of the chunks in the stream and uses less memory (most notably, it does not accumulate a final chat\ncompletion object for you).\n\nIf you need to cancel a stream, you can `break` from a `for await` loop or call `stream.abort()`.\n\nSee an example of streaming helpers in action in [`examples/stream.ts`](examples/stream.ts).\n\n### Automated function calls\n\nWe provide the `openai.chat.completions.runTools({…})`\nconvenience helper for using function tool calls with the `/chat/completions` endpoint\nwhich automatically call the JavaScript functions you provide\nand sends their results back to the `/chat/completions` endpoint,\nlooping as long as the model requests tool calls.\n\nIf you pass a `parse` function, it will automatically parse the `arguments` for you\nand returns any parsing errors to the model to attempt auto-recovery.\nOtherwise, the args will be passed to the function you provide as a string.\n\nIf you pass `tool_choice: {function: {name: …}}` instead of `auto`,\nit returns immediately after calling that function (and only loops to auto-recover parsing errors).\n\n```ts\nimport OpenAI from 'openai';\n\nconst client = new OpenAI();\n\nasync function main() {\n  const runner = client.chat.completions\n    .runTools({\n      model: 'gpt-4o',\n      messages: [{ role: 'user', content: 'How is the weather this week?' }],\n      tools: [\n        {\n          type: 'function',\n          function: {\n            function: getCurrentLocation,\n            parameters: { type: 'object', properties: {} },\n          },\n        },\n        {\n          type: 'function',\n          function: {\n            function: getWeather,\n            parse: JSON.parse, // or use a validation library like zod for typesafe parsing.\n            parameters: {\n              type: 'object',\n              properties: {\n                location: { type: 'string' },\n              },\n            },\n          },\n        },\n      ],\n    })\n    .on('message', (message) => console.log(message));\n\n  const finalContent = await runner.finalContent();\n  console.log();\n  console.log('Final content:', finalContent);\n}\n\nasync function getCurrentLocation() {\n  return 'Boston'; // Simulate lookup\n}\n\nasync function getWeather(args: { location: string }) {\n  const { location } = args;\n  // … do lookup …\n  return { temperature, precipitation };\n}\n\nmain();\n\n// {role: \"user\",      content: \"How's the weather this week?\"}\n// {role: \"assistant\", tool_calls: [{type: \"function\", function: {name: \"getCurrentLocation\", arguments: \"{}\"}, id: \"123\"}\n// {role: \"tool\",      name: \"getCurrentLocation\", content: \"Boston\", tool_call_id: \"123\"}\n// {role: \"assistant\", tool_calls: [{type: \"function\", function: {name: \"getWeather\", arguments: '{\"location\": \"Boston\"}'}, id: \"1234\"}]}\n// {role: \"tool\",      name: \"getWeather\", content: '{\"temperature\": \"50degF\", \"preciptation\": \"high\"}', tool_call_id: \"1234\"}\n// {role: \"assistant\", content: \"It's looking cold and rainy - you might want to wear a jacket!\"}\n//\n// Final content: \"It's looking cold and rainy - you might want to wear a jacket!\"\n```\n\nLike with `.stream()`, we provide a variety of [helpers and events](helpers.md#chat-events).\n\nRead more about various examples such as with integrating with [zod](#integrate-with-zod),\n[next.js](#integrate-with-nextjs), and [proxying a stream to the browser](#proxy-streaming-to-a-browser).\n\nBy default, we run the loop up to 10 chat completions from the API. You can change this behavior by\nadjusting `maxChatCompletions` in the request options object. Note that `max_tokens` is the limit per\nchat completion request, not for the entire call run.\n\nSee an example of automated function calls in action in\n[`examples/function-call-helpers.ts`](examples/function-call-helpers.ts).\n\nNote, `runFunctions` was also previously available, but has been deprecated in favor of `runTools`.\n\n### Chat Events\n\n#### `.on('connect', () => …)`\n\nThe first event that is fired when the connection with the OpenAI API is established.\n\n#### `.on('chunk', (chunk: ChatCompletionChunk, snapshot: ChatCompletionSnapshot) => …)` (with `stream`)\n\nThe event fired when a chunk is received from the API. Not fired when it is not streaming. The snapshot\nreturns an accumulated `ChatCompletionSnapshot`, which has a similar shape to `ChatCompletion` with optional\nfields and is built up from the chunks.\n\n#### `.on('chatCompletion', (completion: ChatCompletion) => …)`\n\nThe event fired when a chat completion is returned or done being streamed by the API.\n\n#### `.on('message', (message: ChatCompletionMessageParam) => …)`\n\nThe event fired when a new message is either sent or received from the API. Does not fire for the messages\nsent as the parameter to either `.runTools()` or `.stream()`\n\n#### `.on('content', (content: string) => …)` (without `stream`)\n\nThe event fired when a message from the `assistant` is received from the API.\n\n#### `.on('content', (delta: string, snapshot: string) => …)` (with `stream`)\n\nThe event fired when a chunk from the `assistant` is received from the API. The `delta` argument contains the\ncontent of the chunk, while the `snapshot` returns the accumulated content for the current message.\n\n#### `.on('functionCall', (functionCall: ChatCompletionMessage.FunctionCall) => …)`\n\nThe event fired when a function call is made by the assistant.\n\n#### `.on('functionCallResult', (content: string) => …)`\n\nThe event fired when the function runner responds to the function call with `role: \"function\"`. The `content` of the\nresponse is given as the first argument to the callback.\n\n#### `.on('content.delta', (props: ContentDeltaEvent) => ...)`\n\nThe event fired for every chunk containing new content. The `props` object contains:\n- `delta`: The new content string received in this chunk\n- `snapshot`: The accumulated content so far\n- `parsed`: The partially parsed content (if applicable)\n\n#### `.on('content.done', (props: ContentDoneEvent<ParsedT>) => ...)`\n\nThe event fired when the content generation is complete. The `props` object contains:\n- `content`: The full generated content\n- `parsed`: The fully parsed content (if applicable)\n\n#### `.on('refusal.delta', (props: RefusalDeltaEvent) => ...)`\n\nThe event fired when a chunk contains part of a content refusal. The `props` object contains:\n- `delta`: The new refusal content string received in this chunk\n- `snapshot`: The accumulated refusal content string so far\n\n#### `.on('refusal.done', (props: RefusalDoneEvent) => ...)`\n\nThe event fired when the refusal content is complete. The `props` object contains:\n- `refusal`: The full refusal content\n\n#### `.on('tool_calls.function.arguments.delta', (props: FunctionToolCallArgumentsDeltaEvent) => ...)`\n\nThe event fired when a chunk contains part of a function tool call's arguments. The `props` object contains:\n- `name`: The name of the function being called\n- `index`: The index of the tool call\n- `arguments`: The accumulated raw JSON string of arguments\n- `parsed_arguments`: The partially parsed arguments object\n- `arguments_delta`: The new JSON string fragment received in this chunk\n\n#### `.on('tool_calls.function.arguments.done', (props: FunctionToolCallArgumentsDoneEvent) => ...)`\n\nThe event fired when a function tool call's arguments are complete. The `props` object contains:\n- `name`: The name of the function being called\n- `index`: The index of the tool call\n- `arguments`: The full raw JSON string of arguments\n- `parsed_arguments`: The fully parsed arguments object\n\n#### `.on('logprobs.content.delta', (props: LogProbsContentDeltaEvent) => ...)`\n\nThe event fired when a chunk contains new content log probabilities. The `props` object contains:\n- `content`: A list of the new log probabilities received in this chunk\n- `snapshot`: A list of the accumulated log probabilities so far\n\n#### `.on('logprobs.content.done', (props: LogProbsContentDoneEvent) => ...)`\n\nThe event fired when all content log probabilities have been received. The `props` object contains:\n- `content`: The full list of token log probabilities for the content\n\n#### `.on('logprobs.refusal.delta', (props: LogProbsRefusalDeltaEvent) => ...)`\n\nThe event fired when a chunk contains new refusal log probabilities. The `props` object contains:\n- `refusal`: A list of the new log probabilities received in this chunk\n- `snapshot`: A list of the accumulated log probabilities so far\n\n#### `.on('logprobs.refusal.done', (props: LogProbsRefusalDoneEvent) => ...)`\n\nThe event fired when all refusal log probabilities have been received. The `props` object contains:\n- `refusal`: The full list of token log probabilities for the refusal\n\n#### `.on('finalChatCompletion', (completion: ChatCompletion) => …)`\n\nThe event fired for the final chat completion. If the function call runner exceeds the number\n`maxChatCompletions`, then the last chat completion is given.\n\n#### `.on('finalContent', (contentSnapshot: string) => …)`\n\nThe event fired for the `content` of the last `role: \"assistant\"` message. Not fired if there is no `assistant`\nmessage.\n\n#### `.on('finalMessage', (message: ChatCompletionMessage) => …)`\n\nThe event fired for the last message.\n\n#### `.on('finalFunctionCall', (functionCall: ChatCompletionMessage.FunctionCall) => …)`\n\nThe event fired for the last message with a defined `function_call`.\n\n#### `.on('finalFunctionCallResult', (content: string) => …)`\n\nThe event fired for the last message with a `role: \"function\"`.\n\n#### `.on('error', (error: OpenAIError) => …)`\n\nThe event fired when an error is encountered outside of a `parse` function or an abort.\n\n#### `.on('abort', (error: APIUserAbortError) => …)`\n\nThe event fired when the stream receives a signal to abort.\n\n#### `.on('totalUsage', (usage: CompletionUsage) => …)` (without `stream`, usage is not currently reported with `stream`)\n\nThe event fired at the end, returning the total usage of the call.\n\n#### `.on('end', () => …)`\n\nThe last event fired in the stream.\n\n### Chat Methods\n\n#### `.abort()`\n\nAborts the runner and the streaming request, equivalent to `.controller.abort()`. Calling `.abort()` on a\n`ChatCompletionStreamingRunner` will also abort any in-flight network requests.\n\n#### `await .done()`\n\nAn empty promise which resolves when the stream is done.\n\n#### `await .finalChatCompletion()`\n\nA promise which resolves with the final chat completion that was received from the API. Throws if the request\nends before a complete chat completion is returned.\n\n#### `await .allChatCompletions()`\n\nA promise which resolves with The array of all chat completions that were received from the API.\n\n#### `await .finalContent()`\n\nA promise which resolves with the `content` of the last `role: \"assistant\"` message. Throws if no such message\ncan be found.\n\n#### `await .finalMessage()`\n\nA promise which resolves with the last message.\n\n#### `await .finalFunctionCall()`\n\nA promise which resolves with the last message with a defined `function_call`. Throws if no such message is\nfound.\n\n#### `await .finalFunctionCallResult()`\n\nA promise which resolves with the last message with a `role: \"function\"`. Throws if no such message is found.\n\n#### `await .totalUsage()` (without `stream`, usage is not currently reported with `stream`)\n\nA promise which resolves with the total usage.\n\n### Chat Fields\n\n#### `.messages`\n\nA mutable array of all messages in the conversation.\n\n#### `.controller`\n\nThe underlying `AbortController` for the runner.\n\n### Chat Examples\n\n#### Abort on a function call\n\nIf you have a function call flow which you intend to _end_ with a certain function call, then you can use the second\nargument `runner` given to the function to either mutate `runner.messages` or call `runner.abort()`.\n\n```ts\nimport OpenAI from 'openai';\n\nconst client = new OpenAI();\n\nasync function main() {\n  const runner = client.chat.completions\n    .runTools({\n      model: 'gpt-3.5-turbo',\n      messages: [{ role: 'user', content: \"How's the weather this week in Los Angeles?\" }],\n      tools: [\n        {\n          type: 'function',\n          function: {\n            function: function updateDatabase(props, runner) {\n              runner.abort()\n            },\n            …\n          }\n        },\n      ],\n    })\n    .on('message', (message) => console.log(message));\n\n  const finalFunctionCall = await runner.finalFunctionCall();\n  console.log('Final function call:', finalFunctionCall);\n}\n\nmain();\n```\n\n#### Integrate with `zod`\n\n[`zod`](https://www.npmjs.com/package/zod) is a schema validation library which can help with validating the\nassistant's response to make sure it conforms to a schema. Paired with [`zod-to-json-schema`](https://www.npmjs.com/package/zod-to-json-schema), the validation schema also acts as the `parameters` JSON Schema passed to the API.\n\n```ts\nimport OpenAI from 'openai';\nimport { z } from 'zod/v3';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\nconst client = new OpenAI();\n\nasync function main() {\n  const runner = client.chat.completions\n    .runTools({\n      model: 'gpt-3.5-turbo',\n      messages: [{ role: 'user', content: \"How's the weather this week in Los Angeles?\" }],\n      tools: [\n        {\n          type: 'function',\n          function: {\n            function: getWeather,\n            parse: GetWeatherParameters.parse,\n            parameters: zodToJsonSchema(GetWeatherParameters),\n          },\n        },\n      ],\n    })\n    .on('message', (message) => console.log(message));\n\n  const finalContent = await runner.finalContent();\n  console.log('Final content:', finalContent);\n}\n\nconst GetWeatherParameters = z.object({\n  location: z.enum(['Boston', 'New York City', 'Los Angeles', 'San Francisco']),\n});\n\nasync function getWeather(args: z.infer<typeof GetWeatherParameters>) {\n  const { location } = args;\n  // … do lookup …\n  return { temperature, precipitation };\n}\n\nmain();\n```\n\nSee a more fully-fledged example in [`examples/function-call-helpers-zod.ts`](examples/function-call-helpers-zod.ts).\n\n#### Integrate with Next.JS\n\nSee an example of a Next.JS integration here [`examples/stream-to-client-next.ts`](examples/stream-to-client-next.ts).\n\n#### Proxy Streaming to a Browser\n\nSee an example of using express to stream to a browser here [`examples/stream-to-client-express.ts`](examples/stream-to-client-express.ts).\n\n# Polling Helpers\n\nWhen interacting with the API some actions such as starting a Run and adding files to vector stores are asynchronous and take time to complete.\nThe SDK includes helper functions which will poll the status until it reaches a terminal state and then return the resulting object.\nIf an API method results in an action which could benefit from polling there will be a corresponding version of the\nmethod ending in `_AndPoll`.\n\nAll methods also allow you to set the polling frequency, how often the API is checked for an update, via a function argument (`pollIntervalMs`).\n\nThe polling methods are:\n\n```ts\nclient.beta.threads.createAndRunPoll(...)\nclient.beta.threads.runs.createAndPoll((...)\nclient.beta.threads.runs.submitToolOutputsAndPoll((...)\nclient.beta.vectorStores.files.uploadAndPoll((...)\nclient.beta.vectorStores.files.createAndPoll((...)\nclient.beta.vectorStores.fileBatches.createAndPoll((...)\nclient.beta.vectorStores.fileBatches.uploadAndPoll((...)\n```\n\n# Bulk Upload Helpers\n\nWhen creating and interacting with vector stores, you can use the polling helpers to monitor the status of operations.\nFor convenience, we also provide a bulk upload helper to allow you to simultaneously upload several files at once.\n\n```ts\nconst fileList = [\n  createReadStream('/home/data/example.pdf'),\n  ...\n];\n\nconst batch = await openai.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, {files: fileList});\n```\n"
  },
  {
    "path": "jest.config.ts",
    "content": "import type { JestConfigWithTsJest } from 'ts-jest';\n\nconst config: JestConfigWithTsJest = {\n  preset: 'ts-jest/presets/default-esm',\n  testEnvironment: 'node',\n  transform: {\n    '^.+\\\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }],\n  },\n  moduleNameMapper: {\n    '^openai$': '<rootDir>/src/index.ts',\n    '^openai/(.*)$': '<rootDir>/src/$1',\n  },\n  modulePathIgnorePatterns: [\n    '<rootDir>/ecosystem-tests/',\n    '<rootDir>/dist/',\n    '<rootDir>/deno/',\n    '<rootDir>/deno_tests/',\n    '<rootDir>/packages/',\n  ],\n  testPathIgnorePatterns: ['scripts'],\n  // prettierPath: require.resolve('prettier-2'),\n};\n\nexport default config;\n"
  },
  {
    "path": "jsr.json",
    "content": "{\n  \"name\": \"@openai/openai\",\n  \"version\": \"6.32.0\",\n  \"exports\": {\n    \".\": \"./index.ts\",\n    \"./helpers/zod\": \"./helpers/zod.ts\",\n    \"./beta/realtime/websocket\": \"./beta/realtime/websocket.ts\"\n  },\n  \"imports\": {\n    \"zod\": \"npm:zod@3\"\n  },\n  \"publish\": {\n    \"exclude\": [\n      \"!.\"\n    ]\n  }\n}\n"
  },
  {
    "path": "jsr.json.orig",
    "content": "{\n  \"name\": \"@openai/openai\",\n  \"version\": \"4.87.4\",\n  \"exports\": {\n    \".\": \"./index.ts\",\n    \"./helpers/zod\": \"./helpers/zod.ts\",\n    \"./beta/realtime/websocket\": \"./beta/realtime/websocket.ts\"\n    \"./realtime/websocket\": \"./realtime/websocket.ts\"\n  },\n  \"imports\": {\n    \"zod\": \"npm:zod@3\"\n  },\n  \"publish\": {\n    \"exclude\": [\n      \"!.\"\n    ]\n  }\n}\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"openai\",\n  \"version\": \"6.32.0\",\n  \"description\": \"The official TypeScript library for the OpenAI API\",\n  \"author\": \"OpenAI <support@openai.com>\",\n  \"types\": \"dist/index.d.ts\",\n  \"main\": \"dist/index.js\",\n  \"type\": \"commonjs\",\n  \"repository\": \"github:openai/openai-node\",\n  \"license\": \"Apache-2.0\",\n  \"packageManager\": \"yarn@1.22.22\",\n  \"files\": [\n    \"**/*\"\n  ],\n  \"private\": false,\n  \"publishConfig\": {\n    \"access\": \"public\"\n  },\n  \"scripts\": {\n    \"test\": \"./scripts/test\",\n    \"build\": \"./scripts/build\",\n    \"prepublishOnly\": \"echo 'to publish, run yarn build && (cd dist; yarn publish)' && exit 1\",\n    \"format\": \"./scripts/format\",\n    \"prepare\": \"if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build && ./scripts/utils/git-swap.sh; fi\",\n    \"tsn\": \"ts-node -r tsconfig-paths/register\",\n    \"lint\": \"./scripts/lint\",\n    \"fix\": \"./scripts/format\"\n  },\n  \"dependencies\": {},\n  \"devDependencies\": {\n    \"@arethetypeswrong/cli\": \"^0.17.0\",\n    \"@swc/core\": \"^1.3.102\",\n    \"@swc/jest\": \"^0.2.29\",\n    \"@types/jest\": \"^29.4.0\",\n    \"@types/ws\": \"^8.5.13\",\n    \"@types/node\": \"^20.17.6\",\n    \"@typescript-eslint/eslint-plugin\": \"8.31.1\",\n    \"@typescript-eslint/parser\": \"8.31.1\",\n    \"deep-object-diff\": \"^1.1.9\",\n    \"@typescript-eslint/typescript-estree\": \"8.31.1\",\n    \"eslint\": \"^9.39.1\",\n    \"eslint-plugin-prettier\": \"^5.4.1\",\n    \"eslint-plugin-unused-imports\": \"^4.1.4\",\n    \"execa\": \"^5.1.1\",\n    \"fast-check\": \"^3.22.0\",\n    \"iconv-lite\": \"^0.6.3\",\n    \"jest\": \"^29.4.0\",\n    \"prettier\": \"^3.0.0\",\n    \"publint\": \"^0.2.12\",\n    \"ws\": \"^8.18.3\",\n    \"@types/ws\": \"^8.5.13\",\n    \"ts-jest\": \"^29.1.0\",\n    \"ts-node\": \"^10.5.0\",\n    \"tsc-multi\": \"https://github.com/stainless-api/tsc-multi/releases/download/v1.1.9/tsc-multi.tgz\",\n    \"tsconfig-paths\": \"^4.0.0\",\n    \"tslib\": \"^2.8.1\",\n    \"typescript\": \"5.8.3\",\n    \"ws\": \"^8.18.0\",\n    \"zod\": \"^3.25 || ^4.0\",\n    \"typescript-eslint\": \"8.31.1\"\n  },\n  \"peerDependencies\": {\n    \"ws\": \"^8.18.0\"\n  },\n  \"peerDependenciesMeta\": {\n    \"ws\": {\n      \"optional\": true\n    }\n  },\n  \"bin\": {\n    \"openai\": \"bin/cli\"\n  },\n  \"overrides\": {\n    \"minimatch\": \"^9.0.5\"\n  },\n  \"pnpm\": {\n    \"overrides\": {\n      \"minimatch\": \"^9.0.5\"\n    }\n  },\n  \"resolutions\": {\n    \"minimatch\": \"^9.0.5\"\n  },\n  \"exports\": {\n    \".\": {\n      \"import\": \"./dist/index.mjs\",\n      \"require\": \"./dist/index.js\"\n    },\n    \"./*.mjs\": {\n      \"default\": \"./dist/*.mjs\"\n    },\n    \"./*.js\": {\n      \"default\": \"./dist/*.js\"\n    },\n    \"./*\": {\n      \"import\": \"./dist/*.mjs\",\n      \"require\": \"./dist/*.js\"\n    }\n  },\n  \"peerDependencies\": {\n    \"ws\": \"^8.18.0\",\n    \"zod\": \"^3.25 || ^4.0\"\n  },\n  \"peerDependenciesMeta\": {\n    \"ws\": {\n      \"optional\": true\n    },\n    \"zod\": {\n      \"optional\": true\n    }\n  }\n}\n"
  },
  {
    "path": "realtime.md",
    "content": "## Realtime API\n\nThe 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.\n\nThe 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).\n\nThis 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).\n\nBasic text based example with `ws`:\n\n```ts\n// requires `yarn add ws @types/ws`\nimport { OpenAIRealtimeWS } from 'openai/realtime/ws';\n\nconst rt = new OpenAIRealtimeWS({ model: 'gpt-realtime' });\n\n// access the underlying `ws.WebSocket` instance\nrt.socket.on('open', () => {\n  console.log('Connection opened!');\n  rt.send({\n    type: 'session.update',\n    session: {\n      modalities: ['text'],\n      model: 'gpt-4o-realtime-preview',\n    },\n  });\n\n  rt.send({\n    type: 'conversation.item.create',\n    item: {\n      type: 'message',\n      role: 'user',\n      content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],\n    },\n  });\n\n  rt.send({ type: 'response.create' });\n});\n\nrt.on('error', (err) => {\n  // in a real world scenario this should be logged somewhere as you\n  // likely want to continue processing events regardless of any errors\n  throw err;\n});\n\nrt.on('session.created', (event) => {\n  console.log('session created!', event.session);\n  console.log();\n});\n\nrt.on('response.text.delta', (event) => process.stdout.write(event.delta));\nrt.on('response.text.done', () => console.log());\n\nrt.on('response.done', () => rt.close());\n\nrt.socket.on('close', () => console.log('\\nConnection closed!'));\n```\n\nTo use the web API `WebSocket` implementation, replace `OpenAIRealtimeWS` with `OpenAIRealtimeWebSocket` and adjust any `rt.socket` access:\n\n```ts\nimport { OpenAIRealtimeWebSocket } from 'openai/realtime/websocket';\n\nconst rt = new OpenAIRealtimeWebSocket({ model: 'gpt-realtime' });\n// ...\nrt.socket.addEventListener('open', () => {\n  // ...\n});\n```\n\nA full example can be found [here](https://github.com/openai/openai-node/blob/master/examples/realtime/websocket.ts).\n\n### Realtime error handling\n\nWhen 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.\n\nIt is **highly recommended** that you register an `error` event listener and handle errors appropriately as typically the underlying connection is still usable.\n\n```ts\nconst rt = new OpenAIRealtimeWS({ model: 'gpt-realtime' });\nrt.on('error', (err) => {\n  // in a real world scenario this should be logged somewhere as you\n  // likely want to continue processing events regardless of any errors\n  throw err;\n});\n```\n"
  },
  {
    "path": "release-please-config.json",
    "content": "{\n  \"packages\": {\n    \".\": {}\n  },\n  \"$schema\": \"https://raw.githubusercontent.com/stainless-api/release-please/main/schemas/config.json\",\n  \"include-v-in-tag\": true,\n  \"include-component-in-tag\": false,\n  \"versioning\": \"prerelease\",\n  \"prerelease\": true,\n  \"bump-minor-pre-major\": true,\n  \"bump-patch-for-minor-pre-major\": false,\n  \"pull-request-header\": \"Automated Release PR\",\n  \"pull-request-title-pattern\": \"release: ${version}\",\n  \"changelog-sections\": [\n    {\n      \"type\": \"feat\",\n      \"section\": \"Features\"\n    },\n    {\n      \"type\": \"fix\",\n      \"section\": \"Bug Fixes\"\n    },\n    {\n      \"type\": \"perf\",\n      \"section\": \"Performance Improvements\"\n    },\n    {\n      \"type\": \"revert\",\n      \"section\": \"Reverts\"\n    },\n    {\n      \"type\": \"chore\",\n      \"section\": \"Chores\"\n    },\n    {\n      \"type\": \"docs\",\n      \"section\": \"Documentation\"\n    },\n    {\n      \"type\": \"style\",\n      \"section\": \"Styles\"\n    },\n    {\n      \"type\": \"refactor\",\n      \"section\": \"Refactors\"\n    },\n    {\n      \"type\": \"test\",\n      \"section\": \"Tests\",\n      \"hidden\": true\n    },\n    {\n      \"type\": \"build\",\n      \"section\": \"Build System\"\n    },\n    {\n      \"type\": \"ci\",\n      \"section\": \"Continuous Integration\",\n      \"hidden\": true\n    }\n  ],\n  \"release-type\": \"node\",\n  \"extra-files\": [\n    \"src/version.ts\",\n    \"README.md\",\n    {\n      \"type\": \"json\",\n      \"path\": \"jsr.json\",\n      \"jsonpath\": \"$.version\"\n    }\n  ]\n}\n"
  },
  {
    "path": "scripts/bootstrap",
    "content": "#!/usr/bin/env bash\n\nset -e\n\ncd \"$(dirname \"$0\")/..\"\n\nif [ -f \"Brewfile\" ] && [ \"$(uname -s)\" = \"Darwin\" ] && [ \"$SKIP_BREW\" != \"1\" ] && [ -t 0 ]; then\n  brew bundle check >/dev/null 2>&1 || {\n    echo -n \"==> Install Homebrew dependencies? (y/N): \"\n    read -r response\n    case \"$response\" in\n      [yY][eE][sS]|[yY])\n        brew bundle\n        ;;\n      *)\n        ;;\n    esac\n    echo\n  }\nfi\n\necho \"==> Installing Node dependencies…\"\n\nPACKAGE_MANAGER=$(command -v yarn >/dev/null 2>&1 && echo \"yarn\" || echo \"npm\")\n\n$PACKAGE_MANAGER install\n\ncd \"$(dirname \"$0\")/../examples\"\n$PACKAGE_MANAGER install\n"
  },
  {
    "path": "scripts/build",
    "content": "#!/usr/bin/env bash\n\nset -exuo pipefail\n\ncd \"$(dirname \"$0\")/..\"\n\nnode scripts/utils/check-version.cjs\n\n# Build into dist and will publish the package from there,\n# so that src/resources/foo.ts becomes <package root>/resources/foo.js\n# This way importing from `\"openai/resources/foo\"` works\n# even with `\"moduleResolution\": \"node\"`\n\nrm -rf dist; mkdir dist\n# Copy src to dist/src and build from dist/src into dist, so that\n# the source map for index.js.map will refer to ./src/index.ts etc\ncp -rp src README.md dist\nfor file in LICENSE CHANGELOG.md; do\n  if [ -e \"${file}\" ]; then cp \"${file}\" dist; fi\ndone\nif [ -e \"bin/cli\" ]; then\n  mkdir -p dist/bin\n  cp -p \"bin/cli\" dist/bin/;\nfi\nif [ -e \"bin/migration-config.json\" ]; then\n  mkdir -p dist/bin\n  cp -p \"bin/migration-config.json\" dist/bin/;\nfi\n# this converts the export map paths for the dist directory\n# and does a few other minor things\nnode scripts/utils/make-dist-package-json.cjs > dist/package.json\n\n# build to .js/.mjs/.d.ts files\n./node_modules/.bin/tsc-multi\n# we need to patch index.js so that `new module.exports()` works for cjs backwards\n# compat. No way to get that from index.ts because it would cause compile errors\n# when building .mjs\nnode scripts/utils/fix-index-exports.cjs\ncp tsconfig.dist-src.json dist/src/tsconfig.json\n\nnode scripts/utils/postprocess-files.cjs\n\n# make sure that nothing crashes when we require the output CJS or\n# import the output ESM\n(cd dist && node -e 'require(\"openai\")')\n(cd dist && node -e 'import(\"openai\")' --input-type=module)\n\nif [ \"${OPENAI_DISABLE_DENO_BUILD:-0}\" != \"1\" ] && [ -e ./scripts/build-deno ]\nthen\n  ./scripts/build-deno\nfi\n"
  },
  {
    "path": "scripts/build-deno",
    "content": "#!/usr/bin/env bash\n\nset -exuo pipefail\n\ncd \"$(dirname \"$0\")/..\"\n\nrm -rf dist-deno; mkdir dist-deno\ncp -rp src/* jsr.json dist-deno\n\nfor file in README.md LICENSE CHANGELOG.md; do\n  if [ -e \"${file}\" ]; then cp \"${file}\" dist-deno; fi\ndone\n\nnode scripts/utils/convert-jsr-readme.cjs ./dist-deno/README.md\n"
  },
  {
    "path": "scripts/detect-breaking-changes",
    "content": "#!/usr/bin/env bash\n\nset -e\n\ncd \"$(dirname \"$0\")/..\"\n\necho \"==> Detecting breaking changes\"\n\nTEST_PATHS=(\n\ttests/api-resources/completions.test.ts\n\ttests/api-resources/chat/chat.test.ts\n\ttests/api-resources/chat/completions/completions.test.ts\n\ttests/api-resources/chat/completions/messages.test.ts\n\ttests/api-resources/embeddings.test.ts\n\ttests/api-resources/files.test.ts\n\ttests/api-resources/images.test.ts\n\ttests/api-resources/audio/audio.test.ts\n\ttests/api-resources/audio/transcriptions.test.ts\n\ttests/api-resources/audio/translations.test.ts\n\ttests/api-resources/audio/speech.test.ts\n\ttests/api-resources/moderations.test.ts\n\ttests/api-resources/models.test.ts\n\ttests/api-resources/fine-tuning/fine-tuning.test.ts\n\ttests/api-resources/fine-tuning/jobs/jobs.test.ts\n\ttests/api-resources/fine-tuning/jobs/checkpoints.test.ts\n\ttests/api-resources/fine-tuning/checkpoints/checkpoints.test.ts\n\ttests/api-resources/fine-tuning/checkpoints/permissions.test.ts\n\ttests/api-resources/fine-tuning/alpha/alpha.test.ts\n\ttests/api-resources/fine-tuning/alpha/graders.test.ts\n\ttests/api-resources/vector-stores/vector-stores.test.ts\n\ttests/api-resources/vector-stores/files.test.ts\n\ttests/api-resources/vector-stores/file-batches.test.ts\n\ttests/api-resources/beta/beta.test.ts\n\ttests/api-resources/beta/realtime/realtime.test.ts\n\ttests/api-resources/beta/realtime/sessions.test.ts\n\ttests/api-resources/beta/realtime/transcription-sessions.test.ts\n\ttests/api-resources/beta/chatkit/chatkit.test.ts\n\ttests/api-resources/beta/chatkit/sessions.test.ts\n\ttests/api-resources/beta/chatkit/threads.test.ts\n\ttests/api-resources/beta/assistants.test.ts\n\ttests/api-resources/beta/threads/threads.test.ts\n\ttests/api-resources/beta/threads/runs/runs.test.ts\n\ttests/api-resources/beta/threads/runs/steps.test.ts\n\ttests/api-resources/beta/threads/messages.test.ts\n\ttests/api-resources/batches.test.ts\n\ttests/api-resources/uploads/uploads.test.ts\n\ttests/api-resources/uploads/parts.test.ts\n\ttests/api-resources/responses/responses.test.ts\n\ttests/api-resources/responses/input-items.test.ts\n\ttests/api-resources/responses/input-tokens.test.ts\n\ttests/api-resources/realtime/realtime.test.ts\n\ttests/api-resources/realtime/client-secrets.test.ts\n\ttests/api-resources/realtime/calls.test.ts\n\ttests/api-resources/conversations/conversations.test.ts\n\ttests/api-resources/conversations/items.test.ts\n\ttests/api-resources/evals/evals.test.ts\n\ttests/api-resources/evals/runs/runs.test.ts\n\ttests/api-resources/evals/runs/output-items.test.ts\n\ttests/api-resources/containers/containers.test.ts\n\ttests/api-resources/containers/files/files.test.ts\n\ttests/api-resources/containers/files/content.test.ts\n\ttests/api-resources/skills/skills.test.ts\n\ttests/api-resources/skills/content.test.ts\n\ttests/api-resources/skills/versions/versions.test.ts\n\ttests/api-resources/skills/versions/content.test.ts\n\ttests/api-resources/videos.test.ts\n\ttests/index.test.ts\n)\n\nfor PATHSPEC in \"${TEST_PATHS[@]}\"; do\n    # Try to check out previous versions of the test files\n    # with the current SDK.\n    git checkout \"$1\" -- \"${PATHSPEC}\" 2>/dev/null || true\ndone\n\n# Instead of running the tests, use the linter to check if an\n# older test is no longer compatible with the latest SDK.\n./scripts/lint\n"
  },
  {
    "path": "scripts/fast-format",
    "content": "#!/usr/bin/env bash\n\nset -euo pipefail\n\necho \"Script started with $# arguments\"\necho \"Arguments: $*\"\necho \"Script location: $(dirname \"$0\")\"\n\ncd \"$(dirname \"$0\")/..\"\necho \"Changed to directory: $(pwd)\"\n\nif [ $# -eq 0 ]; then\n    echo \"Usage: $0 <file-with-paths> [additional-formatter-args...]\"\n    echo \"The file should contain one file path per line\"\n    exit 1\nfi\n\nFILE_LIST=\"$1\"\n\necho \"Looking for file: $FILE_LIST\"\n\nif [ ! -f \"$FILE_LIST\" ]; then\n    echo \"Error: File '$FILE_LIST' not found\"\n    exit 1\nfi\n\necho \"==> Running eslint --fix\"\nESLINT_FILES=\"$(grep '\\.ts$' \"$FILE_LIST\" || true)\"\nif ! [ -z \"$ESLINT_FILES\" ]; then\n   echo \"$ESLINT_FILES\" | xargs ./node_modules/.bin/eslint --cache --fix\nfi\n\necho \"==> Running prettier --write\"\n# format things eslint didn't\nPRETTIER_FILES=\"$(grep '\\.\\(js\\|json\\)$' \"$FILE_LIST\" || true)\"\nif ! [ -z \"$PRETTIER_FILES\" ]; then\n   echo \"$PRETTIER_FILES\" | xargs ./node_modules/.bin/prettier \\\n      --write --cache --cache-strategy metadata --no-error-on-unmatched-pattern \\\n      '!**/dist' '!**/*.ts' '!**/*.mts' '!**/*.cts' '!**/*.js' '!**/*.mjs' '!**/*.cjs'\nfi\n"
  },
  {
    "path": "scripts/format",
    "content": "#!/usr/bin/env bash\n\nset -e\n\ncd \"$(dirname \"$0\")/..\"\n\necho \"==> Running eslint --fix\"\n./node_modules/.bin/eslint --fix .\n\necho \"==> Running prettier --write\"\n# format things eslint didn't\n./node_modules/.bin/prettier --write --cache --cache-strategy metadata . '!**/dist' '!**/*.ts' '!**/*.mts' '!**/*.cts' '!**/*.js' '!**/*.mjs' '!**/*.cjs'\n"
  },
  {
    "path": "scripts/lint",
    "content": "#!/usr/bin/env bash\n\nset -e\n\ncd \"$(dirname \"$0\")/..\"\n\necho \"==> Running eslint\"\n./node_modules/.bin/eslint .\n\necho \"==> Building\"\n./scripts/build\n\necho \"==> Checking types\"\n./node_modules/typescript/bin/tsc\n\necho \"==> Running Are The Types Wrong?\"\n./node_modules/.bin/attw --pack dist -f json >.attw.json || true\nnode scripts/utils/attw-report.cjs\n\necho \"==> Running publint\"\n./node_modules/.bin/publint dist\necho \"==> Running jsr publish --dry-run\"\n(cd dist-deno && npx jsr publish --dry-run --allow-dirty)\n"
  },
  {
    "path": "scripts/mock",
    "content": "#!/usr/bin/env bash\n\nset -e\n\ncd \"$(dirname \"$0\")/..\"\n\nif [[ -n \"$1\" && \"$1\" != '--'* ]]; then\n  URL=\"$1\"\n  shift\nelse\n  URL=\"$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)\"\nfi\n\n# Check if the URL is empty\nif [ -z \"$URL\" ]; then\n  echo \"Error: No OpenAPI spec path/url provided or found in .stats.yml\"\n  exit 1\nfi\n\necho \"==> Starting mock server with URL ${URL}\"\n\n# Run prism mock on the given spec\nif [ \"$1\" == \"--daemon\" ]; then\n  # Pre-install the package so the download doesn't eat into the startup timeout\n  npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism --version\n\n  npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock \"$URL\" &> .prism.log &\n\n  # Wait for server to come online (max 30s)\n  echo -n \"Waiting for server\"\n  attempts=0\n  while ! grep -q \"✖  fatal\\|Prism is listening\" \".prism.log\" ; do\n    attempts=$((attempts + 1))\n    if [ \"$attempts\" -ge 300 ]; then\n      echo\n      echo \"Timed out waiting for Prism server to start\"\n      cat .prism.log\n      exit 1\n    fi\n    echo -n \".\"\n    sleep 0.1\n  done\n\n  if grep -q \"✖  fatal\" \".prism.log\"; then\n    cat .prism.log\n    exit 1\n  fi\n\n  echo\nelse\n  npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock \"$URL\"\nfi\n"
  },
  {
    "path": "scripts/test",
    "content": "#!/usr/bin/env bash\n\nset -e\n\ncd \"$(dirname \"$0\")/..\"\n\nRED='\\033[0;31m'\nGREEN='\\033[0;32m'\nYELLOW='\\033[0;33m'\nNC='\\033[0m' # No Color\n\nfunction prism_is_running() {\n  curl --silent \"http://localhost:4010\" >/dev/null 2>&1\n}\n\nkill_server_on_port() {\n  pids=$(lsof -t -i tcp:\"$1\" || echo \"\")\n  if [ \"$pids\" != \"\" ]; then\n    kill \"$pids\"\n    echo \"Stopped $pids.\"\n  fi\n}\n\nfunction is_overriding_api_base_url() {\n  [ -n \"$TEST_API_BASE_URL\" ]\n}\n\nif ! is_overriding_api_base_url && ! prism_is_running ; then\n  # When we exit this script, make sure to kill the background mock server process\n  trap 'kill_server_on_port 4010' EXIT\n\n  # Start the dev server\n  ./scripts/mock --daemon\nfi\n\nif is_overriding_api_base_url ; then\n  echo -e \"${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}\"\n  echo\nelif ! prism_is_running ; then\n  echo -e \"${RED}ERROR:${NC} The test suite will not run without a mock Prism server\"\n  echo -e \"running against your OpenAPI spec.\"\n  echo\n  echo -e \"To run the server, pass in the path or url of your OpenAPI\"\n  echo -e \"spec to the prism command:\"\n  echo\n  echo -e \"  \\$ ${YELLOW}npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock path/to/your.openapi.yml${NC}\"\n  echo\n\n  exit 1\nelse\n  echo -e \"${GREEN}✔ Mock prism server is running with your OpenAPI spec${NC}\"\n  echo\nfi\n\necho \"==> Running tests\"\n./node_modules/.bin/jest \"$@\"\n"
  },
  {
    "path": "scripts/utils/attw-report.cjs",
    "content": "const fs = require('fs');\nconst problems = Object.values(JSON.parse(fs.readFileSync('.attw.json', 'utf-8')).problems)\n  .flat()\n  .filter(\n    (problem) =>\n      !(\n        // This is intentional, if the user specifies .mjs they get ESM.\n        (\n          (problem.kind === 'CJSResolvesToESM' && problem.entrypoint.endsWith('.mjs')) ||\n          // This is intentional for backwards compat reasons.\n          (problem.kind === 'MissingExportEquals' && problem.implementationFileName.endsWith('/index.js')) ||\n          // this is intentional, we deliberately attempt to import types that may not exist from parent node_modules\n          // folders to better support various runtimes without triggering automatic type acquisition.\n          (problem.kind === 'InternalResolutionError' && problem.moduleSpecifier.includes('node_modules'))\n        )\n      ),\n  );\nfs.unlinkSync('.attw.json');\nif (problems.length) {\n  process.stdout.write('The types are wrong!\\n' + JSON.stringify(problems, null, 2) + '\\n');\n  process.exitCode = 1;\n} else {\n  process.stdout.write('Types ok!\\n');\n}\n"
  },
  {
    "path": "scripts/utils/check-is-in-git-install.sh",
    "content": "#!/usr/bin/env bash\n# Check if you happen to call prepare for a repository that's already in node_modules.\n[ \"$(basename \"$(dirname \"$PWD\")\")\" = 'node_modules' ] ||\n# The name of the containing directory that 'npm` uses, which looks like\n# $HOME/.npm/_cacache/git-cloneXXXXXX\n[ \"$(basename \"$(dirname \"$PWD\")\")\" = 'tmp' ] ||\n# The name of the containing directory that 'yarn` uses, which looks like\n# $(yarn cache dir)/.tmp/XXXXX\n[ \"$(basename \"$(dirname \"$PWD\")\")\" = '.tmp' ]\n"
  },
  {
    "path": "scripts/utils/check-version.cjs",
    "content": "const fs = require('fs');\nconst path = require('path');\n\nconst main = () => {\n  const pkg = require('../../package.json');\n  const version = pkg['version'];\n  if (!version) throw 'The version property is not set in the package.json file';\n  if (typeof version !== 'string') {\n    throw `Unexpected type for the package.json version field; got ${typeof version}, expected string`;\n  }\n\n  const versionFile = path.resolve(__dirname, '..', '..', 'src', 'version.ts');\n  const contents = fs.readFileSync(versionFile, 'utf8');\n  const output = contents.replace(/(export const VERSION = ')(.*)(')/g, `$1${version}$3`);\n  fs.writeFileSync(versionFile, output);\n};\n\nif (require.main === module) {\n  main();\n}\n"
  },
  {
    "path": "scripts/utils/convert-jsr-readme.cjs",
    "content": "const fs = require('fs');\nconst { parse } = require('@typescript-eslint/parser');\nconst { TSError } = require('@typescript-eslint/typescript-estree');\n\n/**\n * Quick and dirty AST traversal\n */\nfunction traverse(node, visitor) {\n  if (!node || typeof node.type !== 'string') return;\n  visitor.node?.(node);\n  visitor[node.type]?.(node);\n  for (const key in node) {\n    const value = node[key];\n    if (Array.isArray(value)) {\n      for (const elem of value) traverse(elem, visitor);\n    } else if (value instanceof Object) {\n      traverse(value, visitor);\n    }\n  }\n}\n\n/**\n * Helper method for replacing arbitrary ranges of text in input code.\n */\nfunction replaceRanges(code, replacer) {\n  const replacements = [];\n  replacer({ replace: (range, replacement) => replacements.push({ range, replacement }) });\n\n  if (!replacements.length) return code;\n  replacements.sort((a, b) => a.range[0] - b.range[0]);\n  const overlapIndex = replacements.findIndex(\n    (r, index) => index > 0 && replacements[index - 1].range[1] > r.range[0],\n  );\n  if (overlapIndex >= 0) {\n    throw new Error(\n      `replacements overlap: ${JSON.stringify(replacements[overlapIndex - 1])} and ${JSON.stringify(\n        replacements[overlapIndex],\n      )}`,\n    );\n  }\n\n  const parts = [];\n  let end = 0;\n  for (const {\n    range: [from, to],\n    replacement,\n  } of replacements) {\n    if (from > end) parts.push(code.substring(end, from));\n    parts.push(replacement);\n    end = to;\n  }\n  if (end < code.length) parts.push(code.substring(end));\n  return parts.join('');\n}\n\nfunction replaceProcessEnv(content) {\n  // Replace process.env['KEY'] and process.env.KEY with Deno.env.get('KEY')\n  return content.replace(/process\\.env(?:\\.|\\[['\"])(.+?)(?:['\"]\\])/g, \"Deno.env.get('$1')\");\n}\n\nfunction replaceProcessStdout(content) {\n  return content.replace(/process\\.stdout.write\\(([^)]+)\\)/g, 'Deno.stdout.writeSync($1)');\n}\n\nfunction replaceInstallationDirections(content) {\n  // Remove npm installation section\n  return content.replace(/```sh\\nnpm install.*?\\n```.*### Installation from JSR\\n\\n/s, '');\n}\n\n/**\n * Maps over module paths in imports and exports\n */\nfunction replaceImports(code, config) {\n  try {\n    const ast = parse(code, { sourceType: 'module', range: true });\n    return replaceRanges(code, ({ replace }) =>\n      traverse(ast, {\n        node(node) {\n          switch (node.type) {\n            case 'ImportDeclaration':\n            case 'ExportNamedDeclaration':\n            case 'ExportAllDeclaration':\n            case 'ImportExpression':\n              if (node.source) {\n                const { range, value } = node.source;\n                if (value.startsWith(config.npm)) {\n                  replace(range, JSON.stringify(value.replace(config.npm, config.jsr)));\n                }\n              }\n          }\n        },\n      }),\n    );\n  } catch (e) {\n    if (e instanceof TSError) {\n      // This can error if the code block is not valid TS, in this case give up trying to transform the imports.\n      console.warn(`Original codeblock could not be parsed, replace import skipped: ${e}\\n\\n${code}`);\n      return code;\n    }\n    throw e;\n  }\n}\n\nfunction processReadme(config, file) {\n  try {\n    let readmeContent = fs.readFileSync(file, 'utf8');\n\n    // First replace installation directions\n    readmeContent = replaceInstallationDirections(readmeContent);\n\n    // Replace content in all code blocks with a single regex\n    readmeContent = readmeContent.replaceAll(\n      /```(?:typescript|ts|javascript|js)\\n([\\s\\S]*?)```/g,\n      (match, codeBlock) => {\n        try {\n          let transformedCode = codeBlock.trim();\n          transformedCode = replaceImports(transformedCode, config);\n          transformedCode = replaceProcessEnv(transformedCode);\n          transformedCode = replaceProcessStdout(transformedCode);\n          return '```typescript\\n' + transformedCode + '\\n```';\n        } catch (error) {\n          console.warn(`Failed to transform code block: ${error}\\n\\n${codeBlock}`);\n          return match; // Return original code block if transformation fails\n        }\n      },\n    );\n\n    fs.writeFileSync(file, readmeContent);\n  } catch (error) {\n    console.error('Error processing README:', error);\n    throw error;\n  }\n}\n\nconst config = {\n  npm: 'openai',\n  jsr: '@openai/openai',\n};\n\nprocessReadme(config, process.argv[2]);\n"
  },
  {
    "path": "scripts/utils/fix-index-exports.cjs",
    "content": "const fs = require('fs');\nconst path = require('path');\n\nconst indexJs =\n  process.env['DIST_PATH'] ?\n    path.resolve(process.env['DIST_PATH'], 'index.js')\n  : path.resolve(__dirname, '..', '..', 'dist', 'index.js');\n\nlet before = fs.readFileSync(indexJs, 'utf8');\nlet after = before.replace(\n  /^(\\s*Object\\.defineProperty\\s*\\(exports,\\s*[\"']__esModule[\"'].+)$/m,\n  `exports = module.exports = function (...args) {\n    return new exports.default(...args)\n  }\n  $1`.replace(/^  /gm, ''),\n);\nfs.writeFileSync(indexJs, after, 'utf8');\n"
  },
  {
    "path": "scripts/utils/git-swap.sh",
    "content": "#!/usr/bin/env bash\nset -exuo pipefail\n# the package is published to NPM from ./dist\n# we want the final file structure for git installs to match the npm installs, so we\n\n# delete everything except ./dist and ./node_modules\nfind . -maxdepth 1 -mindepth 1 ! -name 'dist' ! -name 'node_modules' -exec rm -rf '{}' +\n\n# move everything from ./dist to .\nmv dist/* .\n\n# delete the now-empty ./dist\nrmdir dist\n"
  },
  {
    "path": "scripts/utils/make-dist-package-json.cjs",
    "content": "const pkgJson = require(process.env['PKG_JSON_PATH'] || '../../package.json');\n\nfunction processExportMap(m) {\n  for (const key in m) {\n    const value = m[key];\n    if (typeof value === 'string') m[key] = value.replace(/^\\.\\/dist\\//, './');\n    else processExportMap(value);\n  }\n}\nprocessExportMap(pkgJson.exports);\n\nfor (const key of ['types', 'main', 'module']) {\n  if (typeof pkgJson[key] === 'string') pkgJson[key] = pkgJson[key].replace(/^(\\.\\/)?dist\\//, './');\n}\n\ndelete pkgJson.devDependencies;\ndelete pkgJson.scripts.prepack;\ndelete pkgJson.scripts.prepublishOnly;\ndelete pkgJson.scripts.prepare;\n\nconsole.log(JSON.stringify(pkgJson, null, 2));\n"
  },
  {
    "path": "scripts/utils/postprocess-files.cjs",
    "content": "// @ts-check\nconst fs = require('fs');\nconst path = require('path');\n\nconst distDir =\n  process.env['DIST_PATH'] ?\n    path.resolve(process.env['DIST_PATH'])\n  : path.resolve(__dirname, '..', '..', 'dist');\n\nasync function* walk(dir) {\n  for await (const d of await fs.promises.opendir(dir)) {\n    const entry = path.join(dir, d.name);\n    if (d.isDirectory()) yield* walk(entry);\n    else if (d.isFile()) yield entry;\n  }\n}\n\nasync function postprocess() {\n  for await (const file of walk(distDir)) {\n    if (!/(\\.d)?[cm]?ts$/.test(file)) continue;\n\n    const code = await fs.promises.readFile(file, 'utf8');\n\n    // strip out lib=\"dom\", types=\"node\", and types=\"react\" references; these\n    // are needed at build time, but would pollute the user's TS environment\n    const transformed = code.replace(\n      /^ *\\/\\/\\/ *<reference +(lib=\"dom\"|types=\"(node|react)\").*?\\n/gm,\n      // replace with same number of characters to avoid breaking source maps\n      (match) => ' '.repeat(match.length - 1) + '\\n',\n    );\n\n    if (transformed !== code) {\n      console.error(`wrote ${path.relative(process.cwd(), file)}`);\n      await fs.promises.writeFile(file, transformed, 'utf8');\n    }\n  }\n\n  const newExports = {\n    '.': {\n      require: {\n        types: './index.d.ts',\n        default: './index.js',\n      },\n      types: './index.d.mts',\n      default: './index.mjs',\n    },\n  };\n\n  for (const entry of await fs.promises.readdir(distDir, { withFileTypes: true })) {\n    if (entry.isDirectory() && entry.name !== 'src' && entry.name !== 'internal' && entry.name !== 'bin') {\n      const subpath = './' + entry.name;\n      newExports[subpath + '/*.mjs'] = {\n        default: subpath + '/*.mjs',\n      };\n      newExports[subpath + '/*.js'] = {\n        default: subpath + '/*.js',\n      };\n      newExports[subpath + '/*'] = {\n        import: subpath + '/*.mjs',\n        require: subpath + '/*.js',\n      };\n    } else if (entry.isFile() && /\\.[cm]?js$/.test(entry.name)) {\n      const { name, ext } = path.parse(entry.name);\n      const subpathWithoutExt = './' + name;\n      const subpath = './' + entry.name;\n      newExports[subpathWithoutExt] ||= { import: undefined, require: undefined };\n      const isModule = ext[1] === 'm';\n      if (isModule) {\n        newExports[subpathWithoutExt].import = subpath;\n      } else {\n        newExports[subpathWithoutExt].require = subpath;\n      }\n      newExports[subpath] = {\n        default: subpath,\n      };\n    }\n  }\n  await fs.promises.writeFile(\n    'dist/package.json',\n    JSON.stringify(\n      Object.assign(\n        /** @type {Record<String, unknown>} */ (\n          JSON.parse(await fs.promises.readFile('dist/package.json', 'utf-8'))\n        ),\n        {\n          exports: newExports,\n        },\n      ),\n      null,\n      2,\n    ),\n  );\n}\npostprocess();\n"
  },
  {
    "path": "scripts/utils/upload-artifact.sh",
    "content": "#!/usr/bin/env bash\nset -exuo pipefail\n\nRESPONSE=$(curl -X POST \"$URL\" \\\n  -H \"Authorization: Bearer $AUTH\" \\\n  -H \"Content-Type: application/json\")\n\nSIGNED_URL=$(echo \"$RESPONSE\" | jq -r '.url')\n\nif [[ \"$SIGNED_URL\" == \"null\" ]]; then\n  echo -e \"\\033[31mFailed to get signed URL.\\033[0m\"\n  exit 1\nfi\n\nTARBALL=$(cd dist && npm pack --silent)\n\nUPLOAD_RESPONSE=$(curl -v -X PUT \\\n  -H \"Content-Type: application/gzip\" \\\n  --data-binary \"@dist/$TARBALL\" \"$SIGNED_URL\" 2>&1)\n\nif echo \"$UPLOAD_RESPONSE\" | grep -q \"HTTP/[0-9.]* 200\"; then\n  echo -e \"\\033[32mUploaded build to Stainless storage.\\033[0m\"\n  echo -e \"\\033[32mInstallation: npm install 'https://pkg.stainless.com/s/openai-typescript/$SHA'\\033[0m\"\nelse\n  echo -e \"\\033[31mFailed to upload artifact.\\033[0m\"\n  exit 1\nfi\n"
  },
  {
    "path": "src/_vendor/partial-json-parser/README.md",
    "content": "# Partial JSON Parser\n\nVendored from https://www.npmjs.com/package/partial-json with some modifications\n"
  },
  {
    "path": "src/_vendor/partial-json-parser/parser.ts",
    "content": "const STR = 0b000000001;\nconst NUM = 0b000000010;\nconst ARR = 0b000000100;\nconst OBJ = 0b000001000;\nconst NULL = 0b000010000;\nconst BOOL = 0b000100000;\nconst NAN = 0b001000000;\nconst INFINITY = 0b010000000;\nconst MINUS_INFINITY = 0b100000000;\n\nconst INF = INFINITY | MINUS_INFINITY;\nconst SPECIAL = NULL | BOOL | INF | NAN;\nconst ATOM = STR | NUM | SPECIAL;\nconst COLLECTION = ARR | OBJ;\nconst ALL = ATOM | COLLECTION;\n\nconst Allow = {\n  STR,\n  NUM,\n  ARR,\n  OBJ,\n  NULL,\n  BOOL,\n  NAN,\n  INFINITY,\n  MINUS_INFINITY,\n  INF,\n  SPECIAL,\n  ATOM,\n  COLLECTION,\n  ALL,\n};\n\n// The JSON string segment was unable to be parsed completely\nclass PartialJSON extends Error {}\n\nclass MalformedJSON extends Error {}\n\n/**\n * Parse incomplete JSON\n * @param {string} jsonString Partial JSON to be parsed\n * @param {number} allowPartial Specify what types are allowed to be partial, see {@link Allow} for details\n * @returns The parsed JSON\n * @throws {PartialJSON} If the JSON is incomplete (related to the `allow` parameter)\n * @throws {MalformedJSON} If the JSON is malformed\n */\nfunction parseJSON(jsonString: string, allowPartial: number = Allow.ALL): any {\n  if (typeof jsonString !== 'string') {\n    throw new TypeError(`expecting str, got ${typeof jsonString}`);\n  }\n  if (!jsonString.trim()) {\n    throw new Error(`${jsonString} is empty`);\n  }\n  return _parseJSON(jsonString.trim(), allowPartial);\n}\n\nconst _parseJSON = (jsonString: string, allow: number) => {\n  const length = jsonString.length;\n  let index = 0;\n\n  const markPartialJSON = (msg: string) => {\n    throw new PartialJSON(`${msg} at position ${index}`);\n  };\n\n  const throwMalformedError = (msg: string) => {\n    throw new MalformedJSON(`${msg} at position ${index}`);\n  };\n\n  const parseAny: () => any = () => {\n    skipBlank();\n    if (index >= length) markPartialJSON('Unexpected end of input');\n    if (jsonString[index] === '\"') return parseStr();\n    if (jsonString[index] === '{') return parseObj();\n    if (jsonString[index] === '[') return parseArr();\n    if (\n      jsonString.substring(index, index + 4) === 'null' ||\n      (Allow.NULL & allow && length - index < 4 && 'null'.startsWith(jsonString.substring(index)))\n    ) {\n      index += 4;\n      return null;\n    }\n    if (\n      jsonString.substring(index, index + 4) === 'true' ||\n      (Allow.BOOL & allow && length - index < 4 && 'true'.startsWith(jsonString.substring(index)))\n    ) {\n      index += 4;\n      return true;\n    }\n    if (\n      jsonString.substring(index, index + 5) === 'false' ||\n      (Allow.BOOL & allow && length - index < 5 && 'false'.startsWith(jsonString.substring(index)))\n    ) {\n      index += 5;\n      return false;\n    }\n    if (\n      jsonString.substring(index, index + 8) === 'Infinity' ||\n      (Allow.INFINITY & allow && length - index < 8 && 'Infinity'.startsWith(jsonString.substring(index)))\n    ) {\n      index += 8;\n      return Infinity;\n    }\n    if (\n      jsonString.substring(index, index + 9) === '-Infinity' ||\n      (Allow.MINUS_INFINITY & allow &&\n        1 < length - index &&\n        length - index < 9 &&\n        '-Infinity'.startsWith(jsonString.substring(index)))\n    ) {\n      index += 9;\n      return -Infinity;\n    }\n    if (\n      jsonString.substring(index, index + 3) === 'NaN' ||\n      (Allow.NAN & allow && length - index < 3 && 'NaN'.startsWith(jsonString.substring(index)))\n    ) {\n      index += 3;\n      return NaN;\n    }\n    return parseNum();\n  };\n\n  const parseStr: () => string = () => {\n    const start = index;\n    let escape = false;\n    index++; // skip initial quote\n    while (index < length && (jsonString[index] !== '\"' || (escape && jsonString[index - 1] === '\\\\'))) {\n      escape = jsonString[index] === '\\\\' ? !escape : false;\n      index++;\n    }\n    if (jsonString.charAt(index) == '\"') {\n      try {\n        return JSON.parse(jsonString.substring(start, ++index - Number(escape)));\n      } catch (e) {\n        throwMalformedError(String(e));\n      }\n    } else if (Allow.STR & allow) {\n      try {\n        return JSON.parse(jsonString.substring(start, index - Number(escape)) + '\"');\n      } catch (e) {\n        // SyntaxError: Invalid escape sequence\n        return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf('\\\\')) + '\"');\n      }\n    }\n    markPartialJSON('Unterminated string literal');\n  };\n\n  const parseObj = () => {\n    index++; // skip initial brace\n    skipBlank();\n    const obj: Record<string, any> = {};\n    try {\n      while (jsonString[index] !== '}') {\n        skipBlank();\n        if (index >= length && Allow.OBJ & allow) return obj;\n        const key = parseStr();\n        skipBlank();\n        index++; // skip colon\n        try {\n          const value = parseAny();\n          Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });\n        } catch (e) {\n          if (Allow.OBJ & allow) return obj;\n          else throw e;\n        }\n        skipBlank();\n        if (jsonString[index] === ',') index++; // skip comma\n      }\n    } catch (e) {\n      if (Allow.OBJ & allow) return obj;\n      else markPartialJSON(\"Expected '}' at end of object\");\n    }\n    index++; // skip final brace\n    return obj;\n  };\n\n  const parseArr = () => {\n    index++; // skip initial bracket\n    const arr = [];\n    try {\n      while (jsonString[index] !== ']') {\n        arr.push(parseAny());\n        skipBlank();\n        if (jsonString[index] === ',') {\n          index++; // skip comma\n        }\n      }\n    } catch (e) {\n      if (Allow.ARR & allow) {\n        return arr;\n      }\n      markPartialJSON(\"Expected ']' at end of array\");\n    }\n    index++; // skip final bracket\n    return arr;\n  };\n\n  const parseNum = () => {\n    if (index === 0) {\n      if (jsonString === '-' && Allow.NUM & allow) markPartialJSON(\"Not sure what '-' is\");\n      try {\n        return JSON.parse(jsonString);\n      } catch (e) {\n        if (Allow.NUM & allow) {\n          try {\n            if ('.' === jsonString[jsonString.length - 1])\n              return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf('.')));\n            return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf('e')));\n          } catch (e) {}\n        }\n        throwMalformedError(String(e));\n      }\n    }\n\n    const start = index;\n\n    if (jsonString[index] === '-') index++;\n    while (jsonString[index] && !',]}'.includes(jsonString[index]!)) index++;\n\n    if (index == length && !(Allow.NUM & allow)) markPartialJSON('Unterminated number literal');\n\n    try {\n      return JSON.parse(jsonString.substring(start, index));\n    } catch (e) {\n      if (jsonString.substring(start, index) === '-' && Allow.NUM & allow)\n        markPartialJSON(\"Not sure what '-' is\");\n      try {\n        return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf('e')));\n      } catch (e) {\n        throwMalformedError(String(e));\n      }\n    }\n  };\n\n  const skipBlank = () => {\n    while (index < length && ' \\n\\r\\t'.includes(jsonString[index]!)) {\n      index++;\n    }\n  };\n\n  return parseAny();\n};\n\n// using this function with malformed JSON is undefined behavior\nconst partialParse = (input: string) => parseJSON(input, Allow.ALL ^ Allow.NUM);\n\nexport { partialParse, PartialJSON, MalformedJSON };\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/LICENSE",
    "content": "ISC License\n\nCopyright (c) 2020, Stefan Terdell\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted, provided that the above\ncopyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\nWITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\nANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\nWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\nACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\nOR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/Options.ts",
    "content": "import { ZodSchema, ZodTypeDef } from 'zod/v3';\nimport { Refs, Seen } from './Refs';\nimport { JsonSchema7Type } from './parseDef';\n\nexport type Targets = 'jsonSchema7' | 'jsonSchema2019-09' | 'openApi3';\n\nexport type DateStrategy = 'format:date-time' | 'format:date' | 'string' | 'integer';\n\nexport const ignoreOverride = Symbol('Let zodToJsonSchema decide on which parser to use');\n\nexport type Options<Target extends Targets = 'jsonSchema7'> = {\n  name: string | undefined;\n  $refStrategy: 'root' | 'relative' | 'none' | 'seen' | 'extract-to-root';\n  basePath: string[];\n  effectStrategy: 'input' | 'any';\n  pipeStrategy: 'input' | 'output' | 'all';\n  dateStrategy: DateStrategy | DateStrategy[];\n  mapStrategy: 'entries' | 'record';\n  removeAdditionalStrategy: 'passthrough' | 'strict';\n  nullableStrategy: 'from-target' | 'property';\n  target: Target;\n  strictUnions: boolean;\n  definitionPath: string;\n  definitions: Record<string, ZodSchema | ZodTypeDef>;\n  errorMessages: boolean;\n  markdownDescription: boolean;\n  patternStrategy: 'escape' | 'preserve';\n  applyRegexFlags: boolean;\n  emailStrategy: 'format:email' | 'format:idn-email' | 'pattern:zod';\n  base64Strategy: 'format:binary' | 'contentEncoding:base64' | 'pattern:zod';\n  nameStrategy: 'ref' | 'duplicate-ref' | 'title';\n  override?: (\n    def: ZodTypeDef,\n    refs: Refs,\n    seen: Seen | undefined,\n    forceResolution?: boolean,\n  ) => JsonSchema7Type | undefined | typeof ignoreOverride;\n  openaiStrictMode?: boolean;\n};\n\nconst defaultOptions: Omit<Options, 'definitions' | 'basePath'> = {\n  name: undefined,\n  $refStrategy: 'root',\n  effectStrategy: 'input',\n  pipeStrategy: 'all',\n  dateStrategy: 'format:date-time',\n  mapStrategy: 'entries',\n  nullableStrategy: 'from-target',\n  removeAdditionalStrategy: 'passthrough',\n  definitionPath: 'definitions',\n  target: 'jsonSchema7',\n  strictUnions: false,\n  errorMessages: false,\n  markdownDescription: false,\n  patternStrategy: 'escape',\n  applyRegexFlags: false,\n  emailStrategy: 'format:email',\n  base64Strategy: 'contentEncoding:base64',\n  nameStrategy: 'ref',\n};\n\nexport const getDefaultOptions = <Target extends Targets>(\n  options: Partial<Options<Target>> | string | undefined,\n) => {\n  // We need to add `definitions` here as we may mutate it\n  return (\n    typeof options === 'string' ?\n      {\n        ...defaultOptions,\n        basePath: ['#'],\n        definitions: {},\n        name: options,\n      }\n    : {\n        ...defaultOptions,\n        basePath: ['#'],\n        definitions: {},\n        ...options,\n      }) as Options<Target>;\n};\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/README.md",
    "content": "# Zod to Json Schema\n\nVendored version of https://github.com/StefanTerdell/zod-to-json-schema that has been updated to generate JSON Schemas that are compatible with OpenAI's [strict mode](https://platform.openai.com/docs/guides/structured-outputs/supported-schemas)\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/Refs.ts",
    "content": "import type { ZodTypeDef } from 'zod/v3';\nimport { getDefaultOptions, Options, Targets } from './Options';\nimport { JsonSchema7Type } from './parseDef';\nimport { zodDef } from './util';\n\nexport type Refs = {\n  seen: Map<ZodTypeDef, Seen>;\n  /**\n   * Set of all the `$ref`s we created, e.g. `Set(['#/$defs/ui'])`\n   * this notable does not include any `definitions` that were\n   * explicitly given as an option.\n   */\n  seenRefs: Set<string>;\n  currentPath: string[];\n  propertyPath: string[] | undefined;\n} & Options<Targets>;\n\nexport type Seen = {\n  def: ZodTypeDef;\n  path: string[];\n  jsonSchema: JsonSchema7Type | undefined;\n};\n\nexport const getRefs = (options?: string | Partial<Options<Targets>>): Refs => {\n  const _options = getDefaultOptions(options);\n  const currentPath =\n    _options.name !== undefined ?\n      [..._options.basePath, _options.definitionPath, _options.name]\n    : _options.basePath;\n  return {\n    ..._options,\n    currentPath: currentPath,\n    propertyPath: undefined,\n    seenRefs: new Set(),\n    seen: new Map(\n      Object.entries(_options.definitions).map(([name, def]) => [\n        zodDef(def),\n        {\n          def: zodDef(def),\n          path: [..._options.basePath, _options.definitionPath, name],\n          // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.\n          jsonSchema: undefined,\n        },\n      ]),\n    ),\n  };\n};\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/errorMessages.ts",
    "content": "import { JsonSchema7TypeUnion } from './parseDef';\nimport { Refs } from './Refs';\n\nexport type ErrorMessages<T extends JsonSchema7TypeUnion, OmitProperties extends string = ''> = Partial<\n  Omit<{ [key in keyof T]: string }, OmitProperties | 'type' | 'errorMessages'>\n>;\n\nexport function addErrorMessage<T extends { errorMessage?: ErrorMessages<any> }>(\n  res: T,\n  key: keyof T,\n  errorMessage: string | undefined,\n  refs: Refs,\n) {\n  if (!refs?.errorMessages) return;\n  if (errorMessage) {\n    res.errorMessage = {\n      ...res.errorMessage,\n      [key]: errorMessage,\n    };\n  }\n}\n\nexport function setResponseValueAndErrors<\n  Json7Type extends JsonSchema7TypeUnion & {\n    errorMessage?: ErrorMessages<Json7Type>;\n  },\n  Key extends keyof Omit<Json7Type, 'errorMessage'>,\n>(res: Json7Type, key: Key, value: Json7Type[Key], errorMessage: string | undefined, refs: Refs) {\n  res[key] = value;\n  addErrorMessage(res, key, errorMessage, refs);\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/index.ts",
    "content": "export * from './Options';\nexport * from './Refs';\nexport * from './errorMessages';\nexport * from './parseDef';\nexport * from './parsers/any';\nexport * from './parsers/array';\nexport * from './parsers/bigint';\nexport * from './parsers/boolean';\nexport * from './parsers/branded';\nexport * from './parsers/catch';\nexport * from './parsers/date';\nexport * from './parsers/default';\nexport * from './parsers/effects';\nexport * from './parsers/enum';\nexport * from './parsers/intersection';\nexport * from './parsers/literal';\nexport * from './parsers/map';\nexport * from './parsers/nativeEnum';\nexport * from './parsers/never';\nexport * from './parsers/null';\nexport * from './parsers/nullable';\nexport * from './parsers/number';\nexport * from './parsers/object';\nexport * from './parsers/optional';\nexport * from './parsers/pipeline';\nexport * from './parsers/promise';\nexport * from './parsers/readonly';\nexport * from './parsers/record';\nexport * from './parsers/set';\nexport * from './parsers/string';\nexport * from './parsers/tuple';\nexport * from './parsers/undefined';\nexport * from './parsers/union';\nexport * from './parsers/unknown';\nexport * from './zodToJsonSchema';\nimport { zodToJsonSchema } from './zodToJsonSchema';\nexport default zodToJsonSchema;\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parseDef.ts",
    "content": "import { ZodFirstPartyTypeKind, ZodTypeDef } from 'zod/v3';\nimport { JsonSchema7AnyType, parseAnyDef } from './parsers/any';\nimport { JsonSchema7ArrayType, parseArrayDef } from './parsers/array';\nimport { JsonSchema7BigintType, parseBigintDef } from './parsers/bigint';\nimport { JsonSchema7BooleanType, parseBooleanDef } from './parsers/boolean';\nimport { parseBrandedDef } from './parsers/branded';\nimport { parseCatchDef } from './parsers/catch';\nimport { JsonSchema7DateType, parseDateDef } from './parsers/date';\nimport { parseDefaultDef } from './parsers/default';\nimport { parseEffectsDef } from './parsers/effects';\nimport { JsonSchema7EnumType, parseEnumDef } from './parsers/enum';\nimport { JsonSchema7AllOfType, parseIntersectionDef } from './parsers/intersection';\nimport { JsonSchema7LiteralType, parseLiteralDef } from './parsers/literal';\nimport { JsonSchema7MapType, parseMapDef } from './parsers/map';\nimport { JsonSchema7NativeEnumType, parseNativeEnumDef } from './parsers/nativeEnum';\nimport { JsonSchema7NeverType, parseNeverDef } from './parsers/never';\nimport { JsonSchema7NullType, parseNullDef } from './parsers/null';\nimport { JsonSchema7NullableType, parseNullableDef } from './parsers/nullable';\nimport { JsonSchema7NumberType, parseNumberDef } from './parsers/number';\nimport { JsonSchema7ObjectType, parseObjectDef } from './parsers/object';\nimport { parseOptionalDef } from './parsers/optional';\nimport { parsePipelineDef } from './parsers/pipeline';\nimport { parsePromiseDef } from './parsers/promise';\nimport { JsonSchema7RecordType, parseRecordDef } from './parsers/record';\nimport { JsonSchema7SetType, parseSetDef } from './parsers/set';\nimport { JsonSchema7StringType, parseStringDef } from './parsers/string';\nimport { JsonSchema7TupleType, parseTupleDef } from './parsers/tuple';\nimport { JsonSchema7UndefinedType, parseUndefinedDef } from './parsers/undefined';\nimport { JsonSchema7UnionType, parseUnionDef } from './parsers/union';\nimport { JsonSchema7UnknownType, parseUnknownDef } from './parsers/unknown';\nimport { Refs, Seen } from './Refs';\nimport { parseReadonlyDef } from './parsers/readonly';\nimport { ignoreOverride } from './Options';\n\ntype JsonSchema7RefType = { $ref: string };\ntype JsonSchema7Meta = {\n  title?: string;\n  default?: any;\n  description?: string;\n  markdownDescription?: string;\n};\n\nexport type JsonSchema7TypeUnion =\n  | JsonSchema7StringType\n  | JsonSchema7ArrayType\n  | JsonSchema7NumberType\n  | JsonSchema7BigintType\n  | JsonSchema7BooleanType\n  | JsonSchema7DateType\n  | JsonSchema7EnumType\n  | JsonSchema7LiteralType\n  | JsonSchema7NativeEnumType\n  | JsonSchema7NullType\n  | JsonSchema7NumberType\n  | JsonSchema7ObjectType\n  | JsonSchema7RecordType\n  | JsonSchema7TupleType\n  | JsonSchema7UnionType\n  | JsonSchema7UndefinedType\n  | JsonSchema7RefType\n  | JsonSchema7NeverType\n  | JsonSchema7MapType\n  | JsonSchema7AnyType\n  | JsonSchema7NullableType\n  | JsonSchema7AllOfType\n  | JsonSchema7UnknownType\n  | JsonSchema7SetType;\n\nexport type JsonSchema7Type = JsonSchema7TypeUnion & JsonSchema7Meta;\n\nexport function parseDef(\n  def: ZodTypeDef,\n  refs: Refs,\n  forceResolution = false, // Forces a new schema to be instantiated even though its def has been seen. Used for improving refs in definitions. See https://github.com/StefanTerdell/zod-to-json-schema/pull/61.\n): JsonSchema7Type | undefined {\n  const seenItem = refs.seen.get(def);\n\n  if (refs.override) {\n    const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);\n\n    if (overrideResult !== ignoreOverride) {\n      return overrideResult;\n    }\n  }\n\n  if (seenItem && !forceResolution) {\n    const seenSchema = get$ref(seenItem, refs);\n\n    if (seenSchema !== undefined) {\n      if ('$ref' in seenSchema) {\n        refs.seenRefs.add(seenSchema.$ref);\n      }\n\n      return seenSchema;\n    }\n  }\n\n  const newItem: Seen = { def, path: refs.currentPath, jsonSchema: undefined };\n\n  refs.seen.set(def, newItem);\n\n  const jsonSchema = selectParser(def, (def as any).typeName, refs, forceResolution);\n\n  if (jsonSchema) {\n    addMeta(def, refs, jsonSchema);\n  }\n\n  newItem.jsonSchema = jsonSchema;\n\n  return jsonSchema;\n}\n\nconst get$ref = (\n  item: Seen,\n  refs: Refs,\n):\n  | {\n      $ref: string;\n    }\n  | {}\n  | undefined => {\n  switch (refs.$refStrategy) {\n    case 'root':\n      return { $ref: item.path.join('/') };\n    // this case is needed as OpenAI strict mode doesn't support top-level `$ref`s, i.e.\n    // the top-level schema *must* be `{\"type\": \"object\", \"properties\": {...}}` but if we ever\n    // need to define a `$ref`, relative `$ref`s aren't supported, so we need to extract\n    // the schema to `#/definitions/` and reference that.\n    //\n    // e.g. if we need to reference a schema at\n    // `[\"#\",\"definitions\",\"contactPerson\",\"properties\",\"person1\",\"properties\",\"name\"]`\n    // then we'll extract it out to `contactPerson_properties_person1_properties_name`\n    case 'extract-to-root':\n      const name = item.path.slice(refs.basePath.length + 1).join('_');\n\n      // we don't need to extract the root schema in this case, as it's already\n      // been added to the definitions\n      if (name !== refs.name && refs.nameStrategy === 'duplicate-ref') {\n        refs.definitions[name] = item.def;\n      }\n\n      return { $ref: [...refs.basePath, refs.definitionPath, name].join('/') };\n    case 'relative':\n      return { $ref: getRelativePath(refs.currentPath, item.path) };\n    case 'none':\n    case 'seen': {\n      if (\n        item.path.length < refs.currentPath.length &&\n        item.path.every((value, index) => refs.currentPath[index] === value)\n      ) {\n        console.warn(`Recursive reference detected at ${refs.currentPath.join('/')}! Defaulting to any`);\n\n        return {};\n      }\n\n      return refs.$refStrategy === 'seen' ? {} : undefined;\n    }\n  }\n};\n\nconst getRelativePath = (pathA: string[], pathB: string[]) => {\n  let i = 0;\n  for (; i < pathA.length && i < pathB.length; i++) {\n    if (pathA[i] !== pathB[i]) break;\n  }\n  return [(pathA.length - i).toString(), ...pathB.slice(i)].join('/');\n};\n\nconst selectParser = (\n  def: any,\n  typeName: ZodFirstPartyTypeKind,\n  refs: Refs,\n  forceResolution: boolean,\n): JsonSchema7Type | undefined => {\n  switch (typeName) {\n    case ZodFirstPartyTypeKind.ZodString:\n      return parseStringDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodNumber:\n      return parseNumberDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodObject:\n      return parseObjectDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodBigInt:\n      return parseBigintDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodBoolean:\n      return parseBooleanDef();\n    case ZodFirstPartyTypeKind.ZodDate:\n      return parseDateDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodUndefined:\n      return parseUndefinedDef();\n    case ZodFirstPartyTypeKind.ZodNull:\n      return parseNullDef(refs);\n    case ZodFirstPartyTypeKind.ZodArray:\n      return parseArrayDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodUnion:\n    case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:\n      return parseUnionDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodIntersection:\n      return parseIntersectionDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodTuple:\n      return parseTupleDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodRecord:\n      return parseRecordDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodLiteral:\n      return parseLiteralDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodEnum:\n      return parseEnumDef(def);\n    case ZodFirstPartyTypeKind.ZodNativeEnum:\n      return parseNativeEnumDef(def);\n    case ZodFirstPartyTypeKind.ZodNullable:\n      return parseNullableDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodOptional:\n      return parseOptionalDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodMap:\n      return parseMapDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodSet:\n      return parseSetDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodLazy:\n      return parseDef(def.getter()._def, refs);\n    case ZodFirstPartyTypeKind.ZodPromise:\n      return parsePromiseDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodNaN:\n    case ZodFirstPartyTypeKind.ZodNever:\n      return parseNeverDef();\n    case ZodFirstPartyTypeKind.ZodEffects:\n      return parseEffectsDef(def, refs, forceResolution);\n    case ZodFirstPartyTypeKind.ZodAny:\n      return parseAnyDef();\n    case ZodFirstPartyTypeKind.ZodUnknown:\n      return parseUnknownDef();\n    case ZodFirstPartyTypeKind.ZodDefault:\n      return parseDefaultDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodBranded:\n      return parseBrandedDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodReadonly:\n      return parseReadonlyDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodCatch:\n      return parseCatchDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodPipeline:\n      return parsePipelineDef(def, refs);\n    case ZodFirstPartyTypeKind.ZodFunction:\n    case ZodFirstPartyTypeKind.ZodVoid:\n    case ZodFirstPartyTypeKind.ZodSymbol:\n      return undefined;\n    default:\n      return ((_: never) => undefined)(typeName);\n  }\n};\n\nconst addMeta = (def: ZodTypeDef, refs: Refs, jsonSchema: JsonSchema7Type): JsonSchema7Type => {\n  if (def.description) {\n    jsonSchema.description = def.description;\n\n    if (refs.markdownDescription) {\n      jsonSchema.markdownDescription = def.description;\n    }\n  }\n  return jsonSchema;\n};\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/any.ts",
    "content": "export type JsonSchema7AnyType = {};\n\nexport function parseAnyDef(): JsonSchema7AnyType {\n  return {};\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/array.ts",
    "content": "import { ZodArrayDef, ZodFirstPartyTypeKind } from 'zod/v3';\nimport { ErrorMessages, setResponseValueAndErrors } from '../errorMessages';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport type JsonSchema7ArrayType = {\n  type: 'array';\n  items?: JsonSchema7Type | undefined;\n  minItems?: number;\n  maxItems?: number;\n  errorMessages?: ErrorMessages<JsonSchema7ArrayType, 'items'>;\n};\n\nexport function parseArrayDef(def: ZodArrayDef, refs: Refs) {\n  const res: JsonSchema7ArrayType = {\n    type: 'array',\n  };\n  if (def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {\n    res.items = parseDef(def.type._def, {\n      ...refs,\n      currentPath: [...refs.currentPath, 'items'],\n    });\n  }\n\n  if (def.minLength) {\n    setResponseValueAndErrors(res, 'minItems', def.minLength.value, def.minLength.message, refs);\n  }\n  if (def.maxLength) {\n    setResponseValueAndErrors(res, 'maxItems', def.maxLength.value, def.maxLength.message, refs);\n  }\n  if (def.exactLength) {\n    setResponseValueAndErrors(res, 'minItems', def.exactLength.value, def.exactLength.message, refs);\n    setResponseValueAndErrors(res, 'maxItems', def.exactLength.value, def.exactLength.message, refs);\n  }\n  return res;\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/bigint.ts",
    "content": "import { ZodBigIntDef } from 'zod/v3';\nimport { Refs } from '../Refs';\nimport { ErrorMessages, setResponseValueAndErrors } from '../errorMessages';\n\nexport type JsonSchema7BigintType = {\n  type: 'integer';\n  format: 'int64';\n  minimum?: BigInt;\n  exclusiveMinimum?: BigInt;\n  maximum?: BigInt;\n  exclusiveMaximum?: BigInt;\n  multipleOf?: BigInt;\n  errorMessage?: ErrorMessages<JsonSchema7BigintType>;\n};\n\nexport function parseBigintDef(def: ZodBigIntDef, refs: Refs): JsonSchema7BigintType {\n  const res: JsonSchema7BigintType = {\n    type: 'integer',\n    format: 'int64',\n  };\n\n  if (!def.checks) return res;\n\n  for (const check of def.checks) {\n    switch (check.kind) {\n      case 'min':\n        if (refs.target === 'jsonSchema7') {\n          if (check.inclusive) {\n            setResponseValueAndErrors(res, 'minimum', check.value, check.message, refs);\n          } else {\n            setResponseValueAndErrors(res, 'exclusiveMinimum', check.value, check.message, refs);\n          }\n        } else {\n          if (!check.inclusive) {\n            res.exclusiveMinimum = true as any;\n          }\n          setResponseValueAndErrors(res, 'minimum', check.value, check.message, refs);\n        }\n        break;\n      case 'max':\n        if (refs.target === 'jsonSchema7') {\n          if (check.inclusive) {\n            setResponseValueAndErrors(res, 'maximum', check.value, check.message, refs);\n          } else {\n            setResponseValueAndErrors(res, 'exclusiveMaximum', check.value, check.message, refs);\n          }\n        } else {\n          if (!check.inclusive) {\n            res.exclusiveMaximum = true as any;\n          }\n          setResponseValueAndErrors(res, 'maximum', check.value, check.message, refs);\n        }\n        break;\n      case 'multipleOf':\n        setResponseValueAndErrors(res, 'multipleOf', check.value, check.message, refs);\n        break;\n    }\n  }\n  return res;\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/boolean.ts",
    "content": "export type JsonSchema7BooleanType = {\n  type: 'boolean';\n};\n\nexport function parseBooleanDef(): JsonSchema7BooleanType {\n  return {\n    type: 'boolean',\n  };\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/branded.ts",
    "content": "import { ZodBrandedDef } from 'zod/v3';\nimport { parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport function parseBrandedDef(_def: ZodBrandedDef<any>, refs: Refs) {\n  return parseDef(_def.type._def, refs);\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/catch.ts",
    "content": "import { ZodCatchDef } from 'zod/v3';\nimport { parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport const parseCatchDef = (def: ZodCatchDef<any>, refs: Refs) => {\n  return parseDef(def.innerType._def, refs);\n};\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/date.ts",
    "content": "import { ZodDateDef } from 'zod/v3';\nimport { Refs } from '../Refs';\nimport { ErrorMessages, setResponseValueAndErrors } from '../errorMessages';\nimport { JsonSchema7NumberType } from './number';\nimport { DateStrategy } from '../Options';\n\nexport type JsonSchema7DateType =\n  | {\n      type: 'integer' | 'string';\n      format: 'unix-time' | 'date-time' | 'date';\n      minimum?: number;\n      maximum?: number;\n      errorMessage?: ErrorMessages<JsonSchema7NumberType>;\n    }\n  | {\n      anyOf: JsonSchema7DateType[];\n    };\n\nexport function parseDateDef(\n  def: ZodDateDef,\n  refs: Refs,\n  overrideDateStrategy?: DateStrategy,\n): JsonSchema7DateType {\n  const strategy = overrideDateStrategy ?? refs.dateStrategy;\n\n  if (Array.isArray(strategy)) {\n    return {\n      anyOf: strategy.map((item, i) => parseDateDef(def, refs, item)),\n    };\n  }\n\n  switch (strategy) {\n    case 'string':\n    case 'format:date-time':\n      return {\n        type: 'string',\n        format: 'date-time',\n      };\n    case 'format:date':\n      return {\n        type: 'string',\n        format: 'date',\n      };\n    case 'integer':\n      return integerDateParser(def, refs);\n  }\n}\n\nconst integerDateParser = (def: ZodDateDef, refs: Refs) => {\n  const res: JsonSchema7DateType = {\n    type: 'integer',\n    format: 'unix-time',\n  };\n\n  if (refs.target === 'openApi3') {\n    return res;\n  }\n\n  for (const check of def.checks) {\n    switch (check.kind) {\n      case 'min':\n        setResponseValueAndErrors(\n          res,\n          'minimum',\n          check.value, // This is in milliseconds\n          check.message,\n          refs,\n        );\n        break;\n      case 'max':\n        setResponseValueAndErrors(\n          res,\n          'maximum',\n          check.value, // This is in milliseconds\n          check.message,\n          refs,\n        );\n        break;\n    }\n  }\n\n  return res;\n};\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/default.ts",
    "content": "import { ZodDefaultDef } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport function parseDefaultDef(_def: ZodDefaultDef, refs: Refs): JsonSchema7Type & { default: any } {\n  return {\n    ...parseDef(_def.innerType._def, refs),\n    default: _def.defaultValue(),\n  };\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/effects.ts",
    "content": "import { ZodEffectsDef } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport function parseEffectsDef(\n  _def: ZodEffectsDef,\n  refs: Refs,\n  forceResolution: boolean,\n): JsonSchema7Type | undefined {\n  return refs.effectStrategy === 'input' ? parseDef(_def.schema._def, refs, forceResolution) : {};\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/enum.ts",
    "content": "import { ZodEnumDef } from 'zod/v3';\n\nexport type JsonSchema7EnumType = {\n  type: 'string';\n  enum: string[];\n};\n\nexport function parseEnumDef(def: ZodEnumDef): JsonSchema7EnumType {\n  return {\n    type: 'string',\n    enum: [...def.values],\n  };\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/intersection.ts",
    "content": "import { ZodIntersectionDef } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\nimport { JsonSchema7StringType } from './string';\n\nexport type JsonSchema7AllOfType = {\n  allOf: JsonSchema7Type[];\n  unevaluatedProperties?: boolean;\n};\n\nconst isJsonSchema7AllOfType = (\n  type: JsonSchema7Type | JsonSchema7StringType,\n): type is JsonSchema7AllOfType => {\n  if ('type' in type && type.type === 'string') return false;\n  return 'allOf' in type;\n};\n\nexport function parseIntersectionDef(\n  def: ZodIntersectionDef,\n  refs: Refs,\n): JsonSchema7AllOfType | JsonSchema7Type | undefined {\n  const allOf = [\n    parseDef(def.left._def, {\n      ...refs,\n      currentPath: [...refs.currentPath, 'allOf', '0'],\n    }),\n    parseDef(def.right._def, {\n      ...refs,\n      currentPath: [...refs.currentPath, 'allOf', '1'],\n    }),\n  ].filter((x): x is JsonSchema7Type => !!x);\n\n  let unevaluatedProperties: Pick<JsonSchema7AllOfType, 'unevaluatedProperties'> | undefined =\n    refs.target === 'jsonSchema2019-09' ? { unevaluatedProperties: false } : undefined;\n\n  const mergedAllOf: JsonSchema7Type[] = [];\n  // If either of the schemas is an allOf, merge them into a single allOf\n  allOf.forEach((schema) => {\n    if (isJsonSchema7AllOfType(schema)) {\n      mergedAllOf.push(...schema.allOf);\n      if (schema.unevaluatedProperties === undefined) {\n        // If one of the schemas has no unevaluatedProperties set,\n        // the merged schema should also have no unevaluatedProperties set\n        unevaluatedProperties = undefined;\n      }\n    } else {\n      let nestedSchema: JsonSchema7Type = schema;\n      if ('additionalProperties' in schema && schema.additionalProperties === false) {\n        const { additionalProperties, ...rest } = schema;\n        nestedSchema = rest;\n      } else {\n        // As soon as one of the schemas has additionalProperties set not to false, we allow unevaluatedProperties\n        unevaluatedProperties = undefined;\n      }\n      mergedAllOf.push(nestedSchema);\n    }\n  });\n  return mergedAllOf.length ?\n      {\n        allOf: mergedAllOf,\n        ...unevaluatedProperties,\n      }\n    : undefined;\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/literal.ts",
    "content": "import { ZodLiteralDef } from 'zod/v3';\nimport { Refs } from '../Refs';\n\nexport type JsonSchema7LiteralType =\n  | {\n      type: 'string' | 'number' | 'integer' | 'boolean';\n      const: string | number | boolean;\n    }\n  | {\n      type: 'object' | 'array';\n    };\n\nexport function parseLiteralDef(def: ZodLiteralDef, refs: Refs): JsonSchema7LiteralType {\n  const parsedType = typeof def.value;\n  if (\n    parsedType !== 'bigint' &&\n    parsedType !== 'number' &&\n    parsedType !== 'boolean' &&\n    parsedType !== 'string'\n  ) {\n    return {\n      type: Array.isArray(def.value) ? 'array' : 'object',\n    };\n  }\n\n  if (refs.target === 'openApi3') {\n    return {\n      type: parsedType === 'bigint' ? 'integer' : parsedType,\n      enum: [def.value],\n    } as any;\n  }\n\n  return {\n    type: parsedType === 'bigint' ? 'integer' : parsedType,\n    const: def.value,\n  };\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/map.ts",
    "content": "import { ZodMapDef } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\nimport { JsonSchema7RecordType, parseRecordDef } from './record';\n\nexport type JsonSchema7MapType = {\n  type: 'array';\n  maxItems: 125;\n  items: {\n    type: 'array';\n    items: [JsonSchema7Type, JsonSchema7Type];\n    minItems: 2;\n    maxItems: 2;\n  };\n};\n\nexport function parseMapDef(def: ZodMapDef, refs: Refs): JsonSchema7MapType | JsonSchema7RecordType {\n  if (refs.mapStrategy === 'record') {\n    return parseRecordDef(def, refs);\n  }\n\n  const keys =\n    parseDef(def.keyType._def, {\n      ...refs,\n      currentPath: [...refs.currentPath, 'items', 'items', '0'],\n    }) || {};\n  const values =\n    parseDef(def.valueType._def, {\n      ...refs,\n      currentPath: [...refs.currentPath, 'items', 'items', '1'],\n    }) || {};\n  return {\n    type: 'array',\n    maxItems: 125,\n    items: {\n      type: 'array',\n      items: [keys, values],\n      minItems: 2,\n      maxItems: 2,\n    },\n  };\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/nativeEnum.ts",
    "content": "import { ZodNativeEnumDef } from 'zod/v3';\n\nexport type JsonSchema7NativeEnumType = {\n  type: 'string' | 'number' | ['string', 'number'];\n  enum: (string | number)[];\n};\n\nexport function parseNativeEnumDef(def: ZodNativeEnumDef): JsonSchema7NativeEnumType {\n  const object = def.values;\n  const actualKeys = Object.keys(def.values).filter((key: string) => {\n    return typeof object[object[key]!] !== 'number';\n  });\n\n  const actualValues = actualKeys.map((key: string) => object[key]!);\n\n  const parsedTypes = Array.from(new Set(actualValues.map((values: string | number) => typeof values)));\n\n  return {\n    type:\n      parsedTypes.length === 1 ?\n        parsedTypes[0] === 'string' ?\n          'string'\n        : 'number'\n      : ['string', 'number'],\n    enum: actualValues,\n  };\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/never.ts",
    "content": "export type JsonSchema7NeverType = {\n  not: {};\n};\n\nexport function parseNeverDef(): JsonSchema7NeverType {\n  return {\n    not: {},\n  };\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/null.ts",
    "content": "import { Refs } from '../Refs';\n\nexport type JsonSchema7NullType = {\n  type: 'null';\n};\n\nexport function parseNullDef(refs: Refs): JsonSchema7NullType {\n  return refs.target === 'openApi3' ?\n      ({\n        enum: ['null'],\n        nullable: true,\n      } as any)\n    : {\n        type: 'null',\n      };\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/nullable.ts",
    "content": "import { ZodNullableDef } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\nimport { JsonSchema7NullType } from './null';\nimport { primitiveMappings } from './union';\n\nexport type JsonSchema7NullableType =\n  | {\n      anyOf: [JsonSchema7Type, JsonSchema7NullType];\n    }\n  | {\n      type: [string, 'null'];\n    };\n\nexport function parseNullableDef(def: ZodNullableDef, refs: Refs): JsonSchema7NullableType | undefined {\n  if (\n    ['ZodString', 'ZodNumber', 'ZodBigInt', 'ZodBoolean', 'ZodNull'].includes(def.innerType._def.typeName) &&\n    (!def.innerType._def.checks || !def.innerType._def.checks.length)\n  ) {\n    if (refs.target === 'openApi3' || refs.nullableStrategy === 'property') {\n      return {\n        type: primitiveMappings[def.innerType._def.typeName as keyof typeof primitiveMappings],\n        nullable: true,\n      } as any;\n    }\n\n    return {\n      type: [primitiveMappings[def.innerType._def.typeName as keyof typeof primitiveMappings], 'null'],\n    };\n  }\n\n  if (refs.target === 'openApi3') {\n    const base = parseDef(def.innerType._def, {\n      ...refs,\n      currentPath: [...refs.currentPath],\n    });\n\n    if (base && '$ref' in base) return { allOf: [base], nullable: true } as any;\n\n    return base && ({ ...base, nullable: true } as any);\n  }\n\n  const base = parseDef(def.innerType._def, {\n    ...refs,\n    currentPath: [...refs.currentPath, 'anyOf', '0'],\n  });\n\n  return base && { anyOf: [base, { type: 'null' }] };\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/number.ts",
    "content": "import { ZodNumberDef } from 'zod/v3';\nimport { addErrorMessage, ErrorMessages, setResponseValueAndErrors } from '../errorMessages';\nimport { Refs } from '../Refs';\n\nexport type JsonSchema7NumberType = {\n  type: 'number' | 'integer';\n  minimum?: number;\n  exclusiveMinimum?: number;\n  maximum?: number;\n  exclusiveMaximum?: number;\n  multipleOf?: number;\n  errorMessage?: ErrorMessages<JsonSchema7NumberType>;\n};\n\nexport function parseNumberDef(def: ZodNumberDef, refs: Refs): JsonSchema7NumberType {\n  const res: JsonSchema7NumberType = {\n    type: 'number',\n  };\n\n  if (!def.checks) return res;\n\n  for (const check of def.checks) {\n    switch (check.kind) {\n      case 'int':\n        res.type = 'integer';\n        addErrorMessage(res, 'type', check.message, refs);\n        break;\n      case 'min':\n        if (refs.target === 'jsonSchema7') {\n          if (check.inclusive) {\n            setResponseValueAndErrors(res, 'minimum', check.value, check.message, refs);\n          } else {\n            setResponseValueAndErrors(res, 'exclusiveMinimum', check.value, check.message, refs);\n          }\n        } else {\n          if (!check.inclusive) {\n            res.exclusiveMinimum = true as any;\n          }\n          setResponseValueAndErrors(res, 'minimum', check.value, check.message, refs);\n        }\n        break;\n      case 'max':\n        if (refs.target === 'jsonSchema7') {\n          if (check.inclusive) {\n            setResponseValueAndErrors(res, 'maximum', check.value, check.message, refs);\n          } else {\n            setResponseValueAndErrors(res, 'exclusiveMaximum', check.value, check.message, refs);\n          }\n        } else {\n          if (!check.inclusive) {\n            res.exclusiveMaximum = true as any;\n          }\n          setResponseValueAndErrors(res, 'maximum', check.value, check.message, refs);\n        }\n        break;\n      case 'multipleOf':\n        setResponseValueAndErrors(res, 'multipleOf', check.value, check.message, refs);\n        break;\n    }\n  }\n  return res;\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/object.ts",
    "content": "import { ZodObjectDef } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nfunction decideAdditionalProperties(def: ZodObjectDef, refs: Refs) {\n  if (refs.removeAdditionalStrategy === 'strict') {\n    return def.catchall._def.typeName === 'ZodNever' ?\n        def.unknownKeys !== 'strict'\n      : parseDef(def.catchall._def, {\n          ...refs,\n          currentPath: [...refs.currentPath, 'additionalProperties'],\n        }) ?? true;\n  } else {\n    return def.catchall._def.typeName === 'ZodNever' ?\n        def.unknownKeys === 'passthrough'\n      : parseDef(def.catchall._def, {\n          ...refs,\n          currentPath: [...refs.currentPath, 'additionalProperties'],\n        }) ?? true;\n  }\n}\n\nexport type JsonSchema7ObjectType = {\n  type: 'object';\n  properties: Record<string, JsonSchema7Type>;\n  additionalProperties: boolean | JsonSchema7Type;\n  required?: string[];\n};\n\nexport function parseObjectDef(def: ZodObjectDef, refs: Refs) {\n  const result: JsonSchema7ObjectType = {\n    type: 'object',\n    ...Object.entries(def.shape()).reduce(\n      (\n        acc: {\n          properties: Record<string, JsonSchema7Type>;\n          required: string[];\n        },\n        [propName, propDef],\n      ) => {\n        if (propDef === undefined || propDef._def === undefined) return acc;\n        const propertyPath = [...refs.currentPath, 'properties', propName];\n        const parsedDef = parseDef(propDef._def, {\n          ...refs,\n          currentPath: propertyPath,\n          propertyPath,\n        });\n        if (parsedDef === undefined) return acc;\n        if (\n          refs.openaiStrictMode &&\n          propDef.isOptional() &&\n          !propDef.isNullable() &&\n          typeof propDef._def?.defaultValue === 'undefined'\n        ) {\n          throw new Error(\n            `Zod field at \\`${propertyPath.join(\n              '/',\n            )}\\` uses \\`.optional()\\` without \\`.nullable()\\` which is not supported by the API. See: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required`,\n          );\n        }\n        return {\n          properties: {\n            ...acc.properties,\n            [propName]: parsedDef,\n          },\n          required:\n            propDef.isOptional() && !refs.openaiStrictMode ? acc.required : [...acc.required, propName],\n        };\n      },\n      { properties: {}, required: [] },\n    ),\n    additionalProperties: decideAdditionalProperties(def, refs),\n  };\n  if (!result.required!.length) delete result.required;\n  return result;\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/optional.ts",
    "content": "import { ZodOptionalDef } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport const parseOptionalDef = (def: ZodOptionalDef, refs: Refs): JsonSchema7Type | undefined => {\n  if (\n    refs.propertyPath &&\n    refs.currentPath.slice(0, refs.propertyPath.length).toString() === refs.propertyPath.toString()\n  ) {\n    return parseDef(def.innerType._def, { ...refs, currentPath: refs.currentPath });\n  }\n\n  const innerSchema = parseDef(def.innerType._def, {\n    ...refs,\n    currentPath: [...refs.currentPath, 'anyOf', '1'],\n  });\n\n  return innerSchema ?\n      {\n        anyOf: [\n          {\n            not: {},\n          },\n          innerSchema,\n        ],\n      }\n    : {};\n};\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/pipeline.ts",
    "content": "import { ZodPipelineDef } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\nimport { JsonSchema7AllOfType } from './intersection';\n\nexport const parsePipelineDef = (\n  def: ZodPipelineDef<any, any>,\n  refs: Refs,\n): JsonSchema7AllOfType | JsonSchema7Type | undefined => {\n  if (refs.pipeStrategy === 'input') {\n    return parseDef(def.in._def, refs);\n  } else if (refs.pipeStrategy === 'output') {\n    return parseDef(def.out._def, refs);\n  }\n\n  const a = parseDef(def.in._def, {\n    ...refs,\n    currentPath: [...refs.currentPath, 'allOf', '0'],\n  });\n  const b = parseDef(def.out._def, {\n    ...refs,\n    currentPath: [...refs.currentPath, 'allOf', a ? '1' : '0'],\n  });\n\n  return {\n    allOf: [a, b].filter((x): x is JsonSchema7Type => x !== undefined),\n  };\n};\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/promise.ts",
    "content": "import { ZodPromiseDef } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport function parsePromiseDef(def: ZodPromiseDef, refs: Refs): JsonSchema7Type | undefined {\n  return parseDef(def.type._def, refs);\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/readonly.ts",
    "content": "import { ZodReadonlyDef } from 'zod/v3';\nimport { parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport const parseReadonlyDef = (def: ZodReadonlyDef<any>, refs: Refs) => {\n  return parseDef(def.innerType._def, refs);\n};\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/record.ts",
    "content": "import { ZodFirstPartyTypeKind, ZodMapDef, ZodRecordDef, ZodTypeAny } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\nimport { JsonSchema7EnumType } from './enum';\nimport { JsonSchema7ObjectType } from './object';\nimport { JsonSchema7StringType, parseStringDef } from './string';\n\ntype JsonSchema7RecordPropertyNamesType =\n  | Omit<JsonSchema7StringType, 'type'>\n  | Omit<JsonSchema7EnumType, 'type'>;\n\nexport type JsonSchema7RecordType = {\n  type: 'object';\n  additionalProperties: JsonSchema7Type;\n  propertyNames?: JsonSchema7RecordPropertyNamesType;\n};\n\nexport function parseRecordDef(\n  def: ZodRecordDef<ZodTypeAny, ZodTypeAny> | ZodMapDef,\n  refs: Refs,\n): JsonSchema7RecordType {\n  if (refs.target === 'openApi3' && def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {\n    return {\n      type: 'object',\n      required: def.keyType._def.values,\n      properties: def.keyType._def.values.reduce(\n        (acc: Record<string, JsonSchema7Type>, key: string) => ({\n          ...acc,\n          [key]:\n            parseDef(def.valueType._def, {\n              ...refs,\n              currentPath: [...refs.currentPath, 'properties', key],\n            }) ?? {},\n        }),\n        {},\n      ),\n      additionalProperties: false,\n    } satisfies JsonSchema7ObjectType as any;\n  }\n\n  const schema: JsonSchema7RecordType = {\n    type: 'object',\n    additionalProperties:\n      parseDef(def.valueType._def, {\n        ...refs,\n        currentPath: [...refs.currentPath, 'additionalProperties'],\n      }) ?? {},\n  };\n\n  if (refs.target === 'openApi3') {\n    return schema;\n  }\n\n  if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {\n    const keyType: JsonSchema7RecordPropertyNamesType = Object.entries(\n      parseStringDef(def.keyType._def, refs),\n    ).reduce((acc, [key, value]) => (key === 'type' ? acc : { ...acc, [key]: value }), {});\n\n    return {\n      ...schema,\n      propertyNames: keyType,\n    };\n  } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {\n    return {\n      ...schema,\n      propertyNames: {\n        enum: def.keyType._def.values,\n      },\n    };\n  }\n\n  return schema;\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/set.ts",
    "content": "import { ZodSetDef } from 'zod/v3';\nimport { ErrorMessages, setResponseValueAndErrors } from '../errorMessages';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport type JsonSchema7SetType = {\n  type: 'array';\n  uniqueItems: true;\n  items?: JsonSchema7Type | undefined;\n  minItems?: number;\n  maxItems?: number;\n  errorMessage?: ErrorMessages<JsonSchema7SetType>;\n};\n\nexport function parseSetDef(def: ZodSetDef, refs: Refs): JsonSchema7SetType {\n  const items = parseDef(def.valueType._def, {\n    ...refs,\n    currentPath: [...refs.currentPath, 'items'],\n  });\n\n  const schema: JsonSchema7SetType = {\n    type: 'array',\n    uniqueItems: true,\n    items,\n  };\n\n  if (def.minSize) {\n    setResponseValueAndErrors(schema, 'minItems', def.minSize.value, def.minSize.message, refs);\n  }\n\n  if (def.maxSize) {\n    setResponseValueAndErrors(schema, 'maxItems', def.maxSize.value, def.maxSize.message, refs);\n  }\n\n  return schema;\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/string.ts",
    "content": "// @ts-nocheck\nimport { ZodStringDef } from 'zod/v3';\nimport { ErrorMessages, setResponseValueAndErrors } from '../errorMessages';\nimport { Refs } from '../Refs';\n\nlet emojiRegex: RegExp | undefined;\n\n/**\n * Generated from the regular expressions found here as of 2024-05-22:\n * https://github.com/colinhacks/zod/blob/master/src/types.ts.\n *\n * Expressions with /i flag have been changed accordingly.\n */\nexport const zodPatterns = {\n  /**\n   * `c` was changed to `[cC]` to replicate /i flag\n   */\n  cuid: /^[cC][^\\s-]{8,}$/,\n  cuid2: /^[0-9a-z]+$/,\n  ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,\n  /**\n   * `a-z` was added to replicate /i flag\n   */\n  email: /^(?!\\.)(?!.*\\.\\.)([a-zA-Z0-9_'+\\-\\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\\-]*\\.)+[a-zA-Z]{2,}$/,\n  /**\n   * Constructed a valid Unicode RegExp\n   *\n   * Lazily instantiate since this type of regex isn't supported\n   * in all envs (e.g. React Native).\n   *\n   * See:\n   * https://github.com/colinhacks/zod/issues/2433\n   * Fix in Zod:\n   * https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b\n   */\n  emoji: () => {\n    if (emojiRegex === undefined) {\n      emojiRegex = RegExp('^(\\\\p{Extended_Pictographic}|\\\\p{Emoji_Component})+$', 'u');\n    }\n    return emojiRegex;\n  },\n  /**\n   * Unused\n   */\n  uuid: /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/,\n  /**\n   * Unused\n   */\n  ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,\n  /**\n   * Unused\n   */\n  ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,\n  base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,\n  nanoid: /^[a-zA-Z0-9_-]{21}$/,\n} as const;\n\nexport type JsonSchema7StringType = {\n  type: 'string';\n  minLength?: number;\n  maxLength?: number;\n  format?:\n    | 'email'\n    | 'idn-email'\n    | 'uri'\n    | 'uuid'\n    | 'date-time'\n    | 'ipv4'\n    | 'ipv6'\n    | 'date'\n    | 'time'\n    | 'duration';\n  pattern?: string;\n  allOf?: {\n    pattern: string;\n    errorMessage?: ErrorMessages<{ pattern: string }>;\n  }[];\n  anyOf?: {\n    format: string;\n    errorMessage?: ErrorMessages<{ format: string }>;\n  }[];\n  errorMessage?: ErrorMessages<JsonSchema7StringType>;\n  contentEncoding?: string;\n};\n\nexport function parseStringDef(def: ZodStringDef, refs: Refs): JsonSchema7StringType {\n  const res: JsonSchema7StringType = {\n    type: 'string',\n  };\n\n  function processPattern(value: string): string {\n    return refs.patternStrategy === 'escape' ? escapeNonAlphaNumeric(value) : value;\n  }\n\n  if (def.checks) {\n    for (const check of def.checks) {\n      switch (check.kind) {\n        case 'min':\n          setResponseValueAndErrors(\n            res,\n            'minLength',\n            typeof res.minLength === 'number' ? Math.max(res.minLength, check.value) : check.value,\n            check.message,\n            refs,\n          );\n          break;\n        case 'max':\n          setResponseValueAndErrors(\n            res,\n            'maxLength',\n            typeof res.maxLength === 'number' ? Math.min(res.maxLength, check.value) : check.value,\n            check.message,\n            refs,\n          );\n\n          break;\n        case 'email':\n          switch (refs.emailStrategy) {\n            case 'format:email':\n              addFormat(res, 'email', check.message, refs);\n              break;\n            case 'format:idn-email':\n              addFormat(res, 'idn-email', check.message, refs);\n              break;\n            case 'pattern:zod':\n              addPattern(res, zodPatterns.email, check.message, refs);\n              break;\n          }\n\n          break;\n        case 'url':\n          addFormat(res, 'uri', check.message, refs);\n          break;\n        case 'uuid':\n          addFormat(res, 'uuid', check.message, refs);\n          break;\n        case 'regex':\n          addPattern(res, check.regex, check.message, refs);\n          break;\n        case 'cuid':\n          addPattern(res, zodPatterns.cuid, check.message, refs);\n          break;\n        case 'cuid2':\n          addPattern(res, zodPatterns.cuid2, check.message, refs);\n          break;\n        case 'startsWith':\n          addPattern(res, RegExp(`^${processPattern(check.value)}`), check.message, refs);\n          break;\n        case 'endsWith':\n          addPattern(res, RegExp(`${processPattern(check.value)}$`), check.message, refs);\n          break;\n\n        case 'datetime':\n          addFormat(res, 'date-time', check.message, refs);\n          break;\n        case 'date':\n          addFormat(res, 'date', check.message, refs);\n          break;\n        case 'time':\n          addFormat(res, 'time', check.message, refs);\n          break;\n        case 'duration':\n          addFormat(res, 'duration', check.message, refs);\n          break;\n        case 'length':\n          setResponseValueAndErrors(\n            res,\n            'minLength',\n            typeof res.minLength === 'number' ? Math.max(res.minLength, check.value) : check.value,\n            check.message,\n            refs,\n          );\n          setResponseValueAndErrors(\n            res,\n            'maxLength',\n            typeof res.maxLength === 'number' ? Math.min(res.maxLength, check.value) : check.value,\n            check.message,\n            refs,\n          );\n          break;\n        case 'includes': {\n          addPattern(res, RegExp(processPattern(check.value)), check.message, refs);\n          break;\n        }\n        case 'ip': {\n          if (check.version !== 'v6') {\n            addFormat(res, 'ipv4', check.message, refs);\n          }\n          if (check.version !== 'v4') {\n            addFormat(res, 'ipv6', check.message, refs);\n          }\n          break;\n        }\n        case 'emoji':\n          addPattern(res, zodPatterns.emoji, check.message, refs);\n          break;\n        case 'ulid': {\n          addPattern(res, zodPatterns.ulid, check.message, refs);\n          break;\n        }\n        case 'base64': {\n          switch (refs.base64Strategy) {\n            case 'format:binary': {\n              addFormat(res, 'binary' as any, check.message, refs);\n              break;\n            }\n\n            case 'contentEncoding:base64': {\n              setResponseValueAndErrors(res, 'contentEncoding', 'base64', check.message, refs);\n              break;\n            }\n\n            case 'pattern:zod': {\n              addPattern(res, zodPatterns.base64, check.message, refs);\n              break;\n            }\n          }\n          break;\n        }\n        case 'nanoid': {\n          addPattern(res, zodPatterns.nanoid, check.message, refs);\n        }\n        case 'toLowerCase':\n        case 'toUpperCase':\n        case 'trim':\n          break;\n        default:\n          ((_: never) => {})(check);\n      }\n    }\n  }\n\n  return res;\n}\n\nconst escapeNonAlphaNumeric = (value: string) =>\n  Array.from(value)\n    .map((c) => (/[a-zA-Z0-9]/.test(c) ? c : `\\\\${c}`))\n    .join('');\n\nconst addFormat = (\n  schema: JsonSchema7StringType,\n  value: Required<JsonSchema7StringType>['format'],\n  message: string | undefined,\n  refs: Refs,\n) => {\n  if (schema.format || schema.anyOf?.some((x) => x.format)) {\n    if (!schema.anyOf) {\n      schema.anyOf = [];\n    }\n\n    if (schema.format) {\n      schema.anyOf!.push({\n        format: schema.format,\n        ...(schema.errorMessage &&\n          refs.errorMessages && {\n            errorMessage: { format: schema.errorMessage.format },\n          }),\n      });\n      delete schema.format;\n      if (schema.errorMessage) {\n        delete schema.errorMessage.format;\n        if (Object.keys(schema.errorMessage).length === 0) {\n          delete schema.errorMessage;\n        }\n      }\n    }\n\n    schema.anyOf!.push({\n      format: value,\n      ...(message && refs.errorMessages && { errorMessage: { format: message } }),\n    });\n  } else {\n    setResponseValueAndErrors(schema, 'format', value, message, refs);\n  }\n};\n\nconst addPattern = (\n  schema: JsonSchema7StringType,\n  regex: RegExp | (() => RegExp),\n  message: string | undefined,\n  refs: Refs,\n) => {\n  if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {\n    if (!schema.allOf) {\n      schema.allOf = [];\n    }\n\n    if (schema.pattern) {\n      schema.allOf!.push({\n        pattern: schema.pattern,\n        ...(schema.errorMessage &&\n          refs.errorMessages && {\n            errorMessage: { pattern: schema.errorMessage.pattern },\n          }),\n      });\n      delete schema.pattern;\n      if (schema.errorMessage) {\n        delete schema.errorMessage.pattern;\n        if (Object.keys(schema.errorMessage).length === 0) {\n          delete schema.errorMessage;\n        }\n      }\n    }\n\n    schema.allOf!.push({\n      pattern: processRegExp(regex, refs),\n      ...(message && refs.errorMessages && { errorMessage: { pattern: message } }),\n    });\n  } else {\n    setResponseValueAndErrors(schema, 'pattern', processRegExp(regex, refs), message, refs);\n  }\n};\n\n// Mutate z.string.regex() in a best attempt to accommodate for regex flags when applyRegexFlags is true\nconst processRegExp = (regexOrFunction: RegExp | (() => RegExp), refs: Refs): string => {\n  const regex = typeof regexOrFunction === 'function' ? regexOrFunction() : regexOrFunction;\n  if (!refs.applyRegexFlags || !regex.flags) return regex.source;\n\n  // Currently handled flags\n  const flags = {\n    i: regex.flags.includes('i'), // Case-insensitive\n    m: regex.flags.includes('m'), // `^` and `$` matches adjacent to newline characters\n    s: regex.flags.includes('s'), // `.` matches newlines\n  };\n\n  // The general principle here is to step through each character, one at a time, applying mutations as flags require. We keep track when the current character is escaped, and when it's inside a group /like [this]/ or (also) a range like /[a-z]/. The following is fairly brittle imperative code; edit at your peril!\n\n  const source = flags.i ? regex.source.toLowerCase() : regex.source;\n  let pattern = '';\n  let isEscaped = false;\n  let inCharGroup = false;\n  let inCharRange = false;\n\n  for (let i = 0; i < source.length; i++) {\n    if (isEscaped) {\n      pattern += source[i];\n      isEscaped = false;\n      continue;\n    }\n\n    if (flags.i) {\n      if (inCharGroup) {\n        if (source[i].match(/[a-z]/)) {\n          if (inCharRange) {\n            pattern += source[i];\n            pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();\n            inCharRange = false;\n          } else if (source[i + 1] === '-' && source[i + 2]?.match(/[a-z]/)) {\n            pattern += source[i];\n            inCharRange = true;\n          } else {\n            pattern += `${source[i]}${source[i].toUpperCase()}`;\n          }\n          continue;\n        }\n      } else if (source[i].match(/[a-z]/)) {\n        pattern += `[${source[i]}${source[i].toUpperCase()}]`;\n        continue;\n      }\n    }\n\n    if (flags.m) {\n      if (source[i] === '^') {\n        pattern += `(^|(?<=[\\r\\n]))`;\n        continue;\n      } else if (source[i] === '$') {\n        pattern += `($|(?=[\\r\\n]))`;\n        continue;\n      }\n    }\n\n    if (flags.s && source[i] === '.') {\n      pattern += inCharGroup ? `${source[i]}\\r\\n` : `[${source[i]}\\r\\n]`;\n      continue;\n    }\n\n    pattern += source[i];\n    if (source[i] === '\\\\') {\n      isEscaped = true;\n    } else if (inCharGroup && source[i] === ']') {\n      inCharGroup = false;\n    } else if (!inCharGroup && source[i] === '[') {\n      inCharGroup = true;\n    }\n  }\n\n  try {\n    const regexTest = new RegExp(pattern);\n  } catch {\n    console.warn(\n      `Could not convert regex pattern at ${refs.currentPath.join(\n        '/',\n      )} to a flag-independent form! Falling back to the flag-ignorant source`,\n    );\n    return regex.source;\n  }\n\n  return pattern;\n};\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/tuple.ts",
    "content": "import { ZodTupleDef, ZodTupleItems, ZodTypeAny } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport type JsonSchema7TupleType = {\n  type: 'array';\n  minItems: number;\n  items: JsonSchema7Type[];\n} & (\n  | {\n      maxItems: number;\n    }\n  | {\n      additionalItems?: JsonSchema7Type | undefined;\n    }\n);\n\nexport function parseTupleDef(\n  def: ZodTupleDef<ZodTupleItems | [], ZodTypeAny | null>,\n  refs: Refs,\n): JsonSchema7TupleType {\n  if (def.rest) {\n    return {\n      type: 'array',\n      minItems: def.items.length,\n      items: def.items\n        .map((x, i) =>\n          parseDef(x._def, {\n            ...refs,\n            currentPath: [...refs.currentPath, 'items', `${i}`],\n          }),\n        )\n        .reduce((acc: JsonSchema7Type[], x) => (x === undefined ? acc : [...acc, x]), []),\n      additionalItems: parseDef(def.rest._def, {\n        ...refs,\n        currentPath: [...refs.currentPath, 'additionalItems'],\n      }),\n    };\n  } else {\n    return {\n      type: 'array',\n      minItems: def.items.length,\n      maxItems: def.items.length,\n      items: def.items\n        .map((x, i) =>\n          parseDef(x._def, {\n            ...refs,\n            currentPath: [...refs.currentPath, 'items', `${i}`],\n          }),\n        )\n        .reduce((acc: JsonSchema7Type[], x) => (x === undefined ? acc : [...acc, x]), []),\n    };\n  }\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/undefined.ts",
    "content": "export type JsonSchema7UndefinedType = {\n  not: {};\n};\n\nexport function parseUndefinedDef(): JsonSchema7UndefinedType {\n  return {\n    not: {},\n  };\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/union.ts",
    "content": "import { ZodDiscriminatedUnionDef, ZodLiteralDef, ZodTypeAny, ZodUnionDef } from 'zod/v3';\nimport { JsonSchema7Type, parseDef } from '../parseDef';\nimport { Refs } from '../Refs';\n\nexport const primitiveMappings = {\n  ZodString: 'string',\n  ZodNumber: 'number',\n  ZodBigInt: 'integer',\n  ZodBoolean: 'boolean',\n  ZodNull: 'null',\n} as const;\ntype ZodPrimitive = keyof typeof primitiveMappings;\ntype JsonSchema7Primitive = (typeof primitiveMappings)[keyof typeof primitiveMappings];\n\nexport type JsonSchema7UnionType = JsonSchema7PrimitiveUnionType | JsonSchema7AnyOfType;\n\ntype JsonSchema7PrimitiveUnionType =\n  | {\n      type: JsonSchema7Primitive | JsonSchema7Primitive[];\n    }\n  | {\n      type: JsonSchema7Primitive | JsonSchema7Primitive[];\n      enum: (string | number | bigint | boolean | null)[];\n    };\n\ntype JsonSchema7AnyOfType = {\n  anyOf: JsonSchema7Type[];\n};\n\nexport function parseUnionDef(\n  def: ZodUnionDef | ZodDiscriminatedUnionDef<any, any>,\n  refs: Refs,\n): JsonSchema7PrimitiveUnionType | JsonSchema7AnyOfType | undefined {\n  if (refs.target === 'openApi3') return asAnyOf(def, refs);\n\n  const options: readonly ZodTypeAny[] =\n    def.options instanceof Map ? Array.from(def.options.values()) : def.options;\n\n  // This blocks tries to look ahead a bit to produce nicer looking schemas with type array instead of anyOf.\n  if (\n    options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))\n  ) {\n    // all types in union are primitive and lack checks, so might as well squash into {type: [...]}\n\n    const types = options.reduce((types: JsonSchema7Primitive[], x) => {\n      const type = primitiveMappings[x._def.typeName as ZodPrimitive]; //Can be safely casted due to row 43\n      return type && !types.includes(type) ? [...types, type] : types;\n    }, []);\n\n    return {\n      type: types.length > 1 ? types : types[0]!,\n    };\n  } else if (options.every((x) => x._def.typeName === 'ZodLiteral' && !x.description)) {\n    // all options literals\n\n    const types = options.reduce((acc: JsonSchema7Primitive[], x: { _def: ZodLiteralDef }) => {\n      const type = typeof x._def.value;\n      switch (type) {\n        case 'string':\n        case 'number':\n        case 'boolean':\n          return [...acc, type];\n        case 'bigint':\n          return [...acc, 'integer' as const];\n        case 'object':\n          if (x._def.value === null) return [...acc, 'null' as const];\n        case 'symbol':\n        case 'undefined':\n        case 'function':\n        default:\n          return acc;\n      }\n    }, []);\n\n    if (types.length === options.length) {\n      // all the literals are primitive, as far as null can be considered primitive\n\n      const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);\n      return {\n        type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0]!,\n        enum: options.reduce(\n          (acc, x) => {\n            return acc.includes(x._def.value) ? acc : [...acc, x._def.value];\n          },\n          [] as (string | number | bigint | boolean | null)[],\n        ),\n      };\n    }\n  } else if (options.every((x) => x._def.typeName === 'ZodEnum')) {\n    return {\n      type: 'string',\n      enum: options.reduce(\n        (acc: string[], x) => [...acc, ...x._def.values.filter((x: string) => !acc.includes(x))],\n        [],\n      ),\n    };\n  }\n\n  return asAnyOf(def, refs);\n}\n\nconst asAnyOf = (\n  def: ZodUnionDef | ZodDiscriminatedUnionDef<any, any>,\n  refs: Refs,\n): JsonSchema7PrimitiveUnionType | JsonSchema7AnyOfType | undefined => {\n  const anyOf = ((def.options instanceof Map ? Array.from(def.options.values()) : def.options) as any[])\n    .map((x, i) =>\n      parseDef(x._def, {\n        ...refs,\n        currentPath: [...refs.currentPath, 'anyOf', `${i}`],\n      }),\n    )\n    .filter(\n      (x): x is JsonSchema7Type =>\n        !!x && (!refs.strictUnions || (typeof x === 'object' && Object.keys(x).length > 0)),\n    );\n\n  return anyOf.length ? { anyOf } : undefined;\n};\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/parsers/unknown.ts",
    "content": "export type JsonSchema7UnknownType = {};\n\nexport function parseUnknownDef(): JsonSchema7UnknownType {\n  return {};\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/util.ts",
    "content": "import type { ZodSchema, ZodTypeDef } from 'zod/v3';\n\nexport const zodDef = (zodSchema: ZodSchema | ZodTypeDef): ZodTypeDef => {\n  return '_def' in zodSchema ? zodSchema._def : zodSchema;\n};\n\nexport function isEmptyObj(obj: Object | null | undefined): boolean {\n  if (!obj) return true;\n  for (const _k in obj) return false;\n  return true;\n}\n"
  },
  {
    "path": "src/_vendor/zod-to-json-schema/zodToJsonSchema.ts",
    "content": "import { ZodSchema } from 'zod/v3';\nimport { Options, Targets } from './Options';\nimport { JsonSchema7Type, parseDef } from './parseDef';\nimport { getRefs } from './Refs';\nimport { zodDef, isEmptyObj } from './util';\n\nconst zodToJsonSchema = <Target extends Targets = 'jsonSchema7'>(\n  schema: ZodSchema<any>,\n  options?: Partial<Options<Target>> | string,\n): (Target extends 'jsonSchema7' ? JsonSchema7Type : object) & {\n  $schema?: string;\n  definitions?: {\n    [key: string]: Target extends 'jsonSchema7' ? JsonSchema7Type\n    : Target extends 'jsonSchema2019-09' ? JsonSchema7Type\n    : object;\n  };\n} => {\n  const refs = getRefs(options);\n\n  const name =\n    typeof options === 'string' ? options\n    : options?.nameStrategy === 'title' ? undefined\n    : options?.name;\n\n  const main =\n    parseDef(\n      schema._def,\n      name === undefined ? refs : (\n        {\n          ...refs,\n          currentPath: [...refs.basePath, refs.definitionPath, name],\n        }\n      ),\n      false,\n    ) ?? {};\n\n  const title =\n    typeof options === 'object' && options.name !== undefined && options.nameStrategy === 'title' ?\n      options.name\n    : undefined;\n\n  if (title !== undefined) {\n    main.title = title;\n  }\n\n  const definitions = (() => {\n    if (isEmptyObj(refs.definitions)) {\n      return undefined;\n    }\n\n    const definitions: Record<string, any> = {};\n    const processedDefinitions = new Set();\n\n    // the call to `parseDef()` here might itself add more entries to `.definitions`\n    // so we need to continually evaluate definitions until we've resolved all of them\n    //\n    // we have a generous iteration limit here to avoid blowing up the stack if there\n    // are any bugs that would otherwise result in us iterating indefinitely\n    for (let i = 0; i < 500; i++) {\n      const newDefinitions = Object.entries(refs.definitions).filter(\n        ([key]) => !processedDefinitions.has(key),\n      );\n      if (newDefinitions.length === 0) break;\n\n      for (const [key, schema] of newDefinitions) {\n        definitions[key] =\n          parseDef(\n            zodDef(schema),\n            { ...refs, currentPath: [...refs.basePath, refs.definitionPath, key] },\n            true,\n          ) ?? {};\n        processedDefinitions.add(key);\n      }\n    }\n\n    return definitions;\n  })();\n\n  const combined: ReturnType<typeof zodToJsonSchema<Target>> =\n    name === undefined ?\n      definitions ?\n        {\n          ...main,\n          [refs.definitionPath]: definitions,\n        }\n      : main\n    : refs.nameStrategy === 'duplicate-ref' ?\n      {\n        ...main,\n        ...(definitions || refs.seenRefs.size ?\n          {\n            [refs.definitionPath]: {\n              ...definitions,\n              // only actually duplicate the schema definition if it was ever referenced\n              // otherwise the duplication is completely pointless\n              ...(refs.seenRefs.size ? { [name]: main } : undefined),\n            },\n          }\n        : undefined),\n      }\n    : {\n        $ref: [...(refs.$refStrategy === 'relative' ? [] : refs.basePath), refs.definitionPath, name].join(\n          '/',\n        ),\n        [refs.definitionPath]: {\n          ...definitions,\n          [name]: main,\n        },\n      };\n\n  if (refs.target === 'jsonSchema7') {\n    combined.$schema = 'http://json-schema.org/draft-07/schema#';\n  } else if (refs.target === 'jsonSchema2019-09') {\n    combined.$schema = 'https://json-schema.org/draft/2019-09/schema#';\n  }\n\n  return combined;\n};\n\nexport { zodToJsonSchema };\n"
  },
  {
    "path": "src/api-promise.ts",
    "content": "/** @deprecated Import from ./core/api-promise instead */\nexport * from './core/api-promise';\n"
  },
  {
    "path": "src/azure.ts",
    "content": "import type { RequestInit } from './internal/builtin-types';\nimport type { NullableHeaders } from './internal/headers';\nimport { buildHeaders } from './internal/headers';\nimport * as Errors from './error';\nimport { FinalRequestOptions } from './internal/request-options';\nimport { isObj, readEnv } from './internal/utils';\nimport { ClientOptions, OpenAI } from './client';\n\n/** API Client for interfacing with the Azure OpenAI API. */\nexport interface AzureClientOptions extends ClientOptions {\n  /**\n   * Defaults to process.env['OPENAI_API_VERSION'].\n   */\n  apiVersion?: string | undefined;\n\n  /**\n   * Your Azure endpoint, including the resource, e.g. `https://example-resource.azure.openai.com/`\n   */\n  endpoint?: string | undefined;\n\n  /**\n   * A model deployment, if given, sets the base client URL to include `/deployments/{deployment}`.\n   * Note: this means you won't be able to use non-deployment endpoints. Not supported with Assistants APIs.\n   */\n  deployment?: string | undefined;\n\n  /**\n   * Defaults to process.env['AZURE_OPENAI_API_KEY'].\n   */\n  apiKey?: string | undefined;\n\n  /**\n   * A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory),\n   * which will be invoked on every request.\n   */\n  azureADTokenProvider?: (() => Promise<string>) | undefined;\n}\n\n/** API Client for interfacing with the Azure OpenAI API. */\nexport class AzureOpenAI extends OpenAI {\n  deploymentName: string | undefined;\n  apiVersion: string = '';\n\n  /**\n   * API Client for interfacing with the Azure OpenAI API.\n   *\n   * @param {string | undefined} [opts.apiVersion=process.env['OPENAI_API_VERSION'] ?? undefined]\n   * @param {string | undefined} [opts.endpoint=process.env['AZURE_OPENAI_ENDPOINT'] ?? undefined] - Your Azure endpoint, including the resource, e.g. `https://example-resource.azure.openai.com/`\n   * @param {string | undefined} [opts.apiKey=process.env['AZURE_OPENAI_API_KEY'] ?? undefined]\n   * @param {string | undefined} opts.deployment - A model deployment, if given, sets the base client URL to include `/deployments/{deployment}`.\n   * @param {string | null | undefined} [opts.organization=process.env['OPENAI_ORG_ID'] ?? null]\n   * @param {string} [opts.baseURL=process.env['OPENAI_BASE_URL']] - Sets the base URL for the API, e.g. `https://example-resource.azure.openai.com/openai/`.\n   * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.\n   * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.\n   * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.\n   * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.\n   * @param {Headers} opts.defaultHeaders - Default headers to include with every request to the API.\n   * @param {DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.\n   * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.\n   */\n  constructor({\n    baseURL = readEnv('OPENAI_BASE_URL'),\n    apiKey = readEnv('AZURE_OPENAI_API_KEY'),\n    apiVersion = readEnv('OPENAI_API_VERSION'),\n    endpoint,\n    deployment,\n    azureADTokenProvider,\n    dangerouslyAllowBrowser,\n    ...opts\n  }: AzureClientOptions = {}) {\n    if (!apiVersion) {\n      throw new Errors.OpenAIError(\n        \"The OPENAI_API_VERSION environment variable is missing or empty; either provide it, or instantiate the AzureOpenAI client with an apiVersion option, like new AzureOpenAI({ apiVersion: 'My API Version' }).\",\n      );\n    }\n\n    if (typeof azureADTokenProvider === 'function') {\n      dangerouslyAllowBrowser = true;\n    }\n\n    if (!azureADTokenProvider && !apiKey) {\n      throw new Errors.OpenAIError(\n        'Missing credentials. Please pass one of `apiKey` and `azureADTokenProvider`, or set the `AZURE_OPENAI_API_KEY` environment variable.',\n      );\n    }\n\n    if (azureADTokenProvider && apiKey) {\n      throw new Errors.OpenAIError(\n        'The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.',\n      );\n    }\n\n    opts.defaultQuery = { ...opts.defaultQuery, 'api-version': apiVersion };\n\n    if (!baseURL) {\n      if (!endpoint) {\n        endpoint = process.env['AZURE_OPENAI_ENDPOINT'];\n      }\n\n      if (!endpoint) {\n        throw new Errors.OpenAIError(\n          'Must provide one of the `baseURL` or `endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable',\n        );\n      }\n\n      baseURL = `${endpoint}/openai`;\n    } else {\n      if (endpoint) {\n        throw new Errors.OpenAIError('baseURL and endpoint are mutually exclusive');\n      }\n    }\n\n    super({\n      apiKey: azureADTokenProvider ?? apiKey,\n      baseURL,\n      ...opts,\n      ...(dangerouslyAllowBrowser !== undefined ? { dangerouslyAllowBrowser } : {}),\n    });\n\n    this.apiVersion = apiVersion;\n    this.deploymentName = deployment;\n  }\n\n  override async buildRequest(\n    options: FinalRequestOptions,\n    props: { retryCount?: number } = {},\n  ): Promise<{ req: RequestInit & { headers: Headers }; url: string; timeout: number }> {\n    if (_deployments_endpoints.has(options.path) && options.method === 'post' && options.body !== undefined) {\n      if (!isObj(options.body)) {\n        throw new Error('Expected request body to be an object');\n      }\n      const model = this.deploymentName || options.body['model'] || options.__metadata?.['model'];\n      if (model !== undefined && !this.baseURL.includes('/deployments')) {\n        options.path = `/deployments/${model}${options.path}`;\n      }\n    }\n    return super.buildRequest(options, props);\n  }\n\n  protected override async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {\n    if (typeof this._options.apiKey === 'string') {\n      return buildHeaders([{ 'api-key': this.apiKey }]);\n    }\n    return super.authHeaders(opts);\n  }\n}\n\nconst _deployments_endpoints = new Set([\n  '/completions',\n  '/chat/completions',\n  '/embeddings',\n  '/audio/transcriptions',\n  '/audio/translations',\n  '/audio/speech',\n  '/images/generations',\n  '/batches',\n  '/images/edits',\n]);\n"
  },
  {
    "path": "src/beta/realtime/index.ts",
    "content": "export { OpenAIRealtimeError } from './internal-base';\n"
  },
  {
    "path": "src/beta/realtime/internal-base.ts",
    "content": "import { RealtimeClientEvent, RealtimeServerEvent, ErrorEvent } from '../../resources/beta/realtime/realtime';\nimport { EventEmitter } from '../../lib/EventEmitter';\nimport { OpenAIError } from '../../error';\nimport OpenAI, { AzureOpenAI } from '../../index';\n\nexport class OpenAIRealtimeError extends OpenAIError {\n  /**\n   * The error data that the API sent back in an `error` event.\n   */\n  error?: ErrorEvent.Error | undefined;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id?: string | undefined;\n\n  constructor(message: string, event: ErrorEvent | null) {\n    super(message);\n\n    this.error = event?.error;\n    this.event_id = event?.event_id;\n  }\n}\n\ntype Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};\n\ntype RealtimeEvents = Simplify<\n  {\n    event: (event: RealtimeServerEvent) => void;\n    error: (error: OpenAIRealtimeError) => void;\n  } & {\n    [EventType in Exclude<RealtimeServerEvent['type'], 'error'>]: (\n      event: Extract<RealtimeServerEvent, { type: EventType }>,\n    ) => unknown;\n  }\n>;\n\nexport abstract class OpenAIRealtimeEmitter extends EventEmitter<RealtimeEvents> {\n  /**\n   * Send an event to the API.\n   */\n  abstract send(event: RealtimeClientEvent): void;\n\n  /**\n   * Close the websocket connection.\n   */\n  abstract close(props?: { code: number; reason: string }): void;\n\n  protected _onError(event: null, message: string, cause: any): void;\n  protected _onError(event: ErrorEvent, message?: string | undefined): void;\n  protected _onError(event: ErrorEvent | null, message?: string | undefined, cause?: any): void {\n    message =\n      event?.error ?\n        `${event.error.message} code=${event.error.code} param=${event.error.param} type=${event.error.type} event_id=${event.error.event_id}`\n      : message ?? 'unknown error';\n\n    if (!this._hasListener('error')) {\n      const error = new OpenAIRealtimeError(\n        message +\n          `\\n\\nTo resolve these unhandled rejection errors you should bind an \\`error\\` callback, e.g. \\`rt.on('error', (error) => ...)\\` `,\n        event,\n      );\n      // @ts-ignore\n      error.cause = cause;\n      Promise.reject(error);\n      return;\n    }\n\n    const error = new OpenAIRealtimeError(message, event);\n    // @ts-ignore\n    error.cause = cause;\n\n    this._emit('error', error);\n  }\n}\n\nexport function isAzure(client: Pick<OpenAI, 'apiKey' | 'baseURL'>): client is AzureOpenAI {\n  return client instanceof AzureOpenAI;\n}\n\nexport function buildRealtimeURL(client: Pick<OpenAI, 'apiKey' | 'baseURL'>, model: string): URL {\n  const path = '/realtime';\n  const baseURL = client.baseURL;\n  const url = new URL(baseURL + (baseURL.endsWith('/') ? path.slice(1) : path));\n  url.protocol = 'wss';\n  if (isAzure(client)) {\n    url.searchParams.set('api-version', client.apiVersion);\n    url.searchParams.set('deployment', model);\n  } else {\n    url.searchParams.set('model', model);\n  }\n  return url;\n}\n"
  },
  {
    "path": "src/beta/realtime/websocket.ts",
    "content": "import { AzureOpenAI, OpenAI } from '../../index';\nimport { OpenAIError } from '../../error';\nimport type { RealtimeClientEvent, RealtimeServerEvent } from '../../resources/beta/realtime/realtime';\nimport { OpenAIRealtimeEmitter, buildRealtimeURL, isAzure } from './internal-base';\nimport { isRunningInBrowser } from '../../internal/detect-platform';\n\ninterface MessageEvent {\n  data: string;\n}\n\ntype _WebSocket =\n  typeof globalThis extends (\n    {\n      WebSocket: infer ws extends abstract new (...args: any) => any;\n    }\n  ) ?\n    // @ts-ignore\n    InstanceType<ws>\n  : any;\n\nexport class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {\n  url: URL;\n  socket: _WebSocket;\n\n  constructor(\n    props: {\n      model: string;\n      dangerouslyAllowBrowser?: boolean;\n      /**\n       * Callback to mutate the URL, needed for Azure.\n       * @internal\n       */\n      onURL?: (url: URL) => void;\n      /** Indicates the token was resolved by the factory just before connecting. @internal */\n      __resolvedApiKey?: boolean;\n    },\n    client?: Pick<OpenAI, 'apiKey' | 'baseURL'>,\n  ) {\n    super();\n    const hasProvider = typeof (client as any)?._options?.apiKey === 'function';\n    const dangerouslyAllowBrowser =\n      props.dangerouslyAllowBrowser ??\n      (client as any)?._options?.dangerouslyAllowBrowser ??\n      (client?.apiKey?.startsWith('ek_') ? true : null);\n    if (!dangerouslyAllowBrowser && isRunningInBrowser()) {\n      throw new OpenAIError(\n        \"It looks like you're running in a browser-like environment.\\n\\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\\n\\nYou can avoid this error by creating an ephemeral session token:\\nhttps://platform.openai.com/docs/api-reference/realtime-sessions\\n\",\n      );\n    }\n\n    client ??= new OpenAI({ dangerouslyAllowBrowser });\n\n    if (hasProvider && !props?.__resolvedApiKey) {\n      throw new Error(\n        [\n          'Cannot open Realtime WebSocket with a function-based apiKey.',\n          'Use the .create() method so that the key is resolved before connecting:',\n          'await OpenAIRealtimeWebSocket.create(client, { model })',\n        ].join('\\n'),\n      );\n    }\n\n    this.url = buildRealtimeURL(client, props.model);\n    props.onURL?.(this.url);\n\n    // @ts-ignore\n    this.socket = new WebSocket(this.url.toString(), [\n      'realtime',\n      ...(isAzure(client) ? [] : [`openai-insecure-api-key.${client.apiKey}`]),\n      'openai-beta.realtime-v1',\n    ]);\n\n    this.socket.addEventListener('message', (websocketEvent: MessageEvent) => {\n      const event = (() => {\n        try {\n          return JSON.parse(websocketEvent.data.toString()) as RealtimeServerEvent;\n        } catch (err) {\n          this._onError(null, 'could not parse websocket event', err);\n          return null;\n        }\n      })();\n\n      if (event) {\n        this._emit('event', event);\n\n        if (event.type === 'error') {\n          this._onError(event);\n        } else {\n          // @ts-expect-error TS isn't smart enough to get the relationship right here\n          this._emit(event.type, event);\n        }\n      }\n    });\n\n    this.socket.addEventListener('error', (event: any) => {\n      this._onError(null, event.message, null);\n    });\n\n    if (isAzure(client)) {\n      if (this.url.searchParams.get('Authorization') !== null) {\n        this.url.searchParams.set('Authorization', '<REDACTED>');\n      } else {\n        this.url.searchParams.set('api-key', '<REDACTED>');\n      }\n    }\n  }\n\n  static async create(\n    client: Pick<OpenAI, 'apiKey' | 'baseURL' | '_callApiKey'>,\n    props: { model: string; dangerouslyAllowBrowser?: boolean },\n  ): Promise<OpenAIRealtimeWebSocket> {\n    return new OpenAIRealtimeWebSocket({ ...props, __resolvedApiKey: await client._callApiKey() }, client);\n  }\n\n  static async azure(\n    client: Pick<AzureOpenAI, '_callApiKey' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,\n    options: { deploymentName?: string; dangerouslyAllowBrowser?: boolean } = {},\n  ): Promise<OpenAIRealtimeWebSocket> {\n    const isApiKeyProvider = await client._callApiKey();\n    function onURL(url: URL) {\n      if (isApiKeyProvider) {\n        url.searchParams.set('Authorization', `Bearer ${client.apiKey}`);\n      } else {\n        url.searchParams.set('api-key', client.apiKey);\n      }\n    }\n    const deploymentName = options.deploymentName ?? client.deploymentName;\n    if (!deploymentName) {\n      throw new Error('No deployment name provided');\n    }\n    const { dangerouslyAllowBrowser } = options;\n    return new OpenAIRealtimeWebSocket(\n      {\n        model: deploymentName,\n        onURL,\n        ...(dangerouslyAllowBrowser ? { dangerouslyAllowBrowser } : {}),\n        __resolvedApiKey: isApiKeyProvider,\n      },\n      client,\n    );\n  }\n\n  send(event: RealtimeClientEvent) {\n    try {\n      this.socket.send(JSON.stringify(event));\n    } catch (err) {\n      this._onError(null, 'could not send data', err);\n    }\n  }\n\n  close(props?: { code: number; reason: string }) {\n    try {\n      this.socket.close(props?.code ?? 1000, props?.reason ?? 'OK');\n    } catch (err) {\n      this._onError(null, 'could not close the connection', err);\n    }\n  }\n}\n"
  },
  {
    "path": "src/beta/realtime/ws.ts",
    "content": "import * as WS from 'ws';\nimport { AzureOpenAI, OpenAI } from '../../index';\nimport type { RealtimeClientEvent, RealtimeServerEvent } from '../../resources/beta/realtime/realtime';\nimport { OpenAIRealtimeEmitter, buildRealtimeURL, isAzure } from './internal-base';\n\nexport class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {\n  url: URL;\n  socket: WS.WebSocket;\n\n  constructor(\n    props: {\n      model: string;\n      options?: WS.ClientOptions | undefined;\n      /** @internal */ __resolvedApiKey?: boolean;\n    },\n    client?: Pick<OpenAI, 'apiKey' | 'baseURL'>,\n  ) {\n    super();\n    client ??= new OpenAI();\n    const hasProvider = typeof (client as any)?._options?.apiKey === 'function';\n    if (hasProvider && !props.__resolvedApiKey) {\n      throw new Error(\n        [\n          'Cannot open Realtime WebSocket with a function-based apiKey.',\n          'Use the .create() method so that the key is resolved before connecting:',\n          'await OpenAIRealtimeWS.create(client, { model })',\n        ].join('\\n'),\n      );\n    }\n    this.url = buildRealtimeURL(client, props.model);\n    this.socket = new WS.WebSocket(this.url, {\n      ...props.options,\n      headers: {\n        ...props.options?.headers,\n        ...(isAzure(client) && !props.__resolvedApiKey ? {} : { Authorization: `Bearer ${client.apiKey}` }),\n        'OpenAI-Beta': 'realtime=v1',\n      },\n    });\n\n    this.socket.on('message', (wsEvent) => {\n      const event = (() => {\n        try {\n          return JSON.parse(wsEvent.toString()) as RealtimeServerEvent;\n        } catch (err) {\n          this._onError(null, 'could not parse websocket event', err);\n          return null;\n        }\n      })();\n\n      if (event) {\n        this._emit('event', event);\n\n        if (event.type === 'error') {\n          this._onError(event);\n        } else {\n          // @ts-expect-error TS isn't smart enough to get the relationship right here\n          this._emit(event.type, event);\n        }\n      }\n    });\n\n    this.socket.on('error', (err) => {\n      this._onError(null, err.message, err);\n    });\n  }\n\n  static async create(\n    client: Pick<OpenAI, 'apiKey' | 'baseURL' | '_callApiKey'>,\n    props: { model: string; options?: WS.ClientOptions | undefined },\n  ): Promise<OpenAIRealtimeWS> {\n    return new OpenAIRealtimeWS({ ...props, __resolvedApiKey: await client._callApiKey() }, client);\n  }\n\n  static async azure(\n    client: Pick<AzureOpenAI, '_callApiKey' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,\n    props: { deploymentName?: string; options?: WS.ClientOptions | undefined } = {},\n  ): Promise<OpenAIRealtimeWS> {\n    const isApiKeyProvider = await client._callApiKey();\n    const deploymentName = props.deploymentName ?? client.deploymentName;\n    if (!deploymentName) {\n      throw new Error('No deployment name provided');\n    }\n    return new OpenAIRealtimeWS(\n      {\n        model: deploymentName,\n        options: {\n          ...props.options,\n          headers: {\n            ...props.options?.headers,\n            ...(isApiKeyProvider ? {} : { 'api-key': client.apiKey }),\n          },\n        },\n        __resolvedApiKey: isApiKeyProvider,\n      },\n      client,\n    );\n  }\n\n  send(event: RealtimeClientEvent) {\n    try {\n      this.socket.send(JSON.stringify(event));\n    } catch (err) {\n      this._onError(null, 'could not send data', err);\n    }\n  }\n\n  close(props?: { code: number; reason: string }) {\n    try {\n      this.socket.close(props?.code ?? 1000, props?.reason ?? 'OK');\n    } catch (err) {\n      this._onError(null, 'could not close the connection', err);\n    }\n  }\n}\n"
  },
  {
    "path": "src/client.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport type { RequestInit, RequestInfo, BodyInit } from './internal/builtin-types';\nimport type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from './internal/types';\nimport { uuid4 } from './internal/utils/uuid';\nimport { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values';\nimport { sleep } from './internal/utils/sleep';\nexport type { Logger, LogLevel } from './internal/utils/log';\nimport { castToError, isAbortError } from './internal/errors';\nimport type { APIResponseProps } from './internal/parse';\nimport { getPlatformHeaders } from './internal/detect-platform';\nimport * as Shims from './internal/shims';\nimport * as Opts from './internal/request-options';\nimport { stringifyQuery } from './internal/utils/query';\nimport { VERSION } from './version';\nimport * as Errors from './core/error';\nimport * as Pagination from './core/pagination';\nimport {\n  AbstractPage,\n  type ConversationCursorPageParams,\n  ConversationCursorPageResponse,\n  type CursorPageParams,\n  CursorPageResponse,\n  PageResponse,\n} from './core/pagination';\nimport * as Uploads from './core/uploads';\nimport * as API from './resources/index';\nimport { APIPromise } from './core/api-promise';\nimport {\n  Batch,\n  BatchCreateParams,\n  BatchError,\n  BatchListParams,\n  BatchRequestCounts,\n  BatchUsage,\n  Batches,\n  BatchesPage,\n} from './resources/batches';\nimport {\n  Completion,\n  CompletionChoice,\n  CompletionCreateParams,\n  CompletionCreateParamsNonStreaming,\n  CompletionCreateParamsStreaming,\n  CompletionUsage,\n  Completions,\n} from './resources/completions';\nimport {\n  CreateEmbeddingResponse,\n  Embedding,\n  EmbeddingCreateParams,\n  EmbeddingModel,\n  Embeddings,\n} from './resources/embeddings';\nimport {\n  FileContent,\n  FileCreateParams,\n  FileDeleted,\n  FileListParams,\n  FileObject,\n  FileObjectsPage,\n  FilePurpose,\n  Files,\n} from './resources/files';\nimport {\n  Image,\n  ImageCreateVariationParams,\n  ImageEditCompletedEvent,\n  ImageEditParams,\n  ImageEditParamsNonStreaming,\n  ImageEditParamsStreaming,\n  ImageEditPartialImageEvent,\n  ImageEditStreamEvent,\n  ImageGenCompletedEvent,\n  ImageGenPartialImageEvent,\n  ImageGenStreamEvent,\n  ImageGenerateParams,\n  ImageGenerateParamsNonStreaming,\n  ImageGenerateParamsStreaming,\n  ImageModel,\n  Images,\n  ImagesResponse,\n} from './resources/images';\nimport { Model, ModelDeleted, Models, ModelsPage } from './resources/models';\nimport {\n  Moderation,\n  ModerationCreateParams,\n  ModerationCreateResponse,\n  ModerationImageURLInput,\n  ModerationModel,\n  ModerationMultiModalInput,\n  ModerationTextInput,\n  Moderations,\n} from './resources/moderations';\nimport {\n  ImageInputReferenceParam,\n  Video,\n  VideoCreateCharacterParams,\n  VideoCreateCharacterResponse,\n  VideoCreateError,\n  VideoCreateParams,\n  VideoDeleteResponse,\n  VideoDownloadContentParams,\n  VideoEditParams,\n  VideoExtendParams,\n  VideoGetCharacterResponse,\n  VideoListParams,\n  VideoModel,\n  VideoRemixParams,\n  VideoSeconds,\n  VideoSize,\n  Videos,\n  VideosPage,\n} from './resources/videos';\nimport { Audio, AudioModel, AudioResponseFormat } from './resources/audio/audio';\nimport { Beta } from './resources/beta/beta';\nimport { Chat } from './resources/chat/chat';\nimport {\n  ContainerCreateParams,\n  ContainerCreateResponse,\n  ContainerListParams,\n  ContainerListResponse,\n  ContainerListResponsesPage,\n  ContainerRetrieveResponse,\n  Containers,\n} from './resources/containers/containers';\nimport { Conversations } from './resources/conversations/conversations';\nimport {\n  EvalCreateParams,\n  EvalCreateResponse,\n  EvalCustomDataSourceConfig,\n  EvalDeleteResponse,\n  EvalListParams,\n  EvalListResponse,\n  EvalListResponsesPage,\n  EvalRetrieveResponse,\n  EvalStoredCompletionsDataSourceConfig,\n  EvalUpdateParams,\n  EvalUpdateResponse,\n  Evals,\n} from './resources/evals/evals';\nimport { FineTuning } from './resources/fine-tuning/fine-tuning';\nimport { Graders } from './resources/graders/graders';\nimport { Realtime } from './resources/realtime/realtime';\nimport { Responses } from './resources/responses/responses';\nimport {\n  DeletedSkill,\n  Skill,\n  SkillCreateParams,\n  SkillList,\n  SkillListParams,\n  SkillUpdateParams,\n  Skills,\n  SkillsPage,\n} from './resources/skills/skills';\nimport {\n  Upload,\n  UploadCompleteParams,\n  UploadCreateParams,\n  Uploads as UploadsAPIUploads,\n} from './resources/uploads/uploads';\nimport {\n  AutoFileChunkingStrategyParam,\n  FileChunkingStrategy,\n  FileChunkingStrategyParam,\n  OtherFileChunkingStrategyObject,\n  StaticFileChunkingStrategy,\n  StaticFileChunkingStrategyObject,\n  StaticFileChunkingStrategyObjectParam,\n  VectorStore,\n  VectorStoreCreateParams,\n  VectorStoreDeleted,\n  VectorStoreListParams,\n  VectorStoreSearchParams,\n  VectorStoreSearchResponse,\n  VectorStoreSearchResponsesPage,\n  VectorStoreUpdateParams,\n  VectorStores,\n  VectorStoresPage,\n} from './resources/vector-stores/vector-stores';\nimport { Webhooks } from './resources/webhooks/webhooks';\nimport {\n  ChatCompletion,\n  ChatCompletionAllowedToolChoice,\n  ChatCompletionAllowedTools,\n  ChatCompletionAssistantMessageParam,\n  ChatCompletionAudio,\n  ChatCompletionAudioParam,\n  ChatCompletionChunk,\n  ChatCompletionContentPart,\n  ChatCompletionContentPartImage,\n  ChatCompletionContentPartInputAudio,\n  ChatCompletionContentPartRefusal,\n  ChatCompletionContentPartText,\n  ChatCompletionCreateParams,\n  ChatCompletionCreateParamsNonStreaming,\n  ChatCompletionCreateParamsStreaming,\n  ChatCompletionCustomTool,\n  ChatCompletionDeleted,\n  ChatCompletionDeveloperMessageParam,\n  ChatCompletionFunctionCallOption,\n  ChatCompletionFunctionMessageParam,\n  ChatCompletionFunctionTool,\n  ChatCompletionListParams,\n  ChatCompletionMessage,\n  ChatCompletionMessageCustomToolCall,\n  ChatCompletionMessageFunctionToolCall,\n  ChatCompletionMessageParam,\n  ChatCompletionMessageToolCall,\n  ChatCompletionModality,\n  ChatCompletionNamedToolChoice,\n  ChatCompletionNamedToolChoiceCustom,\n  ChatCompletionPredictionContent,\n  ChatCompletionReasoningEffort,\n  ChatCompletionRole,\n  ChatCompletionStoreMessage,\n  ChatCompletionStreamOptions,\n  ChatCompletionSystemMessageParam,\n  ChatCompletionTokenLogprob,\n  ChatCompletionTool,\n  ChatCompletionToolChoiceOption,\n  ChatCompletionToolMessageParam,\n  ChatCompletionUpdateParams,\n  ChatCompletionUserMessageParam,\n  ChatCompletionsPage,\n} from './resources/chat/completions/completions';\nimport { type Fetch } from './internal/builtin-types';\nimport { isRunningInBrowser } from './internal/detect-platform';\nimport { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';\nimport { FinalRequestOptions, RequestOptions } from './internal/request-options';\nimport { readEnv } from './internal/utils/env';\nimport {\n  type LogLevel,\n  type Logger,\n  formatRequestDetails,\n  loggerFor,\n  parseLogLevel,\n} from './internal/utils/log';\nimport { isEmptyObj } from './internal/utils/values';\n\nexport type ApiKeySetter = () => Promise<string>;\n\nexport interface ClientOptions {\n  /**\n   * API key used for authentication.\n   *\n   * - Accepts either a static string or an async function that resolves to a string.\n   * - Defaults to process.env['OPENAI_API_KEY'].\n   * - When a function is provided, it is invoked before each request so you can rotate\n   *   or refresh credentials at runtime.\n   * - The function must return a non-empty string; otherwise an OpenAIError is thrown.\n   * - If the function throws, the error is wrapped in an OpenAIError with the original\n   *   error available as `cause`.\n   */\n  apiKey?: string | ApiKeySetter | undefined;\n  /**\n   * Defaults to process.env['OPENAI_ORG_ID'].\n   */\n  organization?: string | null | undefined;\n\n  /**\n   * Defaults to process.env['OPENAI_PROJECT_ID'].\n   */\n  project?: string | null | undefined;\n\n  /**\n   * Defaults to process.env['OPENAI_WEBHOOK_SECRET'].\n   */\n  webhookSecret?: string | null | undefined;\n\n  /**\n   * Override the default base URL for the API, e.g., \"https://api.example.com/v2/\"\n   *\n   * Defaults to process.env['OPENAI_BASE_URL'].\n   */\n  baseURL?: string | null | undefined;\n\n  /**\n   * The maximum amount of time (in milliseconds) that the client should wait for a response\n   * from the server before timing out a single request.\n   *\n   * Note that request timeouts are retried by default, so in a worst-case scenario you may wait\n   * much longer than this timeout before the promise succeeds or fails.\n   *\n   * @unit milliseconds\n   */\n  timeout?: number | undefined;\n  /**\n   * Additional `RequestInit` options to be passed to `fetch` calls.\n   * Properties will be overridden by per-request `fetchOptions`.\n   */\n  fetchOptions?: MergedRequestInit | undefined;\n\n  /**\n   * Specify a custom `fetch` function implementation.\n   *\n   * If not provided, we expect that `fetch` is defined globally.\n   */\n  fetch?: Fetch | undefined;\n\n  /**\n   * The maximum number of times that the client will retry a request in case of a\n   * temporary failure, like a network error or a 5XX error from the server.\n   *\n   * @default 2\n   */\n  maxRetries?: number | undefined;\n\n  /**\n   * Default headers to include with every request to the API.\n   *\n   * These can be removed in individual requests by explicitly setting the\n   * header to `null` in request options.\n   */\n  defaultHeaders?: HeadersLike | undefined;\n\n  /**\n   * Default query parameters to include with every request to the API.\n   *\n   * These can be removed in individual requests by explicitly setting the\n   * param to `undefined` in request options.\n   */\n  defaultQuery?: Record<string, string | undefined> | undefined;\n\n  /**\n   * By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.\n   * Only set this option to `true` if you understand the risks and have appropriate mitigations in place.\n   */\n  dangerouslyAllowBrowser?: boolean | undefined;\n\n  /**\n   * Set the log level.\n   *\n   * Defaults to process.env['OPENAI_LOG'] or 'warn' if it isn't set.\n   */\n  logLevel?: LogLevel | undefined;\n\n  /**\n   * Set the logger.\n   *\n   * Defaults to globalThis.console.\n   */\n  logger?: Logger | undefined;\n}\n\n/**\n * API Client for interfacing with the OpenAI API.\n */\nexport class OpenAI {\n  apiKey: string;\n  organization: string | null;\n  project: string | null;\n  webhookSecret: string | null;\n\n  baseURL: string;\n  maxRetries: number;\n  timeout: number;\n  logger: Logger;\n  logLevel: LogLevel | undefined;\n  fetchOptions: MergedRequestInit | undefined;\n\n  private fetch: Fetch;\n  #encoder: Opts.RequestEncoder;\n  protected idempotencyHeader?: string;\n  protected _options: ClientOptions;\n\n  /**\n   * API Client for interfacing with the OpenAI API.\n   *\n   * @param {string | undefined} [opts.apiKey=process.env['OPENAI_API_KEY'] ?? undefined]\n   * @param {string | null | undefined} [opts.organization=process.env['OPENAI_ORG_ID'] ?? null]\n   * @param {string | null | undefined} [opts.project=process.env['OPENAI_PROJECT_ID'] ?? null]\n   * @param {string | null | undefined} [opts.webhookSecret=process.env['OPENAI_WEBHOOK_SECRET'] ?? null]\n   * @param {string} [opts.baseURL=process.env['OPENAI_BASE_URL'] ?? https://api.openai.com/v1] - Override the default base URL for the API.\n   * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.\n   * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.\n   * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.\n   * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.\n   * @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.\n   * @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.\n   * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.\n   */\n  constructor({\n    baseURL = readEnv('OPENAI_BASE_URL'),\n    apiKey = readEnv('OPENAI_API_KEY'),\n    organization = readEnv('OPENAI_ORG_ID') ?? null,\n    project = readEnv('OPENAI_PROJECT_ID') ?? null,\n    webhookSecret = readEnv('OPENAI_WEBHOOK_SECRET') ?? null,\n    ...opts\n  }: ClientOptions = {}) {\n    if (apiKey === undefined) {\n      throw new Errors.OpenAIError(\n        'Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.',\n      );\n    }\n\n    const options: ClientOptions = {\n      apiKey,\n      organization,\n      project,\n      webhookSecret,\n      ...opts,\n      baseURL: baseURL || `https://api.openai.com/v1`,\n    };\n\n    if (!options.dangerouslyAllowBrowser && isRunningInBrowser()) {\n      throw new Errors.OpenAIError(\n        \"It looks like you're running in a browser-like environment.\\n\\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\\nIf you understand the risks and have appropriate mitigations in place,\\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\\n\\nnew OpenAI({ apiKey, dangerouslyAllowBrowser: true });\\n\\nhttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\\n\",\n      );\n    }\n\n    this.baseURL = options.baseURL!;\n    this.timeout = options.timeout ?? OpenAI.DEFAULT_TIMEOUT /* 10 minutes */;\n    this.logger = options.logger ?? console;\n    const defaultLogLevel = 'warn';\n    // Set default logLevel early so that we can log a warning in parseLogLevel.\n    this.logLevel = defaultLogLevel;\n    this.logLevel =\n      parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??\n      parseLogLevel(readEnv('OPENAI_LOG'), \"process.env['OPENAI_LOG']\", this) ??\n      defaultLogLevel;\n    this.fetchOptions = options.fetchOptions;\n    this.maxRetries = options.maxRetries ?? 2;\n    this.fetch = options.fetch ?? Shims.getDefaultFetch();\n    this.#encoder = Opts.FallbackEncoder;\n\n    this._options = options;\n\n    this.apiKey = typeof apiKey === 'string' ? apiKey : 'Missing Key';\n    this.organization = organization;\n    this.project = project;\n    this.webhookSecret = webhookSecret;\n  }\n\n  /**\n   * Create a new client instance re-using the same options given to the current client with optional overriding.\n   */\n  withOptions(options: Partial<ClientOptions>): this {\n    const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({\n      ...this._options,\n      baseURL: this.baseURL,\n      maxRetries: this.maxRetries,\n      timeout: this.timeout,\n      logger: this.logger,\n      logLevel: this.logLevel,\n      fetch: this.fetch,\n      fetchOptions: this.fetchOptions,\n      apiKey: this.apiKey,\n      organization: this.organization,\n      project: this.project,\n      webhookSecret: this.webhookSecret,\n      ...options,\n    });\n    return client;\n  }\n\n  /**\n   * Check whether the base URL is set to its default.\n   */\n  #baseURLOverridden(): boolean {\n    return this.baseURL !== 'https://api.openai.com/v1';\n  }\n\n  protected defaultQuery(): Record<string, string | undefined> | undefined {\n    return this._options.defaultQuery;\n  }\n\n  protected validateHeaders({ values, nulls }: NullableHeaders) {\n    return;\n  }\n\n  protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {\n    return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);\n  }\n\n  protected stringifyQuery(query: object | Record<string, unknown>): string {\n    return stringifyQuery(query);\n  }\n\n  private getUserAgent(): string {\n    return `${this.constructor.name}/JS ${VERSION}`;\n  }\n\n  protected defaultIdempotencyKey(): string {\n    return `stainless-node-retry-${uuid4()}`;\n  }\n\n  protected makeStatusError(\n    status: number,\n    error: Object,\n    message: string | undefined,\n    headers: Headers,\n  ): Errors.APIError {\n    return Errors.APIError.generate(status, error, message, headers);\n  }\n\n  async _callApiKey(): Promise<boolean> {\n    const apiKey = this._options.apiKey;\n    if (typeof apiKey !== 'function') return false;\n\n    let token: unknown;\n    try {\n      token = await apiKey();\n    } catch (err: any) {\n      if (err instanceof Errors.OpenAIError) throw err;\n      throw new Errors.OpenAIError(\n        `Failed to get token from 'apiKey' function: ${err.message}`,\n        // @ts-ignore\n        { cause: err },\n      );\n    }\n\n    if (typeof token !== 'string' || !token) {\n      throw new Errors.OpenAIError(\n        `Expected 'apiKey' function argument to return a string but it returned ${token}`,\n      );\n    }\n    this.apiKey = token;\n    return true;\n  }\n\n  buildURL(\n    path: string,\n    query: Record<string, unknown> | null | undefined,\n    defaultBaseURL?: string | undefined,\n  ): string {\n    const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;\n    const url =\n      isAbsoluteURL(path) ?\n        new URL(path)\n      : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));\n\n    const defaultQuery = this.defaultQuery();\n    const pathQuery = Object.fromEntries(url.searchParams);\n    if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {\n      query = { ...pathQuery, ...defaultQuery, ...query };\n    }\n\n    if (typeof query === 'object' && query && !Array.isArray(query)) {\n      url.search = this.stringifyQuery(query);\n    }\n\n    return url.toString();\n  }\n\n  /**\n   * Used as a callback for mutating the given `FinalRequestOptions` object.\n   */\n  protected async prepareOptions(options: FinalRequestOptions): Promise<void> {\n    await this._callApiKey();\n  }\n\n  /**\n   * Used as a callback for mutating the given `RequestInit` object.\n   *\n   * This is useful for cases where you want to add certain headers based off of\n   * the request properties, e.g. `method` or `url`.\n   */\n  protected async prepareRequest(\n    request: RequestInit,\n    { url, options }: { url: string; options: FinalRequestOptions },\n  ): Promise<void> {}\n\n  get<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {\n    return this.methodRequest('get', path, opts);\n  }\n\n  post<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {\n    return this.methodRequest('post', path, opts);\n  }\n\n  patch<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {\n    return this.methodRequest('patch', path, opts);\n  }\n\n  put<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {\n    return this.methodRequest('put', path, opts);\n  }\n\n  delete<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {\n    return this.methodRequest('delete', path, opts);\n  }\n\n  private methodRequest<Rsp>(\n    method: HTTPMethod,\n    path: string,\n    opts?: PromiseOrValue<RequestOptions>,\n  ): APIPromise<Rsp> {\n    return this.request(\n      Promise.resolve(opts).then((opts) => {\n        return { method, path, ...opts };\n      }),\n    );\n  }\n\n  request<Rsp>(\n    options: PromiseOrValue<FinalRequestOptions>,\n    remainingRetries: number | null = null,\n  ): APIPromise<Rsp> {\n    return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));\n  }\n\n  private async makeRequest(\n    optionsInput: PromiseOrValue<FinalRequestOptions>,\n    retriesRemaining: number | null,\n    retryOfRequestLogID: string | undefined,\n  ): Promise<APIResponseProps> {\n    const options = await optionsInput;\n    const maxRetries = options.maxRetries ?? this.maxRetries;\n    if (retriesRemaining == null) {\n      retriesRemaining = maxRetries;\n    }\n\n    await this.prepareOptions(options);\n\n    const { req, url, timeout } = await this.buildRequest(options, {\n      retryCount: maxRetries - retriesRemaining,\n    });\n\n    await this.prepareRequest(req, { url, options });\n\n    /** Not an API request ID, just for correlating local log entries. */\n    const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');\n    const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;\n    const startTime = Date.now();\n\n    loggerFor(this).debug(\n      `[${requestLogID}] sending request`,\n      formatRequestDetails({\n        retryOfRequestLogID,\n        method: options.method,\n        url,\n        options,\n        headers: req.headers,\n      }),\n    );\n\n    if (options.signal?.aborted) {\n      throw new Errors.APIUserAbortError();\n    }\n\n    const controller = new AbortController();\n    const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);\n    const headersTime = Date.now();\n\n    if (response instanceof globalThis.Error) {\n      const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;\n      if (options.signal?.aborted) {\n        throw new Errors.APIUserAbortError();\n      }\n      // detect native connection timeout errors\n      // deno throws \"TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)\"\n      // undici throws \"TypeError: fetch failed\" with cause \"ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)\"\n      // others do not provide enough information to distinguish timeouts from other connection errors\n      const isTimeout =\n        isAbortError(response) ||\n        /timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));\n      if (retriesRemaining) {\n        loggerFor(this).info(\n          `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`,\n        );\n        loggerFor(this).debug(\n          `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`,\n          formatRequestDetails({\n            retryOfRequestLogID,\n            url,\n            durationMs: headersTime - startTime,\n            message: response.message,\n          }),\n        );\n        return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);\n      }\n      loggerFor(this).info(\n        `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`,\n      );\n      loggerFor(this).debug(\n        `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`,\n        formatRequestDetails({\n          retryOfRequestLogID,\n          url,\n          durationMs: headersTime - startTime,\n          message: response.message,\n        }),\n      );\n      if (isTimeout) {\n        throw new Errors.APIConnectionTimeoutError();\n      }\n      throw new Errors.APIConnectionError({ cause: response });\n    }\n\n    const specialHeaders = [...response.headers.entries()]\n      .filter(([name]) => name === 'x-request-id')\n      .map(([name, value]) => ', ' + name + ': ' + JSON.stringify(value))\n      .join('');\n    const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${\n      response.ok ? 'succeeded' : 'failed'\n    } with status ${response.status} in ${headersTime - startTime}ms`;\n\n    if (!response.ok) {\n      const shouldRetry = await this.shouldRetry(response);\n      if (retriesRemaining && shouldRetry) {\n        const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;\n\n        // We don't need the body of this response.\n        await Shims.CancelReadableStream(response.body);\n        loggerFor(this).info(`${responseInfo} - ${retryMessage}`);\n        loggerFor(this).debug(\n          `[${requestLogID}] response error (${retryMessage})`,\n          formatRequestDetails({\n            retryOfRequestLogID,\n            url: response.url,\n            status: response.status,\n            headers: response.headers,\n            durationMs: headersTime - startTime,\n          }),\n        );\n        return this.retryRequest(\n          options,\n          retriesRemaining,\n          retryOfRequestLogID ?? requestLogID,\n          response.headers,\n        );\n      }\n\n      const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;\n\n      loggerFor(this).info(`${responseInfo} - ${retryMessage}`);\n\n      const errText = await response.text().catch((err: any) => castToError(err).message);\n      const errJSON = safeJSON(errText) as any;\n      const errMessage = errJSON ? undefined : errText;\n\n      loggerFor(this).debug(\n        `[${requestLogID}] response error (${retryMessage})`,\n        formatRequestDetails({\n          retryOfRequestLogID,\n          url: response.url,\n          status: response.status,\n          headers: response.headers,\n          message: errMessage,\n          durationMs: Date.now() - startTime,\n        }),\n      );\n\n      const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);\n      throw err;\n    }\n\n    loggerFor(this).info(responseInfo);\n    loggerFor(this).debug(\n      `[${requestLogID}] response start`,\n      formatRequestDetails({\n        retryOfRequestLogID,\n        url: response.url,\n        status: response.status,\n        headers: response.headers,\n        durationMs: headersTime - startTime,\n      }),\n    );\n\n    return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };\n  }\n\n  getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(\n    path: string,\n    Page: new (...args: any[]) => PageClass,\n    opts?: PromiseOrValue<RequestOptions>,\n  ): Pagination.PagePromise<PageClass, Item> {\n    return this.requestAPIList(\n      Page,\n      opts && 'then' in opts ?\n        opts.then((opts) => ({ method: 'get', path, ...opts }))\n      : { method: 'get', path, ...opts },\n    );\n  }\n\n  requestAPIList<\n    Item = unknown,\n    PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,\n  >(\n    Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,\n    options: PromiseOrValue<FinalRequestOptions>,\n  ): Pagination.PagePromise<PageClass, Item> {\n    const request = this.makeRequest(options, null, undefined);\n    return new Pagination.PagePromise<PageClass, Item>(this as any as OpenAI, request, Page);\n  }\n\n  async fetchWithTimeout(\n    url: RequestInfo,\n    init: RequestInit | undefined,\n    ms: number,\n    controller: AbortController,\n  ): Promise<Response> {\n    const { signal, method, ...options } = init || {};\n    const abort = this._makeAbort(controller);\n    if (signal) signal.addEventListener('abort', abort, { once: true });\n\n    const timeout = setTimeout(abort, ms);\n\n    const isReadableBody =\n      ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||\n      (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);\n\n    const fetchOptions: RequestInit = {\n      signal: controller.signal as any,\n      ...(isReadableBody ? { duplex: 'half' } : {}),\n      method: 'GET',\n      ...options,\n    };\n    if (method) {\n      // Custom methods like 'patch' need to be uppercased\n      // See https://github.com/nodejs/undici/issues/2294\n      fetchOptions.method = method.toUpperCase();\n    }\n\n    try {\n      // use undefined this binding; fetch errors if bound to something else in browser/cloudflare\n      return await this.fetch.call(undefined, url, fetchOptions);\n    } finally {\n      clearTimeout(timeout);\n    }\n  }\n\n  private async shouldRetry(response: Response): Promise<boolean> {\n    // Note this is not a standard header.\n    const shouldRetryHeader = response.headers.get('x-should-retry');\n\n    // If the server explicitly says whether or not to retry, obey.\n    if (shouldRetryHeader === 'true') return true;\n    if (shouldRetryHeader === 'false') return false;\n\n    // Retry on request timeouts.\n    if (response.status === 408) return true;\n\n    // Retry on lock timeouts.\n    if (response.status === 409) return true;\n\n    // Retry on rate limits.\n    if (response.status === 429) return true;\n\n    // Retry internal errors.\n    if (response.status >= 500) return true;\n\n    return false;\n  }\n\n  private async retryRequest(\n    options: FinalRequestOptions,\n    retriesRemaining: number,\n    requestLogID: string,\n    responseHeaders?: Headers | undefined,\n  ): Promise<APIResponseProps> {\n    let timeoutMillis: number | undefined;\n\n    // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.\n    const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');\n    if (retryAfterMillisHeader) {\n      const timeoutMs = parseFloat(retryAfterMillisHeader);\n      if (!Number.isNaN(timeoutMs)) {\n        timeoutMillis = timeoutMs;\n      }\n    }\n\n    // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After\n    const retryAfterHeader = responseHeaders?.get('retry-after');\n    if (retryAfterHeader && !timeoutMillis) {\n      const timeoutSeconds = parseFloat(retryAfterHeader);\n      if (!Number.isNaN(timeoutSeconds)) {\n        timeoutMillis = timeoutSeconds * 1000;\n      } else {\n        timeoutMillis = Date.parse(retryAfterHeader) - Date.now();\n      }\n    }\n\n    // If the API asks us to wait a certain amount of time, just do what it\n    // says, but otherwise calculate a default\n    if (timeoutMillis === undefined) {\n      const maxRetries = options.maxRetries ?? this.maxRetries;\n      timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);\n    }\n    await sleep(timeoutMillis);\n\n    return this.makeRequest(options, retriesRemaining - 1, requestLogID);\n  }\n\n  private calculateDefaultRetryTimeoutMillis(retriesRemaining: number, maxRetries: number): number {\n    const initialRetryDelay = 0.5;\n    const maxRetryDelay = 8.0;\n\n    const numRetries = maxRetries - retriesRemaining;\n\n    // Apply exponential backoff, but not more than the max.\n    const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);\n\n    // Apply some jitter, take up to at most 25 percent of the retry time.\n    const jitter = 1 - Math.random() * 0.25;\n\n    return sleepSeconds * jitter * 1000;\n  }\n\n  async buildRequest(\n    inputOptions: FinalRequestOptions,\n    { retryCount = 0 }: { retryCount?: number } = {},\n  ): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {\n    const options = { ...inputOptions };\n    const { method, path, query, defaultBaseURL } = options;\n\n    const url = this.buildURL(path!, query as Record<string, unknown>, defaultBaseURL);\n    if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);\n    options.timeout = options.timeout ?? this.timeout;\n    const { bodyHeaders, body } = this.buildBody({ options });\n    const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });\n\n    const req: FinalizedRequestInit = {\n      method,\n      headers: reqHeaders,\n      ...(options.signal && { signal: options.signal }),\n      ...((globalThis as any).ReadableStream &&\n        body instanceof (globalThis as any).ReadableStream && { duplex: 'half' }),\n      ...(body && { body }),\n      ...((this.fetchOptions as any) ?? {}),\n      ...((options.fetchOptions as any) ?? {}),\n    };\n\n    return { req, url, timeout: options.timeout };\n  }\n\n  private async buildHeaders({\n    options,\n    method,\n    bodyHeaders,\n    retryCount,\n  }: {\n    options: FinalRequestOptions;\n    method: HTTPMethod;\n    bodyHeaders: HeadersLike;\n    retryCount: number;\n  }): Promise<Headers> {\n    let idempotencyHeaders: HeadersLike = {};\n    if (this.idempotencyHeader && method !== 'get') {\n      if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();\n      idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;\n    }\n\n    const headers = buildHeaders([\n      idempotencyHeaders,\n      {\n        Accept: 'application/json',\n        'User-Agent': this.getUserAgent(),\n        'X-Stainless-Retry-Count': String(retryCount),\n        ...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),\n        ...getPlatformHeaders(),\n        'OpenAI-Organization': this.organization,\n        'OpenAI-Project': this.project,\n      },\n      await this.authHeaders(options),\n      this._options.defaultHeaders,\n      bodyHeaders,\n      options.headers,\n    ]);\n\n    this.validateHeaders(headers);\n\n    return headers.values;\n  }\n\n  private _makeAbort(controller: AbortController) {\n    // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure\n    //       would capture all request options, and cause a memory leak.\n    return () => controller.abort();\n  }\n\n  private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {\n    bodyHeaders: HeadersLike;\n    body: BodyInit | undefined;\n  } {\n    if (!body) {\n      return { bodyHeaders: undefined, body: undefined };\n    }\n    const headers = buildHeaders([rawHeaders]);\n    if (\n      // Pass raw type verbatim\n      ArrayBuffer.isView(body) ||\n      body instanceof ArrayBuffer ||\n      body instanceof DataView ||\n      (typeof body === 'string' &&\n        // Preserve legacy string encoding behavior for now\n        headers.values.has('content-type')) ||\n      // `Blob` is superset of `File`\n      ((globalThis as any).Blob && body instanceof (globalThis as any).Blob) ||\n      // `FormData` -> `multipart/form-data`\n      body instanceof FormData ||\n      // `URLSearchParams` -> `application/x-www-form-urlencoded`\n      body instanceof URLSearchParams ||\n      // Send chunked stream (each chunk has own `length`)\n      ((globalThis as any).ReadableStream && body instanceof (globalThis as any).ReadableStream)\n    ) {\n      return { bodyHeaders: undefined, body: body as BodyInit };\n    } else if (\n      typeof body === 'object' &&\n      (Symbol.asyncIterator in body ||\n        (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))\n    ) {\n      return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };\n    } else if (\n      typeof body === 'object' &&\n      headers.values.get('content-type') === 'application/x-www-form-urlencoded'\n    ) {\n      return {\n        bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },\n        body: this.stringifyQuery(body),\n      };\n    } else {\n      return this.#encoder({ body, headers });\n    }\n  }\n\n  static OpenAI = this;\n  static DEFAULT_TIMEOUT = 600000; // 10 minutes\n\n  static OpenAIError = Errors.OpenAIError;\n  static APIError = Errors.APIError;\n  static APIConnectionError = Errors.APIConnectionError;\n  static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;\n  static APIUserAbortError = Errors.APIUserAbortError;\n  static NotFoundError = Errors.NotFoundError;\n  static ConflictError = Errors.ConflictError;\n  static RateLimitError = Errors.RateLimitError;\n  static BadRequestError = Errors.BadRequestError;\n  static AuthenticationError = Errors.AuthenticationError;\n  static InternalServerError = Errors.InternalServerError;\n  static PermissionDeniedError = Errors.PermissionDeniedError;\n  static UnprocessableEntityError = Errors.UnprocessableEntityError;\n  static InvalidWebhookSignatureError = Errors.InvalidWebhookSignatureError;\n\n  static toFile = Uploads.toFile;\n\n  /**\n   * Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.\n   */\n  completions: API.Completions = new API.Completions(this);\n  chat: API.Chat = new API.Chat(this);\n  /**\n   * Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.\n   */\n  embeddings: API.Embeddings = new API.Embeddings(this);\n  /**\n   * Files are used to upload documents that can be used with features like Assistants and Fine-tuning.\n   */\n  files: API.Files = new API.Files(this);\n  /**\n   * Given a prompt and/or an input image, the model will generate a new image.\n   */\n  images: API.Images = new API.Images(this);\n  audio: API.Audio = new API.Audio(this);\n  /**\n   * Given text and/or image inputs, classifies if those inputs are potentially harmful.\n   */\n  moderations: API.Moderations = new API.Moderations(this);\n  /**\n   * List and describe the various models available in the API.\n   */\n  models: API.Models = new API.Models(this);\n  fineTuning: API.FineTuning = new API.FineTuning(this);\n  graders: API.Graders = new API.Graders(this);\n  vectorStores: API.VectorStores = new API.VectorStores(this);\n  webhooks: API.Webhooks = new API.Webhooks(this);\n  beta: API.Beta = new API.Beta(this);\n  /**\n   * Create large batches of API requests to run asynchronously.\n   */\n  batches: API.Batches = new API.Batches(this);\n  /**\n   * Use Uploads to upload large files in multiple parts.\n   */\n  uploads: API.Uploads = new API.Uploads(this);\n  responses: API.Responses = new API.Responses(this);\n  realtime: API.Realtime = new API.Realtime(this);\n  /**\n   * Manage conversations and conversation items.\n   */\n  conversations: API.Conversations = new API.Conversations(this);\n  /**\n   * Manage and run evals in the OpenAI platform.\n   */\n  evals: API.Evals = new API.Evals(this);\n  containers: API.Containers = new API.Containers(this);\n  skills: API.Skills = new API.Skills(this);\n  videos: API.Videos = new API.Videos(this);\n}\n\nOpenAI.Completions = Completions;\nOpenAI.Chat = Chat;\nOpenAI.Embeddings = Embeddings;\nOpenAI.Files = Files;\nOpenAI.Images = Images;\nOpenAI.Audio = Audio;\nOpenAI.Moderations = Moderations;\nOpenAI.Models = Models;\nOpenAI.FineTuning = FineTuning;\nOpenAI.Graders = Graders;\nOpenAI.VectorStores = VectorStores;\nOpenAI.Webhooks = Webhooks;\nOpenAI.Beta = Beta;\nOpenAI.Batches = Batches;\nOpenAI.Uploads = UploadsAPIUploads;\nOpenAI.Responses = Responses;\nOpenAI.Realtime = Realtime;\nOpenAI.Conversations = Conversations;\nOpenAI.Evals = Evals;\nOpenAI.Containers = Containers;\nOpenAI.Skills = Skills;\nOpenAI.Videos = Videos;\n\nexport declare namespace OpenAI {\n  export type RequestOptions = Opts.RequestOptions;\n\n  export import Page = Pagination.Page;\n  export { type PageResponse as PageResponse };\n\n  export import CursorPage = Pagination.CursorPage;\n  export { type CursorPageParams as CursorPageParams, type CursorPageResponse as CursorPageResponse };\n\n  export import ConversationCursorPage = Pagination.ConversationCursorPage;\n  export {\n    type ConversationCursorPageParams as ConversationCursorPageParams,\n    type ConversationCursorPageResponse as ConversationCursorPageResponse,\n  };\n\n  export {\n    Completions as Completions,\n    type Completion as Completion,\n    type CompletionChoice as CompletionChoice,\n    type CompletionUsage as CompletionUsage,\n    type CompletionCreateParams as CompletionCreateParams,\n    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,\n    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,\n  };\n\n  export {\n    Chat as Chat,\n    type ChatCompletion as ChatCompletion,\n    type ChatCompletionAllowedToolChoice as ChatCompletionAllowedToolChoice,\n    type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,\n    type ChatCompletionAudio as ChatCompletionAudio,\n    type ChatCompletionAudioParam as ChatCompletionAudioParam,\n    type ChatCompletionChunk as ChatCompletionChunk,\n    type ChatCompletionContentPart as ChatCompletionContentPart,\n    type ChatCompletionContentPartImage as ChatCompletionContentPartImage,\n    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,\n    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,\n    type ChatCompletionContentPartText as ChatCompletionContentPartText,\n    type ChatCompletionCustomTool as ChatCompletionCustomTool,\n    type ChatCompletionDeleted as ChatCompletionDeleted,\n    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,\n    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,\n    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,\n    type ChatCompletionFunctionTool as ChatCompletionFunctionTool,\n    type ChatCompletionMessage as ChatCompletionMessage,\n    type ChatCompletionMessageCustomToolCall as ChatCompletionMessageCustomToolCall,\n    type ChatCompletionMessageFunctionToolCall as ChatCompletionMessageFunctionToolCall,\n    type ChatCompletionMessageParam as ChatCompletionMessageParam,\n    type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,\n    type ChatCompletionModality as ChatCompletionModality,\n    type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,\n    type ChatCompletionNamedToolChoiceCustom as ChatCompletionNamedToolChoiceCustom,\n    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,\n    type ChatCompletionRole as ChatCompletionRole,\n    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,\n    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,\n    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,\n    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,\n    type ChatCompletionTool as ChatCompletionTool,\n    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,\n    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,\n    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,\n    type ChatCompletionAllowedTools as ChatCompletionAllowedTools,\n    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,\n    type ChatCompletionsPage as ChatCompletionsPage,\n    type ChatCompletionCreateParams as ChatCompletionCreateParams,\n    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,\n    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,\n    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,\n    type ChatCompletionListParams as ChatCompletionListParams,\n  };\n\n  export {\n    Embeddings as Embeddings,\n    type CreateEmbeddingResponse as CreateEmbeddingResponse,\n    type Embedding as Embedding,\n    type EmbeddingModel as EmbeddingModel,\n    type EmbeddingCreateParams as EmbeddingCreateParams,\n  };\n\n  export {\n    Files as Files,\n    type FileContent as FileContent,\n    type FileDeleted as FileDeleted,\n    type FileObject as FileObject,\n    type FilePurpose as FilePurpose,\n    type FileObjectsPage as FileObjectsPage,\n    type FileCreateParams as FileCreateParams,\n    type FileListParams as FileListParams,\n  };\n\n  export {\n    Images as Images,\n    type Image as Image,\n    type ImageEditCompletedEvent as ImageEditCompletedEvent,\n    type ImageEditPartialImageEvent as ImageEditPartialImageEvent,\n    type ImageEditStreamEvent as ImageEditStreamEvent,\n    type ImageGenCompletedEvent as ImageGenCompletedEvent,\n    type ImageGenPartialImageEvent as ImageGenPartialImageEvent,\n    type ImageGenStreamEvent as ImageGenStreamEvent,\n    type ImageModel as ImageModel,\n    type ImagesResponse as ImagesResponse,\n    type ImageCreateVariationParams as ImageCreateVariationParams,\n    type ImageEditParams as ImageEditParams,\n    type ImageEditParamsNonStreaming as ImageEditParamsNonStreaming,\n    type ImageEditParamsStreaming as ImageEditParamsStreaming,\n    type ImageGenerateParams as ImageGenerateParams,\n    type ImageGenerateParamsNonStreaming as ImageGenerateParamsNonStreaming,\n    type ImageGenerateParamsStreaming as ImageGenerateParamsStreaming,\n  };\n\n  export { Audio as Audio, type AudioModel as AudioModel, type AudioResponseFormat as AudioResponseFormat };\n\n  export {\n    Moderations as Moderations,\n    type Moderation as Moderation,\n    type ModerationImageURLInput as ModerationImageURLInput,\n    type ModerationModel as ModerationModel,\n    type ModerationMultiModalInput as ModerationMultiModalInput,\n    type ModerationTextInput as ModerationTextInput,\n    type ModerationCreateResponse as ModerationCreateResponse,\n    type ModerationCreateParams as ModerationCreateParams,\n  };\n\n  export {\n    Models as Models,\n    type Model as Model,\n    type ModelDeleted as ModelDeleted,\n    type ModelsPage as ModelsPage,\n  };\n\n  export { FineTuning as FineTuning };\n\n  export { Graders as Graders };\n\n  export {\n    VectorStores as VectorStores,\n    type AutoFileChunkingStrategyParam as AutoFileChunkingStrategyParam,\n    type FileChunkingStrategy as FileChunkingStrategy,\n    type FileChunkingStrategyParam as FileChunkingStrategyParam,\n    type OtherFileChunkingStrategyObject as OtherFileChunkingStrategyObject,\n    type StaticFileChunkingStrategy as StaticFileChunkingStrategy,\n    type StaticFileChunkingStrategyObject as StaticFileChunkingStrategyObject,\n    type StaticFileChunkingStrategyObjectParam as StaticFileChunkingStrategyObjectParam,\n    type VectorStore as VectorStore,\n    type VectorStoreDeleted as VectorStoreDeleted,\n    type VectorStoreSearchResponse as VectorStoreSearchResponse,\n    type VectorStoresPage as VectorStoresPage,\n    type VectorStoreSearchResponsesPage as VectorStoreSearchResponsesPage,\n    type VectorStoreCreateParams as VectorStoreCreateParams,\n    type VectorStoreUpdateParams as VectorStoreUpdateParams,\n    type VectorStoreListParams as VectorStoreListParams,\n    type VectorStoreSearchParams as VectorStoreSearchParams,\n  };\n\n  export { Webhooks as Webhooks };\n\n  export { Beta as Beta };\n\n  export {\n    Batches as Batches,\n    type Batch as Batch,\n    type BatchError as BatchError,\n    type BatchRequestCounts as BatchRequestCounts,\n    type BatchUsage as BatchUsage,\n    type BatchesPage as BatchesPage,\n    type BatchCreateParams as BatchCreateParams,\n    type BatchListParams as BatchListParams,\n  };\n\n  export {\n    UploadsAPIUploads as Uploads,\n    type Upload as Upload,\n    type UploadCreateParams as UploadCreateParams,\n    type UploadCompleteParams as UploadCompleteParams,\n  };\n\n  export { Responses as Responses };\n\n  export { Realtime as Realtime };\n\n  export { Conversations as Conversations };\n\n  export {\n    Evals as Evals,\n    type EvalCustomDataSourceConfig as EvalCustomDataSourceConfig,\n    type EvalStoredCompletionsDataSourceConfig as EvalStoredCompletionsDataSourceConfig,\n    type EvalCreateResponse as EvalCreateResponse,\n    type EvalRetrieveResponse as EvalRetrieveResponse,\n    type EvalUpdateResponse as EvalUpdateResponse,\n    type EvalListResponse as EvalListResponse,\n    type EvalDeleteResponse as EvalDeleteResponse,\n    type EvalListResponsesPage as EvalListResponsesPage,\n    type EvalCreateParams as EvalCreateParams,\n    type EvalUpdateParams as EvalUpdateParams,\n    type EvalListParams as EvalListParams,\n  };\n\n  export {\n    Containers as Containers,\n    type ContainerCreateResponse as ContainerCreateResponse,\n    type ContainerRetrieveResponse as ContainerRetrieveResponse,\n    type ContainerListResponse as ContainerListResponse,\n    type ContainerListResponsesPage as ContainerListResponsesPage,\n    type ContainerCreateParams as ContainerCreateParams,\n    type ContainerListParams as ContainerListParams,\n  };\n\n  export {\n    Skills as Skills,\n    type DeletedSkill as DeletedSkill,\n    type Skill as Skill,\n    type SkillList as SkillList,\n    type SkillsPage as SkillsPage,\n    type SkillCreateParams as SkillCreateParams,\n    type SkillUpdateParams as SkillUpdateParams,\n    type SkillListParams as SkillListParams,\n  };\n\n  export {\n    Videos as Videos,\n    type ImageInputReferenceParam as ImageInputReferenceParam,\n    type Video as Video,\n    type VideoCreateError as VideoCreateError,\n    type VideoModel as VideoModel,\n    type VideoSeconds as VideoSeconds,\n    type VideoSize as VideoSize,\n    type VideoDeleteResponse as VideoDeleteResponse,\n    type VideoCreateCharacterResponse as VideoCreateCharacterResponse,\n    type VideoGetCharacterResponse as VideoGetCharacterResponse,\n    type VideosPage as VideosPage,\n    type VideoCreateParams as VideoCreateParams,\n    type VideoListParams as VideoListParams,\n    type VideoCreateCharacterParams as VideoCreateCharacterParams,\n    type VideoDownloadContentParams as VideoDownloadContentParams,\n    type VideoEditParams as VideoEditParams,\n    type VideoExtendParams as VideoExtendParams,\n    type VideoRemixParams as VideoRemixParams,\n  };\n\n  export type AllModels = API.AllModels;\n  export type ChatModel = API.ChatModel;\n  export type ComparisonFilter = API.ComparisonFilter;\n  export type CompoundFilter = API.CompoundFilter;\n  export type CustomToolInputFormat = API.CustomToolInputFormat;\n  export type ErrorObject = API.ErrorObject;\n  export type FunctionDefinition = API.FunctionDefinition;\n  export type FunctionParameters = API.FunctionParameters;\n  export type Metadata = API.Metadata;\n  export type Reasoning = API.Reasoning;\n  export type ReasoningEffort = API.ReasoningEffort;\n  export type ResponseFormatJSONObject = API.ResponseFormatJSONObject;\n  export type ResponseFormatJSONSchema = API.ResponseFormatJSONSchema;\n  export type ResponseFormatText = API.ResponseFormatText;\n  export type ResponseFormatTextGrammar = API.ResponseFormatTextGrammar;\n  export type ResponseFormatTextPython = API.ResponseFormatTextPython;\n  export type ResponsesModel = API.ResponsesModel;\n}\n"
  },
  {
    "path": "src/core/EventEmitter.ts",
    "content": "type EventListener<Events, EventType extends keyof Events> = Events[EventType];\n\ntype EventListeners<Events, EventType extends keyof Events> = Array<{\n  listener: EventListener<Events, EventType>;\n  once?: boolean;\n}>;\n\nexport type EventParameters<Events, EventType extends keyof Events> = {\n  [Event in EventType]: EventListener<Events, EventType> extends (...args: infer P) => any ? P : never;\n}[EventType];\n\nexport class EventEmitter<EventTypes extends Record<string, (...args: any) => any>> {\n  #listeners: {\n    [Event in keyof EventTypes]?: EventListeners<EventTypes, Event>;\n  } = {};\n\n  /**\n   * Adds the listener function to the end of the listeners array for the event.\n   * No checks are made to see if the listener has already been added. Multiple calls passing\n   * the same combination of event and listener will result in the listener being added, and\n   * called, multiple times.\n   * @returns this, so that calls can be chained\n   */\n  on<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n    const listeners: EventListeners<EventTypes, Event> =\n      this.#listeners[event] || (this.#listeners[event] = []);\n    listeners.push({ listener });\n    return this;\n  }\n\n  /**\n   * Removes the specified listener from the listener array for the event.\n   * off() will remove, at most, one instance of a listener from the listener array. If any single\n   * listener has been added multiple times to the listener array for the specified event, then\n   * off() must be called multiple times to remove each instance.\n   * @returns this, so that calls can be chained\n   */\n  off<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n    const listeners = this.#listeners[event];\n    if (!listeners) return this;\n    const index = listeners.findIndex((l) => l.listener === listener);\n    if (index >= 0) listeners.splice(index, 1);\n    return this;\n  }\n\n  /**\n   * Adds a one-time listener function for the event. The next time the event is triggered,\n   * this listener is removed and then invoked.\n   * @returns this, so that calls can be chained\n   */\n  once<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n    const listeners: EventListeners<EventTypes, Event> =\n      this.#listeners[event] || (this.#listeners[event] = []);\n    listeners.push({ listener, once: true });\n    return this;\n  }\n\n  /**\n   * This is similar to `.once()`, but returns a Promise that resolves the next time\n   * the event is triggered, instead of calling a listener callback.\n   * @returns a Promise that resolves the next time given event is triggered,\n   * or rejects if an error is emitted.  (If you request the 'error' event,\n   * returns a promise that resolves with the error).\n   *\n   * Example:\n   *\n   *   const message = await stream.emitted('message') // rejects if the stream errors\n   */\n  emitted<Event extends keyof EventTypes>(\n    event: Event,\n  ): Promise<\n    EventParameters<EventTypes, Event> extends [infer Param] ? Param\n    : EventParameters<EventTypes, Event> extends [] ? void\n    : EventParameters<EventTypes, Event>\n  > {\n    return new Promise((resolve, reject) => {\n      // TODO: handle errors\n      this.once(event, resolve as any);\n    });\n  }\n\n  protected _emit<Event extends keyof EventTypes>(\n    this: EventEmitter<EventTypes>,\n    event: Event,\n    ...args: EventParameters<EventTypes, Event>\n  ) {\n    const listeners: EventListeners<EventTypes, Event> | undefined = this.#listeners[event];\n    if (listeners) {\n      this.#listeners[event] = listeners.filter((l) => !l.once) as any;\n      listeners.forEach(({ listener }: any) => listener(...(args as any)));\n    }\n  }\n\n  protected _hasListener(event: keyof EventTypes): boolean {\n    const listeners = this.#listeners[event];\n    return listeners && listeners.length > 0;\n  }\n}\n"
  },
  {
    "path": "src/core/README.md",
    "content": "# `core`\n\nThis directory holds public modules implementing non-resource-specific SDK functionality.\n"
  },
  {
    "path": "src/core/api-promise.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { type OpenAI } from '../client';\n\nimport { type PromiseOrValue } from '../internal/types';\nimport {\n  type APIResponseProps,\n  defaultParseResponse,\n  type WithRequestID,\n  addRequestID,\n} from '../internal/parse';\n\n/**\n * A subclass of `Promise` providing additional helper methods\n * for interacting with the SDK.\n */\nexport class APIPromise<T> extends Promise<WithRequestID<T>> {\n  private parsedPromise: Promise<WithRequestID<T>> | undefined;\n  #client: OpenAI;\n\n  constructor(\n    client: OpenAI,\n    private responsePromise: Promise<APIResponseProps>,\n    private parseResponse: (\n      client: OpenAI,\n      props: APIResponseProps,\n    ) => PromiseOrValue<WithRequestID<T>> = defaultParseResponse,\n  ) {\n    super((resolve) => {\n      // this is maybe a bit weird but this has to be a no-op to not implicitly\n      // parse the response body; instead .then, .catch, .finally are overridden\n      // to parse the response\n      resolve(null as any);\n    });\n    this.#client = client;\n  }\n\n  _thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U> {\n    return new APIPromise(this.#client, this.responsePromise, async (client, props) =>\n      addRequestID(transform(await this.parseResponse(client, props), props), props.response),\n    );\n  }\n\n  /**\n   * Gets the raw `Response` instance instead of parsing the response\n   * data.\n   *\n   * If you want to parse the response body but still get the `Response`\n   * instance, you can use {@link withResponse()}.\n   *\n   * 👋 Getting the wrong TypeScript type for `Response`?\n   * Try setting `\"moduleResolution\": \"NodeNext\"` or add `\"lib\": [\"DOM\"]`\n   * to your `tsconfig.json`.\n   */\n  asResponse(): Promise<Response> {\n    return this.responsePromise.then((p) => p.response);\n  }\n\n  /**\n   * Gets the parsed response data, the raw `Response` instance and the ID of the request,\n   * returned via the X-Request-ID header which is useful for debugging requests and reporting\n   * issues to OpenAI.\n   *\n   * If you just want to get the raw `Response` instance without parsing it,\n   * you can use {@link asResponse()}.\n   *\n   * 👋 Getting the wrong TypeScript type for `Response`?\n   * Try setting `\"moduleResolution\": \"NodeNext\"` or add `\"lib\": [\"DOM\"]`\n   * to your `tsconfig.json`.\n   */\n  async withResponse(): Promise<{ data: T; response: Response; request_id: string | null }> {\n    const [data, response] = await Promise.all([this.parse(), this.asResponse()]);\n    return { data, response, request_id: response.headers.get('x-request-id') };\n  }\n\n  private parse(): Promise<WithRequestID<T>> {\n    if (!this.parsedPromise) {\n      this.parsedPromise = this.responsePromise.then((data) =>\n        this.parseResponse(this.#client, data),\n      ) as any as Promise<WithRequestID<T>>;\n    }\n    return this.parsedPromise;\n  }\n\n  override then<TResult1 = WithRequestID<T>, TResult2 = never>(\n    onfulfilled?: ((value: WithRequestID<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n    onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,\n  ): Promise<TResult1 | TResult2> {\n    return this.parse().then(onfulfilled, onrejected);\n  }\n\n  override catch<TResult = never>(\n    onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null,\n  ): Promise<WithRequestID<T> | TResult> {\n    return this.parse().catch(onrejected);\n  }\n\n  override finally(onfinally?: (() => void) | undefined | null): Promise<WithRequestID<T>> {\n    return this.parse().finally(onfinally);\n  }\n}\n"
  },
  {
    "path": "src/core/error.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { castToError } from '../internal/errors';\n\nexport class OpenAIError extends Error {}\n\nexport class APIError<\n  TStatus extends number | undefined = number | undefined,\n  THeaders extends Headers | undefined = Headers | undefined,\n  TError extends Object | undefined = Object | undefined,\n> extends OpenAIError {\n  /** HTTP status for the response that caused the error */\n  readonly status: TStatus;\n  /** HTTP headers for the response that caused the error */\n  readonly headers: THeaders;\n  /** JSON body of the response that caused the error */\n  readonly error: TError;\n\n  readonly code: string | null | undefined;\n  readonly param: string | null | undefined;\n  readonly type: string | undefined;\n\n  readonly requestID: string | null | undefined;\n\n  constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {\n    super(`${APIError.makeMessage(status, error, message)}`);\n    this.status = status;\n    this.headers = headers;\n    this.requestID = headers?.get('x-request-id');\n    this.error = error;\n\n    const data = error as Record<string, any>;\n    this.code = data?.['code'];\n    this.param = data?.['param'];\n    this.type = data?.['type'];\n  }\n\n  private static makeMessage(status: number | undefined, error: any, message: string | undefined) {\n    const msg =\n      error?.message ?\n        typeof error.message === 'string' ?\n          error.message\n        : JSON.stringify(error.message)\n      : error ? JSON.stringify(error)\n      : message;\n\n    if (status && msg) {\n      return `${status} ${msg}`;\n    }\n    if (status) {\n      return `${status} status code (no body)`;\n    }\n    if (msg) {\n      return msg;\n    }\n    return '(no status code or body)';\n  }\n\n  static generate(\n    status: number | undefined,\n    errorResponse: Object | undefined,\n    message: string | undefined,\n    headers: Headers | undefined,\n  ): APIError {\n    if (!status || !headers) {\n      return new APIConnectionError({ message, cause: castToError(errorResponse) });\n    }\n\n    const error = (errorResponse as Record<string, any>)?.['error'];\n\n    if (status === 400) {\n      return new BadRequestError(status, error, message, headers);\n    }\n\n    if (status === 401) {\n      return new AuthenticationError(status, error, message, headers);\n    }\n\n    if (status === 403) {\n      return new PermissionDeniedError(status, error, message, headers);\n    }\n\n    if (status === 404) {\n      return new NotFoundError(status, error, message, headers);\n    }\n\n    if (status === 409) {\n      return new ConflictError(status, error, message, headers);\n    }\n\n    if (status === 422) {\n      return new UnprocessableEntityError(status, error, message, headers);\n    }\n\n    if (status === 429) {\n      return new RateLimitError(status, error, message, headers);\n    }\n\n    if (status >= 500) {\n      return new InternalServerError(status, error, message, headers);\n    }\n\n    return new APIError(status, error, message, headers);\n  }\n}\n\nexport class APIUserAbortError extends APIError<undefined, undefined, undefined> {\n  constructor({ message }: { message?: string } = {}) {\n    super(undefined, undefined, message || 'Request was aborted.', undefined);\n  }\n}\n\nexport class APIConnectionError extends APIError<undefined, undefined, undefined> {\n  constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {\n    super(undefined, undefined, message || 'Connection error.', undefined);\n    // in some environments the 'cause' property is already declared\n    // @ts-ignore\n    if (cause) this.cause = cause;\n  }\n}\n\nexport class APIConnectionTimeoutError extends APIConnectionError {\n  constructor({ message }: { message?: string } = {}) {\n    super({ message: message ?? 'Request timed out.' });\n  }\n}\n\nexport class BadRequestError extends APIError<400, Headers> {}\n\nexport class AuthenticationError extends APIError<401, Headers> {}\n\nexport class PermissionDeniedError extends APIError<403, Headers> {}\n\nexport class NotFoundError extends APIError<404, Headers> {}\n\nexport class ConflictError extends APIError<409, Headers> {}\n\nexport class UnprocessableEntityError extends APIError<422, Headers> {}\n\nexport class RateLimitError extends APIError<429, Headers> {}\n\nexport class InternalServerError extends APIError<number, Headers> {}\n\nexport class LengthFinishReasonError extends OpenAIError {\n  constructor() {\n    super(`Could not parse response content as the length limit was reached`);\n  }\n}\n\nexport class ContentFilterFinishReasonError extends OpenAIError {\n  constructor() {\n    super(`Could not parse response content as the request was rejected by the content filter`);\n  }\n}\n\nexport class InvalidWebhookSignatureError extends Error {\n  constructor(message: string) {\n    super(message);\n  }\n}\n"
  },
  {
    "path": "src/core/pagination.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { OpenAIError } from './error';\nimport { FinalRequestOptions } from '../internal/request-options';\nimport { defaultParseResponse, WithRequestID } from '../internal/parse';\nimport { APIPromise } from './api-promise';\nimport { type OpenAI } from '../client';\nimport { type APIResponseProps } from '../internal/parse';\nimport { maybeObj } from '../internal/utils/values';\n\nexport type PageRequestOptions = Pick<FinalRequestOptions, 'query' | 'headers' | 'body' | 'path' | 'method'>;\n\nexport abstract class AbstractPage<Item> implements AsyncIterable<Item> {\n  #client: OpenAI;\n  protected options: FinalRequestOptions;\n\n  protected response: Response;\n  protected body: unknown;\n\n  constructor(client: OpenAI, response: Response, body: unknown, options: FinalRequestOptions) {\n    this.#client = client;\n    this.options = options;\n    this.response = response;\n    this.body = body;\n  }\n\n  abstract nextPageRequestOptions(): PageRequestOptions | null;\n\n  abstract getPaginatedItems(): Item[];\n\n  hasNextPage(): boolean {\n    const items = this.getPaginatedItems();\n    if (!items.length) return false;\n    return this.nextPageRequestOptions() != null;\n  }\n\n  async getNextPage(): Promise<this> {\n    const nextOptions = this.nextPageRequestOptions();\n    if (!nextOptions) {\n      throw new OpenAIError(\n        'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',\n      );\n    }\n\n    return await this.#client.requestAPIList(this.constructor as any, nextOptions);\n  }\n\n  async *iterPages(): AsyncGenerator<this> {\n    let page: this = this;\n    yield page;\n    while (page.hasNextPage()) {\n      page = await page.getNextPage();\n      yield page;\n    }\n  }\n\n  async *[Symbol.asyncIterator](): AsyncGenerator<Item> {\n    for await (const page of this.iterPages()) {\n      for (const item of page.getPaginatedItems()) {\n        yield item;\n      }\n    }\n  }\n}\n\n/**\n * This subclass of Promise will resolve to an instantiated Page once the request completes.\n *\n * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:\n *\n *    for await (const item of client.items.list()) {\n *      console.log(item)\n *    }\n */\nexport class PagePromise<\n    PageClass extends AbstractPage<Item>,\n    Item = ReturnType<PageClass['getPaginatedItems']>[number],\n  >\n  extends APIPromise<PageClass>\n  implements AsyncIterable<Item>\n{\n  constructor(\n    client: OpenAI,\n    request: Promise<APIResponseProps>,\n    Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,\n  ) {\n    super(\n      client,\n      request,\n      async (client, props) =>\n        new Page(\n          client,\n          props.response,\n          await defaultParseResponse(client, props),\n          props.options,\n        ) as WithRequestID<PageClass>,\n    );\n  }\n\n  /**\n   * Allow auto-paginating iteration on an unawaited list call, eg:\n   *\n   *    for await (const item of client.items.list()) {\n   *      console.log(item)\n   *    }\n   */\n  async *[Symbol.asyncIterator](): AsyncGenerator<Item> {\n    const page = await this;\n    for await (const item of page) {\n      yield item;\n    }\n  }\n}\n\nexport interface PageResponse<Item> {\n  data: Array<Item>;\n\n  object: string;\n}\n\n/**\n * Note: no pagination actually occurs yet, this is for forwards-compatibility.\n */\nexport class Page<Item> extends AbstractPage<Item> implements PageResponse<Item> {\n  data: Array<Item>;\n\n  object: string;\n\n  constructor(client: OpenAI, response: Response, body: PageResponse<Item>, options: FinalRequestOptions) {\n    super(client, response, body, options);\n\n    this.data = body.data || [];\n    this.object = body.object;\n  }\n\n  getPaginatedItems(): Item[] {\n    return this.data ?? [];\n  }\n\n  nextPageRequestOptions(): PageRequestOptions | null {\n    return null;\n  }\n}\n\nexport interface CursorPageResponse<Item> {\n  data: Array<Item>;\n\n  has_more: boolean;\n}\n\nexport interface CursorPageParams {\n  after?: string;\n\n  limit?: number;\n}\n\nexport class CursorPage<Item extends { id: string }>\n  extends AbstractPage<Item>\n  implements CursorPageResponse<Item>\n{\n  data: Array<Item>;\n\n  has_more: boolean;\n\n  constructor(\n    client: OpenAI,\n    response: Response,\n    body: CursorPageResponse<Item>,\n    options: FinalRequestOptions,\n  ) {\n    super(client, response, body, options);\n\n    this.data = body.data || [];\n    this.has_more = body.has_more || false;\n  }\n\n  getPaginatedItems(): Item[] {\n    return this.data ?? [];\n  }\n\n  override hasNextPage(): boolean {\n    if (this.has_more === false) {\n      return false;\n    }\n\n    return super.hasNextPage();\n  }\n\n  nextPageRequestOptions(): PageRequestOptions | null {\n    const data = this.getPaginatedItems();\n    const id = data[data.length - 1]?.id;\n    if (!id) {\n      return null;\n    }\n\n    return {\n      ...this.options,\n      query: {\n        ...maybeObj(this.options.query),\n        after: id,\n      },\n    };\n  }\n}\n\nexport interface ConversationCursorPageResponse<Item> {\n  data: Array<Item>;\n\n  has_more: boolean;\n\n  last_id: string;\n}\n\nexport interface ConversationCursorPageParams {\n  after?: string;\n\n  limit?: number;\n}\n\nexport class ConversationCursorPage<Item>\n  extends AbstractPage<Item>\n  implements ConversationCursorPageResponse<Item>\n{\n  data: Array<Item>;\n\n  has_more: boolean;\n\n  last_id: string;\n\n  constructor(\n    client: OpenAI,\n    response: Response,\n    body: ConversationCursorPageResponse<Item>,\n    options: FinalRequestOptions,\n  ) {\n    super(client, response, body, options);\n\n    this.data = body.data || [];\n    this.has_more = body.has_more || false;\n    this.last_id = body.last_id || '';\n  }\n\n  getPaginatedItems(): Item[] {\n    return this.data ?? [];\n  }\n\n  override hasNextPage(): boolean {\n    if (this.has_more === false) {\n      return false;\n    }\n\n    return super.hasNextPage();\n  }\n\n  nextPageRequestOptions(): PageRequestOptions | null {\n    const cursor = this.last_id;\n    if (!cursor) {\n      return null;\n    }\n\n    return {\n      ...this.options,\n      query: {\n        ...maybeObj(this.options.query),\n        after: cursor,\n      },\n    };\n  }\n}\n"
  },
  {
    "path": "src/core/resource.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport type { OpenAI } from '../client';\n\nexport abstract class APIResource {\n  protected _client: OpenAI;\n\n  constructor(client: OpenAI) {\n    this._client = client;\n  }\n}\n"
  },
  {
    "path": "src/core/streaming.ts",
    "content": "import { OpenAIError } from './error';\nimport { type ReadableStream } from '../internal/shim-types';\nimport { makeReadableStream } from '../internal/shims';\nimport { findDoubleNewlineIndex, LineDecoder } from '../internal/decoders/line';\nimport { ReadableStreamToAsyncIterable } from '../internal/shims';\nimport { isAbortError } from '../internal/errors';\nimport { encodeUTF8 } from '../internal/utils/bytes';\nimport { loggerFor } from '../internal/utils/log';\nimport type { OpenAI } from '../client';\n\nimport { APIError } from './error';\n\ntype Bytes = string | ArrayBuffer | Uint8Array | null | undefined;\n\nexport type ServerSentEvent = {\n  event: string | null;\n  data: string;\n  raw: string[];\n};\n\nexport class Stream<Item> implements AsyncIterable<Item> {\n  controller: AbortController;\n  #client: OpenAI | undefined;\n\n  constructor(\n    private iterator: () => AsyncIterator<Item>,\n    controller: AbortController,\n    client?: OpenAI,\n  ) {\n    this.controller = controller;\n    this.#client = client;\n  }\n\n  static fromSSEResponse<Item>(\n    response: Response,\n    controller: AbortController,\n    client?: OpenAI,\n    synthesizeEventData?: boolean,\n  ): Stream<Item> {\n    let consumed = false;\n    const logger = client ? loggerFor(client) : console;\n\n    async function* iterator(): AsyncIterator<Item, any, undefined> {\n      if (consumed) {\n        throw new OpenAIError('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');\n      }\n      consumed = true;\n      let done = false;\n      try {\n        for await (const sse of _iterSSEMessages(response, controller)) {\n          if (done) continue;\n\n          if (sse.data.startsWith('[DONE]')) {\n            done = true;\n            continue;\n          }\n\n          if (sse.event === null || !sse.event.startsWith('thread.')) {\n            let data;\n\n            try {\n              data = JSON.parse(sse.data) as any;\n            } catch (e) {\n              logger.error(`Could not parse message into JSON:`, sse.data);\n              logger.error(`From chunk:`, sse.raw);\n              throw e;\n            }\n\n            if (data && data.error) {\n              throw new APIError(undefined, data.error, undefined, response.headers);\n            }\n\n            yield synthesizeEventData ? { event: sse.event, data } : data;\n          } else {\n            let data;\n            try {\n              data = JSON.parse(sse.data);\n            } catch (e) {\n              console.error(`Could not parse message into JSON:`, sse.data);\n              console.error(`From chunk:`, sse.raw);\n              throw e;\n            }\n            // TODO: Is this where the error should be thrown?\n            if (sse.event == 'error') {\n              throw new APIError(undefined, data.error, data.message, undefined);\n            }\n            yield { event: sse.event, data: data } as any;\n          }\n        }\n        done = true;\n      } catch (e) {\n        // If the user calls `stream.controller.abort()`, we should exit without throwing.\n        if (isAbortError(e)) return;\n        throw e;\n      } finally {\n        // If the user `break`s, abort the ongoing request.\n        if (!done) controller.abort();\n      }\n    }\n\n    return new Stream(iterator, controller, client);\n  }\n\n  /**\n   * Generates a Stream from a newline-separated ReadableStream\n   * where each item is a JSON value.\n   */\n  static fromReadableStream<Item>(\n    readableStream: ReadableStream,\n    controller: AbortController,\n    client?: OpenAI,\n  ): Stream<Item> {\n    let consumed = false;\n\n    async function* iterLines(): AsyncGenerator<string, void, unknown> {\n      const lineDecoder = new LineDecoder();\n\n      const iter = ReadableStreamToAsyncIterable<Bytes>(readableStream);\n      for await (const chunk of iter) {\n        for (const line of lineDecoder.decode(chunk)) {\n          yield line;\n        }\n      }\n\n      for (const line of lineDecoder.flush()) {\n        yield line;\n      }\n    }\n\n    async function* iterator(): AsyncIterator<Item, any, undefined> {\n      if (consumed) {\n        throw new OpenAIError('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');\n      }\n      consumed = true;\n      let done = false;\n      try {\n        for await (const line of iterLines()) {\n          if (done) continue;\n          if (line) yield JSON.parse(line) as Item;\n        }\n        done = true;\n      } catch (e) {\n        // If the user calls `stream.controller.abort()`, we should exit without throwing.\n        if (isAbortError(e)) return;\n        throw e;\n      } finally {\n        // If the user `break`s, abort the ongoing request.\n        if (!done) controller.abort();\n      }\n    }\n\n    return new Stream(iterator, controller, client);\n  }\n\n  [Symbol.asyncIterator](): AsyncIterator<Item> {\n    return this.iterator();\n  }\n\n  /**\n   * Splits the stream into two streams which can be\n   * independently read from at different speeds.\n   */\n  tee(): [Stream<Item>, Stream<Item>] {\n    const left: Array<Promise<IteratorResult<Item>>> = [];\n    const right: Array<Promise<IteratorResult<Item>>> = [];\n    const iterator = this.iterator();\n\n    const teeIterator = (queue: Array<Promise<IteratorResult<Item>>>): AsyncIterator<Item> => {\n      return {\n        next: () => {\n          if (queue.length === 0) {\n            const result = iterator.next();\n            left.push(result);\n            right.push(result);\n          }\n          return queue.shift()!;\n        },\n      };\n    };\n\n    return [\n      new Stream(() => teeIterator(left), this.controller, this.#client),\n      new Stream(() => teeIterator(right), this.controller, this.#client),\n    ];\n  }\n\n  /**\n   * Converts this stream to a newline-separated ReadableStream of\n   * JSON stringified values in the stream\n   * which can be turned back into a Stream with `Stream.fromReadableStream()`.\n   */\n  toReadableStream(): ReadableStream {\n    const self = this;\n    let iter: AsyncIterator<Item>;\n\n    return makeReadableStream({\n      async start() {\n        iter = self[Symbol.asyncIterator]();\n      },\n      async pull(ctrl: any) {\n        try {\n          const { value, done } = await iter.next();\n          if (done) return ctrl.close();\n\n          const bytes = encodeUTF8(JSON.stringify(value) + '\\n');\n\n          ctrl.enqueue(bytes);\n        } catch (err) {\n          ctrl.error(err);\n        }\n      },\n      async cancel() {\n        await iter.return?.();\n      },\n    });\n  }\n}\n\nexport async function* _iterSSEMessages(\n  response: Response,\n  controller: AbortController,\n): AsyncGenerator<ServerSentEvent, void, unknown> {\n  if (!response.body) {\n    controller.abort();\n    if (\n      typeof (globalThis as any).navigator !== 'undefined' &&\n      (globalThis as any).navigator.product === 'ReactNative'\n    ) {\n      throw new OpenAIError(\n        `The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`,\n      );\n    }\n    throw new OpenAIError(`Attempted to iterate over a response with no body`);\n  }\n\n  const sseDecoder = new SSEDecoder();\n  const lineDecoder = new LineDecoder();\n\n  const iter = ReadableStreamToAsyncIterable<Bytes>(response.body);\n  for await (const sseChunk of iterSSEChunks(iter)) {\n    for (const line of lineDecoder.decode(sseChunk)) {\n      const sse = sseDecoder.decode(line);\n      if (sse) yield sse;\n    }\n  }\n\n  for (const line of lineDecoder.flush()) {\n    const sse = sseDecoder.decode(line);\n    if (sse) yield sse;\n  }\n}\n\n/**\n * Given an async iterable iterator, iterates over it and yields full\n * SSE chunks, i.e. yields when a double new-line is encountered.\n */\nasync function* iterSSEChunks(iterator: AsyncIterableIterator<Bytes>): AsyncGenerator<Uint8Array> {\n  let data = new Uint8Array();\n\n  for await (const chunk of iterator) {\n    if (chunk == null) {\n      continue;\n    }\n\n    const binaryChunk =\n      chunk instanceof ArrayBuffer ? new Uint8Array(chunk)\n      : typeof chunk === 'string' ? encodeUTF8(chunk)\n      : chunk;\n\n    let newData = new Uint8Array(data.length + binaryChunk.length);\n    newData.set(data);\n    newData.set(binaryChunk, data.length);\n    data = newData;\n\n    let patternIndex;\n    while ((patternIndex = findDoubleNewlineIndex(data)) !== -1) {\n      yield data.slice(0, patternIndex);\n      data = data.slice(patternIndex);\n    }\n  }\n\n  if (data.length > 0) {\n    yield data;\n  }\n}\n\nclass SSEDecoder {\n  private data: string[];\n  private event: string | null;\n  private chunks: string[];\n\n  constructor() {\n    this.event = null;\n    this.data = [];\n    this.chunks = [];\n  }\n\n  decode(line: string) {\n    if (line.endsWith('\\r')) {\n      line = line.substring(0, line.length - 1);\n    }\n\n    if (!line) {\n      // empty line and we didn't previously encounter any messages\n      if (!this.event && !this.data.length) return null;\n\n      const sse: ServerSentEvent = {\n        event: this.event,\n        data: this.data.join('\\n'),\n        raw: this.chunks,\n      };\n\n      this.event = null;\n      this.data = [];\n      this.chunks = [];\n\n      return sse;\n    }\n\n    this.chunks.push(line);\n\n    if (line.startsWith(':')) {\n      return null;\n    }\n\n    let [fieldname, _, value] = partition(line, ':');\n\n    if (value.startsWith(' ')) {\n      value = value.substring(1);\n    }\n\n    if (fieldname === 'event') {\n      this.event = value;\n    } else if (fieldname === 'data') {\n      this.data.push(value);\n    }\n\n    return null;\n  }\n}\n\nfunction partition(str: string, delimiter: string): [string, string, string] {\n  const index = str.indexOf(delimiter);\n  if (index !== -1) {\n    return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];\n  }\n\n  return [str, '', ''];\n}\n"
  },
  {
    "path": "src/core/uploads.ts",
    "content": "export { type Uploadable } from '../internal/uploads';\nexport { toFile, type ToFileInput } from '../internal/to-file';\n"
  },
  {
    "path": "src/error.ts",
    "content": "/** @deprecated Import from ./core/error instead */\nexport * from './core/error';\n"
  },
  {
    "path": "src/helpers/audio.ts",
    "content": "import { spawn } from 'node:child_process';\nimport { Readable } from 'node:stream';\nimport { platform, versions } from 'node:process';\nimport { checkFileSupport } from '../internal/uploads';\n\nconst DEFAULT_SAMPLE_RATE = 24000;\nconst DEFAULT_CHANNELS = 1;\n\nconst isNode = Boolean(versions?.node);\n\nconst recordingProviders: Record<NodeJS.Platform, string> = {\n  win32: 'dshow',\n  darwin: 'avfoundation',\n  linux: 'alsa',\n  aix: 'alsa',\n  android: 'alsa',\n  freebsd: 'alsa',\n  haiku: 'alsa',\n  sunos: 'alsa',\n  netbsd: 'alsa',\n  openbsd: 'alsa',\n  cygwin: 'dshow',\n};\n\nfunction isResponse(stream: NodeJS.ReadableStream | Response | File): stream is Response {\n  return typeof (stream as any).body !== 'undefined';\n}\n\nfunction isFile(stream: NodeJS.ReadableStream | Response | File): stream is File {\n  checkFileSupport();\n  return stream instanceof File;\n}\n\nasync function nodejsPlayAudio(stream: NodeJS.ReadableStream | Response | File): Promise<void> {\n  return new Promise((resolve, reject) => {\n    try {\n      const ffplay = spawn('ffplay', ['-autoexit', '-nodisp', '-i', 'pipe:0']);\n\n      if (isResponse(stream)) {\n        (stream.body! as any).pipe(ffplay.stdin);\n      } else if (isFile(stream)) {\n        Readable.from(stream.stream()).pipe(ffplay.stdin);\n      } else {\n        stream.pipe(ffplay.stdin);\n      }\n\n      ffplay.on('close', (code: number) => {\n        if (code !== 0) {\n          reject(new Error(`ffplay process exited with code ${code}`));\n        }\n        resolve();\n      });\n    } catch (error) {\n      reject(error);\n    }\n  });\n}\n\nexport async function playAudio(input: NodeJS.ReadableStream | Response | File): Promise<void> {\n  if (isNode) {\n    return nodejsPlayAudio(input);\n  }\n\n  throw new Error(\n    'Play audio is not supported in the browser yet. Check out https://npm.im/wavtools as an alternative.',\n  );\n}\n\ntype RecordAudioOptions = {\n  signal?: AbortSignal;\n  device?: number;\n  timeout?: number;\n};\n\nfunction nodejsRecordAudio({ signal, device, timeout }: RecordAudioOptions = {}): Promise<File> {\n  checkFileSupport();\n  return new Promise((resolve, reject) => {\n    const data: any[] = [];\n    const provider = recordingProviders[platform];\n    try {\n      const ffmpeg = spawn(\n        'ffmpeg',\n        [\n          '-f',\n          provider,\n          '-i',\n          `:${device ?? 0}`, // default audio input device; adjust as needed\n          '-ar',\n          DEFAULT_SAMPLE_RATE.toString(),\n          '-ac',\n          DEFAULT_CHANNELS.toString(),\n          '-f',\n          'wav',\n          'pipe:1',\n        ],\n        {\n          stdio: ['ignore', 'pipe', 'pipe'],\n        },\n      );\n\n      ffmpeg.stdout.on('data', (chunk) => {\n        data.push(chunk);\n      });\n\n      ffmpeg.on('error', (error) => {\n        console.error(error);\n        reject(error);\n      });\n\n      ffmpeg.on('close', (code) => {\n        returnData();\n      });\n\n      function returnData() {\n        const audioBuffer = Buffer.concat(data);\n        const audioFile = new File([audioBuffer], 'audio.wav', { type: 'audio/wav' });\n        resolve(audioFile);\n      }\n\n      if (typeof timeout === 'number' && timeout > 0) {\n        const internalSignal = AbortSignal.timeout(timeout);\n        internalSignal.addEventListener('abort', () => {\n          ffmpeg.kill('SIGTERM');\n        });\n      }\n\n      if (signal) {\n        signal.addEventListener('abort', () => {\n          ffmpeg.kill('SIGTERM');\n        });\n      }\n    } catch (error) {\n      reject(error);\n    }\n  });\n}\n\nexport async function recordAudio(options: RecordAudioOptions = {}) {\n  if (isNode) {\n    return nodejsRecordAudio(options);\n  }\n\n  throw new Error(\n    'Record audio is not supported in the browser. Check out https://npm.im/wavtools as an alternative.',\n  );\n}\n"
  },
  {
    "path": "src/helpers/zod.ts",
    "content": "import { ResponseFormatJSONSchema } from '../resources/index';\nimport * as z3 from 'zod/v3';\nimport * as z4 from 'zod/v4';\nimport {\n  AutoParseableResponseFormat,\n  AutoParseableTextFormat,\n  AutoParseableTool,\n  makeParseableResponseFormat,\n  makeParseableTextFormat,\n  makeParseableTool,\n} from '../lib/parser';\nimport { zodToJsonSchema as _zodToJsonSchema } from '../_vendor/zod-to-json-schema';\nimport { AutoParseableResponseTool, makeParseableResponseTool } from '../lib/ResponsesParser';\nimport { type ResponseFormatTextJSONSchemaConfig } from '../resources/responses/responses';\nimport { toStrictJsonSchema } from '../lib/transform';\nimport { JSONSchema } from '../lib/jsonschema';\n\ntype InferZodType<T> =\n  T extends z4.ZodType ? z4.infer<T>\n  : T extends z3.ZodType ? z3.infer<T>\n  : never;\n\nfunction zodV3ToJsonSchema(schema: z3.ZodType, options: { name: string }): Record<string, unknown> {\n  return _zodToJsonSchema(schema, {\n    openaiStrictMode: true,\n    name: options.name,\n    nameStrategy: 'duplicate-ref',\n    $refStrategy: 'extract-to-root',\n    nullableStrategy: 'property',\n  });\n}\n\nfunction zodV4ToJsonSchema(schema: z4.ZodType): Record<string, unknown> {\n  return toStrictJsonSchema(\n    z4.toJSONSchema(schema, {\n      target: 'draft-7',\n    }) as JSONSchema,\n  ) as Record<string, unknown>;\n}\n\nfunction isZodV4(zodObject: z3.ZodType | z4.ZodType): zodObject is z4.ZodType {\n  return '_zod' in zodObject;\n}\n\n/**\n * Creates a chat completion `JSONSchema` response format object from\n * the given Zod schema.\n *\n * If this is passed to the `.parse()`, `.stream()` or `.runTools()`\n * chat completion methods then the response message will contain a\n * `.parsed` property that is the result of parsing the content with\n * the given Zod object.\n *\n * ```ts\n * const completion = await client.chat.completions.parse({\n *    model: 'gpt-4o-2024-08-06',\n *    messages: [\n *      { role: 'system', content: 'You are a helpful math tutor.' },\n *      { role: 'user', content: 'solve 8x + 31 = 2' },\n *    ],\n *    response_format: zodResponseFormat(\n *      z.object({\n *        steps: z.array(z.object({\n *          explanation: z.string(),\n *          answer: z.string(),\n *        })),\n *        final_answer: z.string(),\n *      }),\n *      'math_answer',\n *    ),\n *  });\n *  const message = completion.choices[0]?.message;\n *  if (message?.parsed) {\n *    console.log(message.parsed);\n *    console.log(message.parsed.final_answer);\n * }\n * ```\n *\n * This can be passed directly to the `.create()` method but will not\n * result in any automatic parsing, you'll have to parse the response yourself.\n */\nexport function zodResponseFormat<ZodInput extends z3.ZodType | z4.ZodType>(\n  zodObject: ZodInput,\n  name: string,\n  props?: Omit<ResponseFormatJSONSchema.JSONSchema, 'schema' | 'strict' | 'name'>,\n): AutoParseableResponseFormat<InferZodType<ZodInput>> {\n  return makeParseableResponseFormat(\n    {\n      type: 'json_schema',\n      json_schema: {\n        ...props,\n        name,\n        strict: true,\n        schema: isZodV4(zodObject) ? zodV4ToJsonSchema(zodObject) : zodV3ToJsonSchema(zodObject, { name }),\n      },\n    },\n    (content) => zodObject.parse(JSON.parse(content)),\n  );\n}\n\nexport function zodTextFormat<ZodInput extends z3.ZodType | z4.ZodType>(\n  zodObject: ZodInput,\n  name: string,\n  props?: Omit<ResponseFormatTextJSONSchemaConfig, 'schema' | 'type' | 'strict' | 'name'>,\n): AutoParseableTextFormat<InferZodType<ZodInput>> {\n  return makeParseableTextFormat(\n    {\n      type: 'json_schema',\n      ...props,\n      name,\n      strict: true,\n      schema: isZodV4(zodObject) ? zodV4ToJsonSchema(zodObject) : zodV3ToJsonSchema(zodObject, { name }),\n    },\n    (content) => zodObject.parse(JSON.parse(content)),\n  );\n}\n\n/**\n * Creates a chat completion `function` tool that can be invoked\n * automatically by the chat completion `.runTools()` method or automatically\n * parsed by `.parse()` / `.stream()`.\n */\nexport function zodFunction<Parameters extends z3.ZodType | z4.ZodType>(options: {\n  name: string;\n  parameters: Parameters;\n  function?: ((args: InferZodType<Parameters>) => unknown | Promise<unknown>) | undefined;\n  description?: string | undefined;\n}): AutoParseableTool<{\n  arguments: Parameters;\n  name: string;\n  function: (args: InferZodType<Parameters>) => unknown;\n}> {\n  // @ts-expect-error TODO\n  return makeParseableTool<any>(\n    {\n      type: 'function',\n      function: {\n        name: options.name,\n        parameters:\n          isZodV4(options.parameters) ?\n            zodV4ToJsonSchema(options.parameters)\n          : zodV3ToJsonSchema(options.parameters, { name: options.name }),\n        strict: true,\n        ...(options.description ? { description: options.description } : undefined),\n      },\n    },\n    {\n      callback: options.function,\n      parser: (args) => options.parameters.parse(JSON.parse(args)),\n    },\n  );\n}\n\nexport function zodResponsesFunction<Parameters extends z3.ZodType | z4.ZodType>(options: {\n  name: string;\n  parameters: Parameters;\n  function?: ((args: InferZodType<Parameters>) => unknown | Promise<unknown>) | undefined;\n  description?: string | undefined;\n}): AutoParseableResponseTool<{\n  arguments: Parameters;\n  name: string;\n  function: (args: InferZodType<Parameters>) => unknown;\n}> {\n  return makeParseableResponseTool<any>(\n    {\n      type: 'function',\n      name: options.name,\n      parameters:\n        isZodV4(options.parameters) ?\n          zodV4ToJsonSchema(options.parameters)\n        : zodV3ToJsonSchema(options.parameters, { name: options.name }),\n      strict: true,\n      ...(options.description ? { description: options.description } : undefined),\n    },\n    {\n      callback: options.function,\n      parser: (args) => options.parameters.parse(JSON.parse(args)),\n    },\n  );\n}\n"
  },
  {
    "path": "src/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { OpenAI as default } from './client';\n\nexport { type Uploadable, toFile } from './core/uploads';\nexport { APIPromise } from './core/api-promise';\nexport { OpenAI, type ClientOptions } from './client';\nexport { PagePromise } from './core/pagination';\nexport {\n  OpenAIError,\n  APIError,\n  APIConnectionError,\n  APIConnectionTimeoutError,\n  APIUserAbortError,\n  NotFoundError,\n  ConflictError,\n  RateLimitError,\n  BadRequestError,\n  AuthenticationError,\n  InternalServerError,\n  PermissionDeniedError,\n  UnprocessableEntityError,\n  InvalidWebhookSignatureError,\n} from './core/error';\n\nexport { AzureOpenAI } from './azure';\n"
  },
  {
    "path": "src/internal/README.md",
    "content": "# `internal`\n\nThe modules in this directory are not importable outside this package and will change between releases.\n"
  },
  {
    "path": "src/internal/builtin-types.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;\n\n/**\n * An alias to the builtin `RequestInit` type so we can\n * easily alias it in import statements if there are name clashes.\n *\n * https://developer.mozilla.org/docs/Web/API/RequestInit\n */\ntype _RequestInit = RequestInit;\n\n/**\n * An alias to the builtin `Response` type so we can\n * easily alias it in import statements if there are name clashes.\n *\n * https://developer.mozilla.org/docs/Web/API/Response\n */\ntype _Response = Response;\n\n/**\n * The type for the first argument to `fetch`.\n *\n * https://developer.mozilla.org/docs/Web/API/Window/fetch#resource\n */\ntype _RequestInfo = Request | URL | string;\n\n/**\n * The type for constructing `RequestInit` Headers.\n *\n * https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers\n */\ntype _HeadersInit = RequestInit['headers'];\n\n/**\n * The type for constructing `RequestInit` body.\n *\n * https://developer.mozilla.org/docs/Web/API/RequestInit#body\n */\ntype _BodyInit = RequestInit['body'];\n\n/**\n * An alias to the builtin `Array<T>` type so we can\n * easily alias it in import statements if there are name clashes.\n */\ntype _Array<T> = Array<T>;\n\n/**\n * An alias to the builtin `Record<K, T>` type so we can\n * easily alias it in import statements if there are name clashes.\n */\ntype _Record<K extends keyof any, T> = Record<K, T>;\n\nexport type {\n  _Array as Array,\n  _BodyInit as BodyInit,\n  _HeadersInit as HeadersInit,\n  _Record as Record,\n  _RequestInfo as RequestInfo,\n  _RequestInit as RequestInit,\n  _Response as Response,\n};\n\n/**\n * A copy of the builtin `EndingType` type as it isn't fully supported in certain\n * environments and attempting to reference the global version will error.\n *\n * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941\n */\ntype EndingType = 'native' | 'transparent';\n\n/**\n * A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain\n * environments and attempting to reference the global version will error.\n *\n * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154\n * https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options\n */\nexport interface BlobPropertyBag {\n  endings?: EndingType;\n  type?: string;\n}\n\n/**\n * A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain\n * environments and attempting to reference the global version will error.\n *\n * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503\n * https://developer.mozilla.org/en-US/docs/Web/API/File/File#options\n */\nexport interface FilePropertyBag extends BlobPropertyBag {\n  lastModified?: number;\n}\n"
  },
  {
    "path": "src/internal/decoders/line.ts",
    "content": "import { concatBytes, decodeUTF8, encodeUTF8 } from '../utils/bytes';\n\nexport type Bytes = string | ArrayBuffer | Uint8Array | null | undefined;\n\n/**\n * A re-implementation of httpx's `LineDecoder` in Python that handles incrementally\n * reading lines from text.\n *\n * https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258\n */\nexport class LineDecoder {\n  // prettier-ignore\n  static NEWLINE_CHARS = new Set(['\\n', '\\r']);\n  static NEWLINE_REGEXP = /\\r\\n|[\\n\\r]/g;\n\n  #buffer: Uint8Array;\n  #carriageReturnIndex: number | null;\n\n  constructor() {\n    this.#buffer = new Uint8Array();\n    this.#carriageReturnIndex = null;\n  }\n\n  decode(chunk: Bytes): string[] {\n    if (chunk == null) {\n      return [];\n    }\n\n    const binaryChunk =\n      chunk instanceof ArrayBuffer ? new Uint8Array(chunk)\n      : typeof chunk === 'string' ? encodeUTF8(chunk)\n      : chunk;\n\n    this.#buffer = concatBytes([this.#buffer, binaryChunk]);\n\n    const lines: string[] = [];\n    let patternIndex;\n    while ((patternIndex = findNewlineIndex(this.#buffer, this.#carriageReturnIndex)) != null) {\n      if (patternIndex.carriage && this.#carriageReturnIndex == null) {\n        // skip until we either get a corresponding `\\n`, a new `\\r` or nothing\n        this.#carriageReturnIndex = patternIndex.index;\n        continue;\n      }\n\n      // we got double \\r or \\rtext\\n\n      if (\n        this.#carriageReturnIndex != null &&\n        (patternIndex.index !== this.#carriageReturnIndex + 1 || patternIndex.carriage)\n      ) {\n        lines.push(decodeUTF8(this.#buffer.subarray(0, this.#carriageReturnIndex - 1)));\n        this.#buffer = this.#buffer.subarray(this.#carriageReturnIndex);\n        this.#carriageReturnIndex = null;\n        continue;\n      }\n\n      const endIndex =\n        this.#carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;\n\n      const line = decodeUTF8(this.#buffer.subarray(0, endIndex));\n      lines.push(line);\n\n      this.#buffer = this.#buffer.subarray(patternIndex.index);\n      this.#carriageReturnIndex = null;\n    }\n\n    return lines;\n  }\n\n  flush(): string[] {\n    if (!this.#buffer.length) {\n      return [];\n    }\n    return this.decode('\\n');\n  }\n}\n\n/**\n * This function searches the buffer for the end patterns, (\\r or \\n)\n * and returns an object with the index preceding the matched newline and the\n * index after the newline char. `null` is returned if no new line is found.\n *\n * ```ts\n * findNewLineIndex('abc\\ndef') -> { preceding: 2, index: 3 }\n * ```\n */\nfunction findNewlineIndex(\n  buffer: Uint8Array,\n  startIndex: number | null,\n): { preceding: number; index: number; carriage: boolean } | null {\n  const newline = 0x0a; // \\n\n  const carriage = 0x0d; // \\r\n\n  for (let i = startIndex ?? 0; i < buffer.length; i++) {\n    if (buffer[i] === newline) {\n      return { preceding: i, index: i + 1, carriage: false };\n    }\n\n    if (buffer[i] === carriage) {\n      return { preceding: i, index: i + 1, carriage: true };\n    }\n  }\n\n  return null;\n}\n\nexport function findDoubleNewlineIndex(buffer: Uint8Array): number {\n  // This function searches the buffer for the end patterns (\\r\\r, \\n\\n, \\r\\n\\r\\n)\n  // and returns the index right after the first occurrence of any pattern,\n  // or -1 if none of the patterns are found.\n  const newline = 0x0a; // \\n\n  const carriage = 0x0d; // \\r\n\n  for (let i = 0; i < buffer.length - 1; i++) {\n    if (buffer[i] === newline && buffer[i + 1] === newline) {\n      // \\n\\n\n      return i + 2;\n    }\n    if (buffer[i] === carriage && buffer[i + 1] === carriage) {\n      // \\r\\r\n      return i + 2;\n    }\n    if (\n      buffer[i] === carriage &&\n      buffer[i + 1] === newline &&\n      i + 3 < buffer.length &&\n      buffer[i + 2] === carriage &&\n      buffer[i + 3] === newline\n    ) {\n      // \\r\\n\\r\\n\n      return i + 4;\n    }\n  }\n\n  return -1;\n}\n"
  },
  {
    "path": "src/internal/detect-platform.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { VERSION } from '../version';\n\nexport const isRunningInBrowser = () => {\n  return (\n    // @ts-ignore\n    typeof window !== 'undefined' &&\n    // @ts-ignore\n    typeof window.document !== 'undefined' &&\n    // @ts-ignore\n    typeof navigator !== 'undefined'\n  );\n};\n\ntype DetectedPlatform = 'deno' | 'node' | 'edge' | 'unknown';\n\n/**\n * Note this does not detect 'browser'; for that, use getBrowserInfo().\n */\nfunction getDetectedPlatform(): DetectedPlatform {\n  if (typeof Deno !== 'undefined' && Deno.build != null) {\n    return 'deno';\n  }\n  if (typeof EdgeRuntime !== 'undefined') {\n    return 'edge';\n  }\n  if (\n    Object.prototype.toString.call(\n      typeof (globalThis as any).process !== 'undefined' ? (globalThis as any).process : 0,\n    ) === '[object process]'\n  ) {\n    return 'node';\n  }\n  return 'unknown';\n}\n\ndeclare const Deno: any;\ndeclare const EdgeRuntime: any;\ntype Arch = 'x32' | 'x64' | 'arm' | 'arm64' | `other:${string}` | 'unknown';\ntype PlatformName =\n  | 'MacOS'\n  | 'Linux'\n  | 'Windows'\n  | 'FreeBSD'\n  | 'OpenBSD'\n  | 'iOS'\n  | 'Android'\n  | `Other:${string}`\n  | 'Unknown';\ntype Browser = 'ie' | 'edge' | 'chrome' | 'firefox' | 'safari';\ntype PlatformProperties = {\n  'X-Stainless-Lang': 'js';\n  'X-Stainless-Package-Version': string;\n  'X-Stainless-OS': PlatformName;\n  'X-Stainless-Arch': Arch;\n  'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | `browser:${Browser}` | 'unknown';\n  'X-Stainless-Runtime-Version': string;\n};\nconst getPlatformProperties = (): PlatformProperties => {\n  const detectedPlatform = getDetectedPlatform();\n  if (detectedPlatform === 'deno') {\n    return {\n      'X-Stainless-Lang': 'js',\n      'X-Stainless-Package-Version': VERSION,\n      'X-Stainless-OS': normalizePlatform(Deno.build.os),\n      'X-Stainless-Arch': normalizeArch(Deno.build.arch),\n      'X-Stainless-Runtime': 'deno',\n      'X-Stainless-Runtime-Version':\n        typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',\n    };\n  }\n  if (typeof EdgeRuntime !== 'undefined') {\n    return {\n      'X-Stainless-Lang': 'js',\n      'X-Stainless-Package-Version': VERSION,\n      'X-Stainless-OS': 'Unknown',\n      'X-Stainless-Arch': `other:${EdgeRuntime}`,\n      'X-Stainless-Runtime': 'edge',\n      'X-Stainless-Runtime-Version': (globalThis as any).process.version,\n    };\n  }\n  // Check if Node.js\n  if (detectedPlatform === 'node') {\n    return {\n      'X-Stainless-Lang': 'js',\n      'X-Stainless-Package-Version': VERSION,\n      'X-Stainless-OS': normalizePlatform((globalThis as any).process.platform ?? 'unknown'),\n      'X-Stainless-Arch': normalizeArch((globalThis as any).process.arch ?? 'unknown'),\n      'X-Stainless-Runtime': 'node',\n      'X-Stainless-Runtime-Version': (globalThis as any).process.version ?? 'unknown',\n    };\n  }\n\n  const browserInfo = getBrowserInfo();\n  if (browserInfo) {\n    return {\n      'X-Stainless-Lang': 'js',\n      'X-Stainless-Package-Version': VERSION,\n      'X-Stainless-OS': 'Unknown',\n      'X-Stainless-Arch': 'unknown',\n      'X-Stainless-Runtime': `browser:${browserInfo.browser}`,\n      'X-Stainless-Runtime-Version': browserInfo.version,\n    };\n  }\n\n  // TODO add support for Cloudflare workers, etc.\n  return {\n    'X-Stainless-Lang': 'js',\n    'X-Stainless-Package-Version': VERSION,\n    'X-Stainless-OS': 'Unknown',\n    'X-Stainless-Arch': 'unknown',\n    'X-Stainless-Runtime': 'unknown',\n    'X-Stainless-Runtime-Version': 'unknown',\n  };\n};\n\ntype BrowserInfo = {\n  browser: Browser;\n  version: string;\n};\n\ndeclare const navigator: { userAgent: string } | undefined;\n\n// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts\nfunction getBrowserInfo(): BrowserInfo | null {\n  if (typeof navigator === 'undefined' || !navigator) {\n    return null;\n  }\n\n  // NOTE: The order matters here!\n  const browserPatterns = [\n    { key: 'edge' as const, pattern: /Edge(?:\\W+(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?/ },\n    { key: 'ie' as const, pattern: /MSIE(?:\\W+(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?/ },\n    { key: 'ie' as const, pattern: /Trident(?:.*rv\\:(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?/ },\n    { key: 'chrome' as const, pattern: /Chrome(?:\\W+(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?/ },\n    { key: 'firefox' as const, pattern: /Firefox(?:\\W+(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?/ },\n    { key: 'safari' as const, pattern: /(?:Version\\W+(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?(?:\\W+Mobile\\S*)?\\W+Safari/ },\n  ];\n\n  // Find the FIRST matching browser\n  for (const { key, pattern } of browserPatterns) {\n    const match = pattern.exec(navigator.userAgent);\n    if (match) {\n      const major = match[1] || 0;\n      const minor = match[2] || 0;\n      const patch = match[3] || 0;\n\n      return { browser: key, version: `${major}.${minor}.${patch}` };\n    }\n  }\n\n  return null;\n}\n\nconst normalizeArch = (arch: string): Arch => {\n  // Node docs:\n  // - https://nodejs.org/api/process.html#processarch\n  // Deno docs:\n  // - https://doc.deno.land/deno/stable/~/Deno.build\n  if (arch === 'x32') return 'x32';\n  if (arch === 'x86_64' || arch === 'x64') return 'x64';\n  if (arch === 'arm') return 'arm';\n  if (arch === 'aarch64' || arch === 'arm64') return 'arm64';\n  if (arch) return `other:${arch}`;\n  return 'unknown';\n};\n\nconst normalizePlatform = (platform: string): PlatformName => {\n  // Node platforms:\n  // - https://nodejs.org/api/process.html#processplatform\n  // Deno platforms:\n  // - https://doc.deno.land/deno/stable/~/Deno.build\n  // - https://github.com/denoland/deno/issues/14799\n\n  platform = platform.toLowerCase();\n\n  // NOTE: this iOS check is untested and may not work\n  // Node does not work natively on IOS, there is a fork at\n  // https://github.com/nodejs-mobile/nodejs-mobile\n  // however it is unknown at the time of writing how to detect if it is running\n  if (platform.includes('ios')) return 'iOS';\n  if (platform === 'android') return 'Android';\n  if (platform === 'darwin') return 'MacOS';\n  if (platform === 'win32') return 'Windows';\n  if (platform === 'freebsd') return 'FreeBSD';\n  if (platform === 'openbsd') return 'OpenBSD';\n  if (platform === 'linux') return 'Linux';\n  if (platform) return `Other:${platform}`;\n  return 'Unknown';\n};\n\nlet _platformHeaders: PlatformProperties;\nexport const getPlatformHeaders = () => {\n  return (_platformHeaders ??= getPlatformProperties());\n};\n"
  },
  {
    "path": "src/internal/errors.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport function isAbortError(err: unknown) {\n  return (\n    typeof err === 'object' &&\n    err !== null &&\n    // Spec-compliant fetch implementations\n    (('name' in err && (err as any).name === 'AbortError') ||\n      // Expo fetch\n      ('message' in err && String((err as any).message).includes('FetchRequestCanceledException')))\n  );\n}\n\nexport const castToError = (err: any): Error => {\n  if (err instanceof Error) return err;\n  if (typeof err === 'object' && err !== null) {\n    try {\n      if (Object.prototype.toString.call(err) === '[object Error]') {\n        // @ts-ignore - not all envs have native support for cause yet\n        const error = new Error(err.message, err.cause ? { cause: err.cause } : {});\n        if (err.stack) error.stack = err.stack;\n        // @ts-ignore - not all envs have native support for cause yet\n        if (err.cause && !error.cause) error.cause = err.cause;\n        if (err.name) error.name = err.name;\n        return error;\n      }\n    } catch {}\n    try {\n      return new Error(JSON.stringify(err));\n    } catch {}\n  }\n  return new Error(err);\n};\n"
  },
  {
    "path": "src/internal/headers.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { isReadonlyArray } from './utils/values';\n\ntype HeaderValue = string | undefined | null;\nexport type HeadersLike =\n  | Headers\n  | readonly HeaderValue[][]\n  | Record<string, HeaderValue | readonly HeaderValue[]>\n  | undefined\n  | null\n  | NullableHeaders;\n\nconst brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');\n\n/**\n * @internal\n * Users can pass explicit nulls to unset default headers. When we parse them\n * into a standard headers type we need to preserve that information.\n */\nexport type NullableHeaders = {\n  /** Brand check, prevent users from creating a NullableHeaders. */\n  [brand_privateNullableHeaders]: true;\n  /** Parsed headers. */\n  values: Headers;\n  /** Set of lowercase header names explicitly set to null. */\n  nulls: Set<string>;\n};\n\nfunction* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [string, string | null]> {\n  if (!headers) return;\n\n  if (brand_privateNullableHeaders in headers) {\n    const { values, nulls } = headers;\n    yield* values.entries();\n    for (const name of nulls) {\n      yield [name, null];\n    }\n    return;\n  }\n\n  let shouldClear = false;\n  let iter: Iterable<readonly (HeaderValue | readonly HeaderValue[])[]>;\n  if (headers instanceof Headers) {\n    iter = headers.entries();\n  } else if (isReadonlyArray(headers)) {\n    iter = headers;\n  } else {\n    shouldClear = true;\n    iter = Object.entries(headers ?? {});\n  }\n  for (let row of iter) {\n    const name = row[0];\n    if (typeof name !== 'string') throw new TypeError('expected header name to be a string');\n    const values = isReadonlyArray(row[1]) ? row[1] : [row[1]];\n    let didClear = false;\n    for (const value of values) {\n      if (value === undefined) continue;\n\n      // Objects keys always overwrite older headers, they never append.\n      // Yield a null to clear the header before adding the new values.\n      if (shouldClear && !didClear) {\n        didClear = true;\n        yield [name, null];\n      }\n      yield [name, value];\n    }\n  }\n}\n\nexport const buildHeaders = (newHeaders: HeadersLike[]): NullableHeaders => {\n  const targetHeaders = new Headers();\n  const nullHeaders = new Set<string>();\n  for (const headers of newHeaders) {\n    const seenHeaders = new Set<string>();\n    for (const [name, value] of iterateHeaders(headers)) {\n      const lowerName = name.toLowerCase();\n      if (!seenHeaders.has(lowerName)) {\n        targetHeaders.delete(name);\n        seenHeaders.add(lowerName);\n      }\n      if (value === null) {\n        targetHeaders.delete(name);\n        nullHeaders.add(lowerName);\n      } else {\n        targetHeaders.append(name, value);\n        nullHeaders.delete(lowerName);\n      }\n    }\n  }\n  return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };\n};\n\nexport const isEmptyHeaders = (headers: HeadersLike) => {\n  for (const _ of iterateHeaders(headers)) return false;\n  return true;\n};\n"
  },
  {
    "path": "src/internal/parse.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport type { FinalRequestOptions } from './request-options';\nimport { Stream } from '../core/streaming';\nimport { type OpenAI } from '../client';\nimport { formatRequestDetails, loggerFor } from './utils/log';\nimport type { AbstractPage } from '../pagination';\n\nexport type APIResponseProps = {\n  response: Response;\n  options: FinalRequestOptions;\n  controller: AbortController;\n  requestLogID: string;\n  retryOfRequestLogID: string | undefined;\n  startTime: number;\n};\n\nexport async function defaultParseResponse<T>(\n  client: OpenAI,\n  props: APIResponseProps,\n): Promise<WithRequestID<T>> {\n  const { response, requestLogID, retryOfRequestLogID, startTime } = props;\n  const body = await (async () => {\n    if (props.options.stream) {\n      loggerFor(client).debug('response', response.status, response.url, response.headers, response.body);\n\n      // Note: there is an invariant here that isn't represented in the type system\n      // that if you set `stream: true` the response type must also be `Stream<T>`\n\n      if (props.options.__streamClass) {\n        return props.options.__streamClass.fromSSEResponse(\n          response,\n          props.controller,\n          client,\n          props.options.__synthesizeEventData,\n        ) as any;\n      }\n\n      return Stream.fromSSEResponse(\n        response,\n        props.controller,\n        client,\n        props.options.__synthesizeEventData,\n      ) as any;\n    }\n\n    // fetch refuses to read the body when the status code is 204.\n    if (response.status === 204) {\n      return null as T;\n    }\n\n    if (props.options.__binaryResponse) {\n      return response as unknown as T;\n    }\n\n    const contentType = response.headers.get('content-type');\n    const mediaType = contentType?.split(';')[0]?.trim();\n    const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');\n    if (isJSON) {\n      const contentLength = response.headers.get('content-length');\n      if (contentLength === '0') {\n        // if there is no content we can't do anything\n        return undefined as T;\n      }\n\n      const json = await response.json();\n      return addRequestID(json as T, response);\n    }\n\n    const text = await response.text();\n    return text as unknown as T;\n  })();\n  loggerFor(client).debug(\n    `[${requestLogID}] response parsed`,\n    formatRequestDetails({\n      retryOfRequestLogID,\n      url: response.url,\n      status: response.status,\n      body,\n      durationMs: Date.now() - startTime,\n    }),\n  );\n  return body;\n}\n\nexport type WithRequestID<T> =\n  T extends Array<any> | Response | AbstractPage<any> ? T\n  : T extends Record<string, any> ? T & { _request_id?: string | null }\n  : T;\n\nexport function addRequestID<T>(value: T, response: Response): WithRequestID<T> {\n  if (!value || typeof value !== 'object' || Array.isArray(value)) {\n    return value as WithRequestID<T>;\n  }\n\n  return Object.defineProperty(value, '_request_id', {\n    value: response.headers.get('x-request-id'),\n    enumerable: false,\n  }) as WithRequestID<T>;\n}\n"
  },
  {
    "path": "src/internal/qs/LICENSE.md",
    "content": "BSD 3-Clause License\n\nCopyright (c) 2014, Nathan LaFreniere and other [contributors](https://github.com/puruvj/neoqs/graphs/contributors) All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\n3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
  },
  {
    "path": "src/internal/qs/README.md",
    "content": "# qs\n\nThis is a vendored version of [neoqs](https://github.com/PuruVJ/neoqs) which is a TypeScript rewrite of [qs](https://github.com/ljharb/qs), a query string library.\n"
  },
  {
    "path": "src/internal/qs/formats.ts",
    "content": "import type { Format } from './types';\n\nexport const default_format: Format = 'RFC3986';\nexport const default_formatter = (v: PropertyKey) => String(v);\nexport const formatters: Record<Format, (str: PropertyKey) => string> = {\n  RFC1738: (v: PropertyKey) => String(v).replace(/%20/g, '+'),\n  RFC3986: default_formatter,\n};\nexport const RFC1738 = 'RFC1738';\nexport const RFC3986 = 'RFC3986';\n"
  },
  {
    "path": "src/internal/qs/index.ts",
    "content": "import { default_format, formatters, RFC1738, RFC3986 } from './formats';\n\nconst formats = {\n  formatters,\n  RFC1738,\n  RFC3986,\n  default: default_format,\n};\n\nexport { stringify } from './stringify';\nexport { formats };\n\nexport type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from './types';\n"
  },
  {
    "path": "src/internal/qs/stringify.ts",
    "content": "import { encode, is_buffer, maybe_map, has } from './utils';\nimport { default_format, default_formatter, formatters } from './formats';\nimport type { NonNullableProperties, StringifyOptions } from './types';\nimport { isArray } from '../utils/values';\n\nconst array_prefix_generators = {\n  brackets(prefix: PropertyKey) {\n    return String(prefix) + '[]';\n  },\n  comma: 'comma',\n  indices(prefix: PropertyKey, key: string) {\n    return String(prefix) + '[' + key + ']';\n  },\n  repeat(prefix: PropertyKey) {\n    return String(prefix);\n  },\n};\n\nconst push_to_array = function (arr: any[], value_or_array: any) {\n  Array.prototype.push.apply(arr, isArray(value_or_array) ? value_or_array : [value_or_array]);\n};\n\nlet toISOString;\n\nconst defaults = {\n  addQueryPrefix: false,\n  allowDots: false,\n  allowEmptyArrays: false,\n  arrayFormat: 'indices',\n  charset: 'utf-8',\n  charsetSentinel: false,\n  delimiter: '&',\n  encode: true,\n  encodeDotInKeys: false,\n  encoder: encode,\n  encodeValuesOnly: false,\n  format: default_format,\n  formatter: default_formatter,\n  /** @deprecated */\n  indices: false,\n  serializeDate(date) {\n    return (toISOString ??= Function.prototype.call.bind(Date.prototype.toISOString))(date);\n  },\n  skipNulls: false,\n  strictNullHandling: false,\n} as NonNullableProperties<StringifyOptions & { formatter: (typeof formatters)['RFC1738'] }>;\n\nfunction is_non_nullish_primitive(v: unknown): v is string | number | boolean | symbol | bigint {\n  return (\n    typeof v === 'string' ||\n    typeof v === 'number' ||\n    typeof v === 'boolean' ||\n    typeof v === 'symbol' ||\n    typeof v === 'bigint'\n  );\n}\n\nconst sentinel = {};\n\nfunction inner_stringify(\n  object: any,\n  prefix: PropertyKey,\n  generateArrayPrefix: StringifyOptions['arrayFormat'] | ((prefix: string, key: string) => string),\n  commaRoundTrip: boolean,\n  allowEmptyArrays: boolean,\n  strictNullHandling: boolean,\n  skipNulls: boolean,\n  encodeDotInKeys: boolean,\n  encoder: StringifyOptions['encoder'],\n  filter: StringifyOptions['filter'],\n  sort: StringifyOptions['sort'],\n  allowDots: StringifyOptions['allowDots'],\n  serializeDate: StringifyOptions['serializeDate'],\n  format: StringifyOptions['format'],\n  formatter: StringifyOptions['formatter'],\n  encodeValuesOnly: boolean,\n  charset: StringifyOptions['charset'],\n  sideChannel: WeakMap<any, any>,\n) {\n  let obj = object;\n\n  let tmp_sc = sideChannel;\n  let step = 0;\n  let find_flag = false;\n  while ((tmp_sc = tmp_sc.get(sentinel)) !== void undefined && !find_flag) {\n    // Where object last appeared in the ref tree\n    const pos = tmp_sc.get(object);\n    step += 1;\n    if (typeof pos !== 'undefined') {\n      if (pos === step) {\n        throw new RangeError('Cyclic object value');\n      } else {\n        find_flag = true; // Break while\n      }\n    }\n    if (typeof tmp_sc.get(sentinel) === 'undefined') {\n      step = 0;\n    }\n  }\n\n  if (typeof filter === 'function') {\n    obj = filter(prefix, obj);\n  } else if (obj instanceof Date) {\n    obj = serializeDate?.(obj);\n  } else if (generateArrayPrefix === 'comma' && isArray(obj)) {\n    obj = maybe_map(obj, function (value) {\n      if (value instanceof Date) {\n        return serializeDate?.(value);\n      }\n      return value;\n    });\n  }\n\n  if (obj === null) {\n    if (strictNullHandling) {\n      return encoder && !encodeValuesOnly ?\n          // @ts-expect-error\n          encoder(prefix, defaults.encoder, charset, 'key', format)\n        : prefix;\n    }\n\n    obj = '';\n  }\n\n  if (is_non_nullish_primitive(obj) || is_buffer(obj)) {\n    if (encoder) {\n      const key_value =\n        encodeValuesOnly ? prefix\n          // @ts-expect-error\n        : encoder(prefix, defaults.encoder, charset, 'key', format);\n      return [\n        formatter?.(key_value) +\n          '=' +\n          // @ts-expect-error\n          formatter?.(encoder(obj, defaults.encoder, charset, 'value', format)),\n      ];\n    }\n    return [formatter?.(prefix) + '=' + formatter?.(String(obj))];\n  }\n\n  const values: string[] = [];\n\n  if (typeof obj === 'undefined') {\n    return values;\n  }\n\n  let obj_keys;\n  if (generateArrayPrefix === 'comma' && isArray(obj)) {\n    // we need to join elements in\n    if (encodeValuesOnly && encoder) {\n      // @ts-expect-error values only\n      obj = maybe_map(obj, encoder);\n    }\n    obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];\n  } else if (isArray(filter)) {\n    obj_keys = filter;\n  } else {\n    const keys = Object.keys(obj);\n    obj_keys = sort ? keys.sort(sort) : keys;\n  }\n\n  const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\\./g, '%2E') : String(prefix);\n\n  const adjusted_prefix =\n    commaRoundTrip && isArray(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix;\n\n  if (allowEmptyArrays && isArray(obj) && obj.length === 0) {\n    return adjusted_prefix + '[]';\n  }\n\n  for (let j = 0; j < obj_keys.length; ++j) {\n    const key = obj_keys[j];\n    const value =\n      // @ts-ignore\n      typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key as any];\n\n    if (skipNulls && value === null) {\n      continue;\n    }\n\n    // @ts-ignore\n    const encoded_key = allowDots && encodeDotInKeys ? (key as any).replace(/\\./g, '%2E') : key;\n    const key_prefix =\n      isArray(obj) ?\n        typeof generateArrayPrefix === 'function' ?\n          generateArrayPrefix(adjusted_prefix, encoded_key)\n        : adjusted_prefix\n      : adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']');\n\n    sideChannel.set(object, step);\n    const valueSideChannel = new WeakMap();\n    valueSideChannel.set(sentinel, sideChannel);\n    push_to_array(\n      values,\n      inner_stringify(\n        value,\n        key_prefix,\n        generateArrayPrefix,\n        commaRoundTrip,\n        allowEmptyArrays,\n        strictNullHandling,\n        skipNulls,\n        encodeDotInKeys,\n        // @ts-ignore\n        generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder,\n        filter,\n        sort,\n        allowDots,\n        serializeDate,\n        format,\n        formatter,\n        encodeValuesOnly,\n        charset,\n        valueSideChannel,\n      ),\n    );\n  }\n\n  return values;\n}\n\nfunction normalize_stringify_options(\n  opts: StringifyOptions = defaults,\n): NonNullableProperties<Omit<StringifyOptions, 'indices'>> & { indices?: boolean } {\n  if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {\n    throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');\n  }\n\n  if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {\n    throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');\n  }\n\n  if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {\n    throw new TypeError('Encoder has to be a function.');\n  }\n\n  const charset = opts.charset || defaults.charset;\n  if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {\n    throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');\n  }\n\n  let format = default_format;\n  if (typeof opts.format !== 'undefined') {\n    if (!has(formatters, opts.format)) {\n      throw new TypeError('Unknown format option provided.');\n    }\n    format = opts.format;\n  }\n  const formatter = formatters[format];\n\n  let filter = defaults.filter;\n  if (typeof opts.filter === 'function' || isArray(opts.filter)) {\n    filter = opts.filter;\n  }\n\n  let arrayFormat: StringifyOptions['arrayFormat'];\n  if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) {\n    arrayFormat = opts.arrayFormat;\n  } else if ('indices' in opts) {\n    arrayFormat = opts.indices ? 'indices' : 'repeat';\n  } else {\n    arrayFormat = defaults.arrayFormat;\n  }\n\n  if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {\n    throw new TypeError('`commaRoundTrip` must be a boolean, or absent');\n  }\n\n  const allowDots =\n    typeof opts.allowDots === 'undefined' ?\n      !!opts.encodeDotInKeys === true ?\n        true\n      : defaults.allowDots\n    : !!opts.allowDots;\n\n  return {\n    addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,\n    // @ts-ignore\n    allowDots: allowDots,\n    allowEmptyArrays:\n      typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,\n    arrayFormat: arrayFormat,\n    charset: charset,\n    charsetSentinel:\n      typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,\n    commaRoundTrip: !!opts.commaRoundTrip,\n    delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,\n    encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,\n    encodeDotInKeys:\n      typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,\n    encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,\n    encodeValuesOnly:\n      typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,\n    filter: filter,\n    format: format,\n    formatter: formatter,\n    serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,\n    skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,\n    // @ts-ignore\n    sort: typeof opts.sort === 'function' ? opts.sort : null,\n    strictNullHandling:\n      typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling,\n  };\n}\n\nexport function stringify(object: any, opts: StringifyOptions = {}) {\n  let obj = object;\n  const options = normalize_stringify_options(opts);\n\n  let obj_keys: PropertyKey[] | undefined;\n  let filter;\n\n  if (typeof options.filter === 'function') {\n    filter = options.filter;\n    obj = filter('', obj);\n  } else if (isArray(options.filter)) {\n    filter = options.filter;\n    obj_keys = filter;\n  }\n\n  const keys: string[] = [];\n\n  if (typeof obj !== 'object' || obj === null) {\n    return '';\n  }\n\n  const generateArrayPrefix = array_prefix_generators[options.arrayFormat];\n  const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;\n\n  if (!obj_keys) {\n    obj_keys = Object.keys(obj);\n  }\n\n  if (options.sort) {\n    obj_keys.sort(options.sort);\n  }\n\n  const sideChannel = new WeakMap();\n  for (let i = 0; i < obj_keys.length; ++i) {\n    const key = obj_keys[i]!;\n\n    if (options.skipNulls && obj[key] === null) {\n      continue;\n    }\n    push_to_array(\n      keys,\n      inner_stringify(\n        obj[key],\n        key,\n        // @ts-expect-error\n        generateArrayPrefix,\n        commaRoundTrip,\n        options.allowEmptyArrays,\n        options.strictNullHandling,\n        options.skipNulls,\n        options.encodeDotInKeys,\n        options.encode ? options.encoder : null,\n        options.filter,\n        options.sort,\n        options.allowDots,\n        options.serializeDate,\n        options.format,\n        options.formatter,\n        options.encodeValuesOnly,\n        options.charset,\n        sideChannel,\n      ),\n    );\n  }\n\n  const joined = keys.join(options.delimiter);\n  let prefix = options.addQueryPrefix === true ? '?' : '';\n\n  if (options.charsetSentinel) {\n    if (options.charset === 'iso-8859-1') {\n      // encodeURIComponent('&#10003;'), the \"numeric entity\" representation of a checkmark\n      prefix += 'utf8=%26%2310003%3B&';\n    } else {\n      // encodeURIComponent('✓')\n      prefix += 'utf8=%E2%9C%93&';\n    }\n  }\n\n  return joined.length > 0 ? prefix + joined : '';\n}\n"
  },
  {
    "path": "src/internal/qs/types.ts",
    "content": "export type Format = 'RFC1738' | 'RFC3986';\n\nexport type DefaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string;\nexport type DefaultDecoder = (str: string, decoder?: any, charset?: string) => string;\n\nexport type BooleanOptional = boolean | undefined;\n\nexport type StringifyBaseOptions = {\n  delimiter?: string;\n  allowDots?: boolean;\n  encodeDotInKeys?: boolean;\n  strictNullHandling?: boolean;\n  skipNulls?: boolean;\n  encode?: boolean;\n  encoder?: (\n    str: any,\n    defaultEncoder: DefaultEncoder,\n    charset: string,\n    type: 'key' | 'value',\n    format?: Format,\n  ) => string;\n  filter?: Array<PropertyKey> | ((prefix: PropertyKey, value: any) => any);\n  arrayFormat?: 'indices' | 'brackets' | 'repeat' | 'comma';\n  indices?: boolean;\n  sort?: ((a: PropertyKey, b: PropertyKey) => number) | null;\n  serializeDate?: (d: Date) => string;\n  format?: 'RFC1738' | 'RFC3986';\n  formatter?: (str: PropertyKey) => string;\n  encodeValuesOnly?: boolean;\n  addQueryPrefix?: boolean;\n  charset?: 'utf-8' | 'iso-8859-1';\n  charsetSentinel?: boolean;\n  allowEmptyArrays?: boolean;\n  commaRoundTrip?: boolean;\n};\n\nexport type StringifyOptions = StringifyBaseOptions;\n\nexport type ParseBaseOptions = {\n  comma?: boolean;\n  delimiter?: string | RegExp;\n  depth?: number | false;\n  decoder?: (str: string, defaultDecoder: DefaultDecoder, charset: string, type: 'key' | 'value') => any;\n  arrayLimit?: number;\n  parseArrays?: boolean;\n  plainObjects?: boolean;\n  allowPrototypes?: boolean;\n  allowSparse?: boolean;\n  parameterLimit?: number;\n  strictDepth?: boolean;\n  strictNullHandling?: boolean;\n  ignoreQueryPrefix?: boolean;\n  charset?: 'utf-8' | 'iso-8859-1';\n  charsetSentinel?: boolean;\n  interpretNumericEntities?: boolean;\n  allowEmptyArrays?: boolean;\n  duplicates?: 'combine' | 'first' | 'last';\n  allowDots?: boolean;\n  decodeDotInKeys?: boolean;\n};\n\nexport type ParseOptions = ParseBaseOptions;\n\nexport type ParsedQs = {\n  [key: string]: undefined | string | string[] | ParsedQs | ParsedQs[];\n};\n\n// Type to remove null or undefined union from each property\nexport type NonNullableProperties<T> = {\n  [K in keyof T]-?: Exclude<T[K], undefined | null>;\n};\n"
  },
  {
    "path": "src/internal/qs/utils.ts",
    "content": "import { RFC1738 } from './formats';\nimport type { DefaultEncoder, Format } from './types';\nimport { isArray } from '../utils/values';\n\nexport let has = (obj: object, key: PropertyKey): boolean => (\n  (has = (Object as any).hasOwn ?? Function.prototype.call.bind(Object.prototype.hasOwnProperty)),\n  has(obj, key)\n);\n\nconst hex_table = /* @__PURE__ */ (() => {\n  const array = [];\n  for (let i = 0; i < 256; ++i) {\n    array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());\n  }\n\n  return array;\n})();\n\nfunction compact_queue<T extends Record<string, any>>(queue: Array<{ obj: T; prop: string }>) {\n  while (queue.length > 1) {\n    const item = queue.pop();\n    if (!item) continue;\n\n    const obj = item.obj[item.prop];\n\n    if (isArray(obj)) {\n      const compacted: unknown[] = [];\n\n      for (let j = 0; j < obj.length; ++j) {\n        if (typeof obj[j] !== 'undefined') {\n          compacted.push(obj[j]);\n        }\n      }\n\n      // @ts-ignore\n      item.obj[item.prop] = compacted;\n    }\n  }\n}\n\nfunction array_to_object(source: any[], options: { plainObjects: boolean }) {\n  const obj = options && options.plainObjects ? Object.create(null) : {};\n  for (let i = 0; i < source.length; ++i) {\n    if (typeof source[i] !== 'undefined') {\n      obj[i] = source[i];\n    }\n  }\n\n  return obj;\n}\n\nexport function merge(\n  target: any,\n  source: any,\n  options: { plainObjects?: boolean; allowPrototypes?: boolean } = {},\n) {\n  if (!source) {\n    return target;\n  }\n\n  if (typeof source !== 'object') {\n    if (isArray(target)) {\n      target.push(source);\n    } else if (target && typeof target === 'object') {\n      if ((options && (options.plainObjects || options.allowPrototypes)) || !has(Object.prototype, source)) {\n        target[source] = true;\n      }\n    } else {\n      return [target, source];\n    }\n\n    return target;\n  }\n\n  if (!target || typeof target !== 'object') {\n    return [target].concat(source);\n  }\n\n  let mergeTarget = target;\n  if (isArray(target) && !isArray(source)) {\n    // @ts-ignore\n    mergeTarget = array_to_object(target, options);\n  }\n\n  if (isArray(target) && isArray(source)) {\n    source.forEach(function (item, i) {\n      if (has(target, i)) {\n        const targetItem = target[i];\n        if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {\n          target[i] = merge(targetItem, item, options);\n        } else {\n          target.push(item);\n        }\n      } else {\n        target[i] = item;\n      }\n    });\n    return target;\n  }\n\n  return Object.keys(source).reduce(function (acc, key) {\n    const value = source[key];\n\n    if (has(acc, key)) {\n      acc[key] = merge(acc[key], value, options);\n    } else {\n      acc[key] = value;\n    }\n    return acc;\n  }, mergeTarget);\n}\n\nexport function assign_single_source(target: any, source: any) {\n  return Object.keys(source).reduce(function (acc, key) {\n    acc[key] = source[key];\n    return acc;\n  }, target);\n}\n\nexport function decode(str: string, _: any, charset: string) {\n  const strWithoutPlus = str.replace(/\\+/g, ' ');\n  if (charset === 'iso-8859-1') {\n    // unescape never throws, no try...catch needed:\n    return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);\n  }\n  // utf-8\n  try {\n    return decodeURIComponent(strWithoutPlus);\n  } catch (e) {\n    return strWithoutPlus;\n  }\n}\n\nconst limit = 1024;\n\nexport const encode: (\n  str: any,\n  defaultEncoder: DefaultEncoder,\n  charset: string,\n  type: 'key' | 'value',\n  format: Format,\n) => string = (str, _defaultEncoder, charset, _kind, format: Format) => {\n  // This code was originally written by Brian White for the io.js core querystring library.\n  // It has been adapted here for stricter adherence to RFC 3986\n  if (str.length === 0) {\n    return str;\n  }\n\n  let string = str;\n  if (typeof str === 'symbol') {\n    string = Symbol.prototype.toString.call(str);\n  } else if (typeof str !== 'string') {\n    string = String(str);\n  }\n\n  if (charset === 'iso-8859-1') {\n    return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {\n      return '%26%23' + parseInt($0.slice(2), 16) + '%3B';\n    });\n  }\n\n  let out = '';\n  for (let j = 0; j < string.length; j += limit) {\n    const segment = string.length >= limit ? string.slice(j, j + limit) : string;\n    const arr = [];\n\n    for (let i = 0; i < segment.length; ++i) {\n      let c = segment.charCodeAt(i);\n      if (\n        c === 0x2d || // -\n        c === 0x2e || // .\n        c === 0x5f || // _\n        c === 0x7e || // ~\n        (c >= 0x30 && c <= 0x39) || // 0-9\n        (c >= 0x41 && c <= 0x5a) || // a-z\n        (c >= 0x61 && c <= 0x7a) || // A-Z\n        (format === RFC1738 && (c === 0x28 || c === 0x29)) // ( )\n      ) {\n        arr[arr.length] = segment.charAt(i);\n        continue;\n      }\n\n      if (c < 0x80) {\n        arr[arr.length] = hex_table[c];\n        continue;\n      }\n\n      if (c < 0x800) {\n        arr[arr.length] = hex_table[0xc0 | (c >> 6)]! + hex_table[0x80 | (c & 0x3f)];\n        continue;\n      }\n\n      if (c < 0xd800 || c >= 0xe000) {\n        arr[arr.length] =\n          hex_table[0xe0 | (c >> 12)]! + hex_table[0x80 | ((c >> 6) & 0x3f)] + hex_table[0x80 | (c & 0x3f)];\n        continue;\n      }\n\n      i += 1;\n      c = 0x10000 + (((c & 0x3ff) << 10) | (segment.charCodeAt(i) & 0x3ff));\n\n      arr[arr.length] =\n        hex_table[0xf0 | (c >> 18)]! +\n        hex_table[0x80 | ((c >> 12) & 0x3f)] +\n        hex_table[0x80 | ((c >> 6) & 0x3f)] +\n        hex_table[0x80 | (c & 0x3f)];\n    }\n\n    out += arr.join('');\n  }\n\n  return out;\n};\n\nexport function compact(value: any) {\n  const queue = [{ obj: { o: value }, prop: 'o' }];\n  const refs = [];\n\n  for (let i = 0; i < queue.length; ++i) {\n    const item = queue[i];\n    // @ts-ignore\n    const obj = item.obj[item.prop];\n\n    const keys = Object.keys(obj);\n    for (let j = 0; j < keys.length; ++j) {\n      const key = keys[j]!;\n      const val = obj[key];\n      if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {\n        queue.push({ obj: obj, prop: key });\n        refs.push(val);\n      }\n    }\n  }\n\n  compact_queue(queue);\n\n  return value;\n}\n\nexport function is_regexp(obj: any) {\n  return Object.prototype.toString.call(obj) === '[object RegExp]';\n}\n\nexport function is_buffer(obj: any) {\n  if (!obj || typeof obj !== 'object') {\n    return false;\n  }\n\n  return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));\n}\n\nexport function combine(a: any, b: any) {\n  return [].concat(a, b);\n}\n\nexport function maybe_map<T>(val: T[], fn: (v: T) => T) {\n  if (isArray(val)) {\n    const mapped = [];\n    for (let i = 0; i < val.length; i += 1) {\n      mapped.push(fn(val[i]!));\n    }\n    return mapped;\n  }\n  return fn(val);\n}\n"
  },
  {
    "path": "src/internal/request-options.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { NullableHeaders } from './headers';\n\nimport type { BodyInit } from './builtin-types';\nimport { Stream } from '../core/streaming';\nimport type { HTTPMethod, MergedRequestInit } from './types';\nimport { type HeadersLike } from './headers';\n\nexport type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };\n\nexport type RequestOptions = {\n  /**\n   * The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').\n   */\n  method?: HTTPMethod;\n\n  /**\n   * The URL path for the request.\n   *\n   * @example \"/v1/foo\"\n   */\n  path?: string;\n\n  /**\n   * Query parameters to include in the request URL.\n   */\n  query?: object | undefined | null;\n\n  /**\n   * The request body. Can be a string, JSON object, FormData, or other supported types.\n   */\n  body?: unknown;\n\n  /**\n   * HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.\n   */\n  headers?: HeadersLike;\n\n  /**\n   * The maximum number of times that the client will retry a request in case of a\n   * temporary failure, like a network error or a 5XX error from the server.\n   *\n   * @default 2\n   */\n  maxRetries?: number;\n\n  stream?: boolean | undefined;\n\n  /**\n   * The maximum amount of time (in milliseconds) that the client should wait for a response\n   * from the server before timing out a single request.\n   *\n   * @unit milliseconds\n   */\n  timeout?: number;\n\n  /**\n   * Additional `RequestInit` options to be passed to the underlying `fetch` call.\n   * These options will be merged with the client's default fetch options.\n   */\n  fetchOptions?: MergedRequestInit;\n\n  /**\n   * An AbortSignal that can be used to cancel the request.\n   */\n  signal?: AbortSignal | undefined | null;\n\n  /**\n   * A unique key for this request to enable idempotency.\n   */\n  idempotencyKey?: string;\n\n  /**\n   * Override the default base URL for this specific request.\n   */\n  defaultBaseURL?: string | undefined;\n\n  __metadata?: Record<string, unknown>;\n  __binaryResponse?: boolean | undefined;\n  __streamClass?: typeof Stream;\n  __synthesizeEventData?: boolean;\n};\n\nexport type EncodedContent = { bodyHeaders: HeadersLike; body: BodyInit };\nexport type RequestEncoder = (request: { headers: NullableHeaders; body: unknown }) => EncodedContent;\n\nexport const FallbackEncoder: RequestEncoder = ({ headers, body }) => {\n  return {\n    bodyHeaders: {\n      'content-type': 'application/json',\n    },\n    body: JSON.stringify(body),\n  };\n};\n"
  },
  {
    "path": "src/internal/shim-types.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\n/**\n * Shims for types that we can't always rely on being available globally.\n *\n * Note: these only exist at the type-level, there is no corresponding runtime\n * version for any of these symbols.\n */\n\ntype NeverToAny<T> = T extends never ? any : T;\n\n/** @ts-ignore */\ntype _DOMReadableStream<R = any> = globalThis.ReadableStream<R>;\n\n/** @ts-ignore */\ntype _NodeReadableStream<R = any> = import('stream/web').ReadableStream<R>;\n\ntype _ConditionalNodeReadableStream<R = any> =\n  typeof globalThis extends { ReadableStream: any } ? never : _NodeReadableStream<R>;\n\ntype _ReadableStream<R = any> = NeverToAny<\n  | ([0] extends [1 & _DOMReadableStream<R>] ? never : _DOMReadableStream<R>)\n  | ([0] extends [1 & _ConditionalNodeReadableStream<R>] ? never : _ConditionalNodeReadableStream<R>)\n>;\n\nexport type { _ReadableStream as ReadableStream };\n"
  },
  {
    "path": "src/internal/shims.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\n/**\n * This module provides internal shims and utility functions for environments where certain Node.js or global types may not be available.\n *\n * These are used to ensure we can provide a consistent behaviour between different JavaScript environments and good error\n * messages in cases where an environment isn't fully supported.\n */\n\nimport type { Fetch } from './builtin-types';\nimport type { ReadableStream } from './shim-types';\n\nexport function getDefaultFetch(): Fetch {\n  if (typeof fetch !== 'undefined') {\n    return fetch as any;\n  }\n\n  throw new Error(\n    '`fetch` is not defined as a global; Either pass `fetch` to the client, `new OpenAI({ fetch })` or polyfill the global, `globalThis.fetch = fetch`',\n  );\n}\n\ntype ReadableStreamArgs = ConstructorParameters<typeof ReadableStream>;\n\nexport function makeReadableStream(...args: ReadableStreamArgs): ReadableStream {\n  const ReadableStream = (globalThis as any).ReadableStream;\n  if (typeof ReadableStream === 'undefined') {\n    // Note: All of the platforms / runtimes we officially support already define\n    // `ReadableStream` as a global, so this should only ever be hit on unsupported runtimes.\n    throw new Error(\n      '`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`',\n    );\n  }\n\n  return new ReadableStream(...args);\n}\n\nexport function ReadableStreamFrom<T>(iterable: Iterable<T> | AsyncIterable<T>): ReadableStream<T> {\n  let iter: AsyncIterator<T> | Iterator<T> =\n    Symbol.asyncIterator in iterable ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();\n\n  return makeReadableStream({\n    start() {},\n    async pull(controller: any) {\n      const { done, value } = await iter.next();\n      if (done) {\n        controller.close();\n      } else {\n        controller.enqueue(value);\n      }\n    },\n    async cancel() {\n      await iter.return?.();\n    },\n  });\n}\n\n/**\n * Most browsers don't yet have async iterable support for ReadableStream,\n * and Node has a very different way of reading bytes from its \"ReadableStream\".\n *\n * This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490\n */\nexport function ReadableStreamToAsyncIterable<T>(stream: any): AsyncIterableIterator<T> {\n  if (stream[Symbol.asyncIterator]) return stream;\n\n  const reader = stream.getReader();\n  return {\n    async next() {\n      try {\n        const result = await reader.read();\n        if (result?.done) reader.releaseLock(); // release lock when stream becomes closed\n        return result;\n      } catch (e) {\n        reader.releaseLock(); // release lock when stream becomes errored\n        throw e;\n      }\n    },\n    async return() {\n      const cancelPromise = reader.cancel();\n      reader.releaseLock();\n      await cancelPromise;\n      return { done: true, value: undefined };\n    },\n    [Symbol.asyncIterator]() {\n      return this;\n    },\n  };\n}\n\n/**\n * Cancels a ReadableStream we don't need to consume.\n * See https://undici.nodejs.org/#/?id=garbage-collection\n */\nexport async function CancelReadableStream(stream: any): Promise<void> {\n  if (stream === null || typeof stream !== 'object') return;\n\n  if (stream[Symbol.asyncIterator]) {\n    await stream[Symbol.asyncIterator]().return?.();\n    return;\n  }\n\n  const reader = stream.getReader();\n  const cancelPromise = reader.cancel();\n  reader.releaseLock();\n  await cancelPromise;\n}\n"
  },
  {
    "path": "src/internal/stream-utils.ts",
    "content": "/**\n * Most browsers don't yet have async iterable support for ReadableStream,\n * and Node has a very different way of reading bytes from its \"ReadableStream\".\n *\n * This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490\n */\nexport function ReadableStreamToAsyncIterable<T>(stream: any): AsyncIterableIterator<T> {\n  if (stream[Symbol.asyncIterator]) return stream;\n\n  const reader = stream.getReader();\n  return {\n    async next() {\n      try {\n        const result = await reader.read();\n        if (result?.done) reader.releaseLock(); // release lock when stream becomes closed\n        return result;\n      } catch (e) {\n        reader.releaseLock(); // release lock when stream becomes errored\n        throw e;\n      }\n    },\n    async return() {\n      const cancelPromise = reader.cancel();\n      reader.releaseLock();\n      await cancelPromise;\n      return { done: true, value: undefined };\n    },\n    [Symbol.asyncIterator]() {\n      return this;\n    },\n  };\n}\n"
  },
  {
    "path": "src/internal/to-file.ts",
    "content": "import { BlobPart, getName, makeFile, isAsyncIterable } from './uploads';\nimport type { FilePropertyBag } from './builtin-types';\nimport { checkFileSupport } from './uploads';\n\ntype BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;\n\n/**\n * Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.\n * Don't add arrayBuffer here, node-fetch doesn't have it\n */\ninterface BlobLike {\n  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */\n  readonly size: number;\n  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */\n  readonly type: string;\n  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */\n  text(): Promise<string>;\n  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */\n  slice(start?: number, end?: number): BlobLike;\n}\n\n/**\n * This check adds the arrayBuffer() method type because it is available and used at runtime\n */\nconst isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>\n  value != null &&\n  typeof value === 'object' &&\n  typeof value.size === 'number' &&\n  typeof value.type === 'string' &&\n  typeof value.text === 'function' &&\n  typeof value.slice === 'function' &&\n  typeof value.arrayBuffer === 'function';\n\n/**\n * Intended to match DOM File, node:buffer File, undici File, etc.\n */\ninterface FileLike extends BlobLike {\n  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */\n  readonly lastModified: number;\n  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */\n  readonly name?: string | undefined;\n}\n\n/**\n * This check adds the arrayBuffer() method type because it is available and used at runtime\n */\nconst isFileLike = (value: any): value is FileLike & { arrayBuffer(): Promise<ArrayBuffer> } =>\n  value != null &&\n  typeof value === 'object' &&\n  typeof value.name === 'string' &&\n  typeof value.lastModified === 'number' &&\n  isBlobLike(value);\n\n/**\n * Intended to match DOM Response, node-fetch Response, undici Response, etc.\n */\nexport interface ResponseLike {\n  url: string;\n  blob(): Promise<BlobLike>;\n}\n\nconst isResponseLike = (value: any): value is ResponseLike =>\n  value != null &&\n  typeof value === 'object' &&\n  typeof value.url === 'string' &&\n  typeof value.blob === 'function';\n\nexport type ToFileInput =\n  | FileLike\n  | ResponseLike\n  | Exclude<BlobLikePart, string>\n  | AsyncIterable<BlobLikePart>;\n\n/**\n * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats\n * @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts\n * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible\n * @param {Object=} options additional properties\n * @param {string=} options.type the MIME type of the content\n * @param {number=} options.lastModified the last modified timestamp\n * @returns a {@link File} with the given properties\n */\nexport async function toFile(\n  value: ToFileInput | PromiseLike<ToFileInput>,\n  name?: string | null | undefined,\n  options?: FilePropertyBag | undefined,\n): Promise<File> {\n  checkFileSupport();\n\n  // If it's a promise, resolve it.\n  value = await value;\n\n  // If we've been given a `File` we don't need to do anything\n  if (isFileLike(value)) {\n    if (value instanceof File) {\n      return value;\n    }\n    return makeFile([await value.arrayBuffer()], value.name);\n  }\n\n  if (isResponseLike(value)) {\n    const blob = await value.blob();\n    name ||= new URL(value.url).pathname.split(/[\\\\/]/).pop();\n\n    return makeFile(await getBytes(blob), name, options);\n  }\n\n  const parts = await getBytes(value);\n\n  name ||= getName(value);\n\n  if (!options?.type) {\n    const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);\n    if (typeof type === 'string') {\n      options = { ...options, type };\n    }\n  }\n\n  return makeFile(parts, name, options);\n}\n\nasync function getBytes(value: BlobLikePart | AsyncIterable<BlobLikePart>): Promise<Array<BlobPart>> {\n  let parts: Array<BlobPart> = [];\n  if (\n    typeof value === 'string' ||\n    ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.\n    value instanceof ArrayBuffer\n  ) {\n    parts.push(value);\n  } else if (isBlobLike(value)) {\n    parts.push(value instanceof Blob ? value : await value.arrayBuffer());\n  } else if (\n    isAsyncIterable(value) // includes Readable, ReadableStream, etc.\n  ) {\n    for await (const chunk of value) {\n      parts.push(...(await getBytes(chunk as BlobLikePart))); // TODO, consider validating?\n    }\n  } else {\n    const constructor = value?.constructor?.name;\n    throw new Error(\n      `Unexpected data type: ${typeof value}${\n        constructor ? `; constructor: ${constructor}` : ''\n      }${propsForError(value)}`,\n    );\n  }\n\n  return parts;\n}\n\nfunction propsForError(value: unknown): string {\n  if (typeof value !== 'object' || value === null) return '';\n  const props = Object.getOwnPropertyNames(value);\n  return `; props: [${props.map((p) => `\"${p}\"`).join(', ')}]`;\n}\n"
  },
  {
    "path": "src/internal/types.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport type PromiseOrValue<T> = T | Promise<T>;\nexport type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';\n\nexport type KeysEnum<T> = { [P in keyof Required<T>]: true };\n\nexport type FinalizedRequestInit = RequestInit & { headers: Headers };\n\ntype NotAny<T> = [0] extends [1 & T] ? never : T;\n\n/**\n * Some environments overload the global fetch function, and Parameters<T> only gets the last signature.\n */\ntype OverloadedParameters<T> =\n  T extends (\n    {\n      (...args: infer A): unknown;\n      (...args: infer B): unknown;\n      (...args: infer C): unknown;\n      (...args: infer D): unknown;\n    }\n  ) ?\n    A | B | C | D\n  : T extends (\n    {\n      (...args: infer A): unknown;\n      (...args: infer B): unknown;\n      (...args: infer C): unknown;\n    }\n  ) ?\n    A | B | C\n  : T extends (\n    {\n      (...args: infer A): unknown;\n      (...args: infer B): unknown;\n    }\n  ) ?\n    A | B\n  : T extends (...args: infer A) => unknown ? A\n  : never;\n\n/* eslint-disable */\n/**\n * These imports attempt to get types from a parent package's dependencies.\n * Unresolved bare specifiers can trigger [automatic type acquisition][1] in some projects, which\n * would cause typescript to show types not present at runtime. To avoid this, we import\n * directly from parent node_modules folders.\n *\n * We need to check multiple levels because we don't know what directory structure we'll be in.\n * For example, pnpm generates directories like this:\n * ```\n * node_modules\n * ├── .pnpm\n * │   └── pkg@1.0.0\n * │       └── node_modules\n * │           └── pkg\n * │               └── internal\n * │                   └── types.d.ts\n * ├── pkg -> .pnpm/pkg@1.0.0/node_modules/pkg\n * └── undici\n * ```\n *\n * [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition\n */\n/** @ts-ignore For users with \\@types/node */\ntype UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit>;\n/** @ts-ignore For users with undici */\ntype UndiciRequestInit = NotAny<import('../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici/index.d.ts').RequestInit>;\n/** @ts-ignore For users with \\@types/bun */\ntype BunRequestInit = globalThis.FetchRequestInit;\n/** @ts-ignore For users with node-fetch@2 */\ntype NodeFetch2RequestInit = NotAny<import('../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit>;\n/** @ts-ignore For users with node-fetch@3, doesn't need file extension because types are at ./@types/index.d.ts */\ntype NodeFetch3RequestInit =  NotAny<import('../node_modules/node-fetch').RequestInit> | NotAny<import('../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/node-fetch').RequestInit>;\n/** @ts-ignore For users who use Deno */\ntype FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;\n/* eslint-enable */\n\ntype RequestInits =\n  | NotAny<UndiciTypesRequestInit>\n  | NotAny<UndiciRequestInit>\n  | NotAny<BunRequestInit>\n  | NotAny<NodeFetch2RequestInit>\n  | NotAny<NodeFetch3RequestInit>\n  | NotAny<RequestInit>\n  | NotAny<FetchRequestInit>;\n\n/**\n * This type contains `RequestInit` options that may be available on the current runtime,\n * including per-platform extensions like `dispatcher`, `agent`, `client`, etc.\n */\nexport type MergedRequestInit = RequestInits &\n  /** We don't include these in the types as they'll be overridden for every request. */\n  Partial<Record<'body' | 'headers' | 'method' | 'signal', never>>;\n"
  },
  {
    "path": "src/internal/uploads.ts",
    "content": "import { type RequestOptions } from './request-options';\nimport type { FilePropertyBag, Fetch } from './builtin-types';\nimport type { OpenAI } from '../client';\nimport { ReadableStreamFrom } from './shims';\n\nexport type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;\ntype FsReadStream = AsyncIterable<Uint8Array> & { path: string | { toString(): string } };\n\n// https://github.com/oven-sh/bun/issues/5980\ninterface BunFile extends Blob {\n  readonly name?: string | undefined;\n}\n\nexport const checkFileSupport = () => {\n  if (typeof File === 'undefined') {\n    const { process } = globalThis as any;\n    const isOldNode =\n      typeof process?.versions?.node === 'string' && parseInt(process.versions.node.split('.')) < 20;\n    throw new Error(\n      '`File` is not defined as a global, which is required for file uploads.' +\n        (isOldNode ?\n          \" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`.\"\n        : ''),\n    );\n  }\n};\n\n/**\n * Typically, this is a native \"File\" class.\n *\n * We provide the {@link toFile} utility to convert a variety of objects\n * into the File class.\n *\n * For convenience, you can also pass a fetch Response, or in Node,\n * the result of fs.createReadStream().\n */\nexport type Uploadable = File | Response | FsReadStream | BunFile;\n\n/**\n * Construct a `File` instance. This is used to ensure a helpful error is thrown\n * for environments that don't define a global `File` yet.\n */\nexport function makeFile(\n  fileBits: BlobPart[],\n  fileName: string | undefined,\n  options?: FilePropertyBag,\n): File {\n  checkFileSupport();\n  return new File(fileBits as any, fileName ?? 'unknown_file', options);\n}\n\nexport function getName(value: any): string | undefined {\n  return (\n    (\n      (typeof value === 'object' &&\n        value !== null &&\n        (('name' in value && value.name && String(value.name)) ||\n          ('url' in value && value.url && String(value.url)) ||\n          ('filename' in value && value.filename && String(value.filename)) ||\n          ('path' in value && value.path && String(value.path)))) ||\n      ''\n    )\n      .split(/[\\\\/]/)\n      .pop() || undefined\n  );\n}\n\nexport const isAsyncIterable = (value: any): value is AsyncIterable<any> =>\n  value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';\n\n/**\n * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.\n * Otherwise returns the request as is.\n */\nexport const maybeMultipartFormRequestOptions = async (\n  opts: RequestOptions,\n  fetch: OpenAI | Fetch,\n): Promise<RequestOptions> => {\n  if (!hasUploadableValue(opts.body)) return opts;\n\n  return { ...opts, body: await createForm(opts.body, fetch) };\n};\n\ntype MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & { body: unknown };\n\nexport const multipartFormRequestOptions = async (\n  opts: MultipartFormRequestOptions,\n  fetch: OpenAI | Fetch,\n): Promise<RequestOptions> => {\n  return { ...opts, body: await createForm(opts.body, fetch) };\n};\n\nconst supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();\n\n/**\n * node-fetch doesn't support the global FormData object in recent node versions. Instead of sending\n * properly-encoded form data, it just stringifies the object, resulting in a request body of \"[object FormData]\".\n * This function detects if the fetch function provided supports the global FormData object to avoid\n * confusing error messages later on.\n */\nfunction supportsFormData(fetchObject: OpenAI | Fetch): Promise<boolean> {\n  const fetch: Fetch = typeof fetchObject === 'function' ? fetchObject : (fetchObject as any).fetch;\n  const cached = supportsFormDataMap.get(fetch);\n  if (cached) return cached;\n  const promise = (async () => {\n    try {\n      const FetchResponse = (\n        'Response' in fetch ?\n          fetch.Response\n        : (await fetch('data:,')).constructor) as typeof Response;\n      const data = new FormData();\n      if (data.toString() === (await new FetchResponse(data).text())) {\n        return false;\n      }\n      return true;\n    } catch {\n      // avoid false negatives\n      return true;\n    }\n  })();\n  supportsFormDataMap.set(fetch, promise);\n  return promise;\n}\n\nexport const createForm = async <T = Record<string, unknown>>(\n  body: T | undefined,\n  fetch: OpenAI | Fetch,\n): Promise<FormData> => {\n  if (!(await supportsFormData(fetch))) {\n    throw new TypeError(\n      'The provided fetch function does not support file uploads with the current global FormData class.',\n    );\n  }\n  const form = new FormData();\n  await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));\n  return form;\n};\n\n// We check for Blob not File because Bun.File doesn't inherit from File,\n// but they both inherit from Blob and have a `name` property at runtime.\nconst isNamedBlob = (value: unknown) => value instanceof Blob && 'name' in value;\n\nconst isUploadable = (value: unknown) =>\n  typeof value === 'object' &&\n  value !== null &&\n  (value instanceof Response || isAsyncIterable(value) || isNamedBlob(value));\n\nconst hasUploadableValue = (value: unknown): boolean => {\n  if (isUploadable(value)) return true;\n  if (Array.isArray(value)) return value.some(hasUploadableValue);\n  if (value && typeof value === 'object') {\n    for (const k in value) {\n      if (hasUploadableValue((value as any)[k])) return true;\n    }\n  }\n  return false;\n};\n\nconst addFormValue = async (form: FormData, key: string, value: unknown): Promise<void> => {\n  if (value === undefined) return;\n  if (value == null) {\n    throw new TypeError(\n      `Received null for \"${key}\"; to pass null in FormData, you must use the string 'null'`,\n    );\n  }\n\n  // TODO: make nested formats configurable\n  if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n    form.append(key, String(value));\n  } else if (value instanceof Response) {\n    form.append(key, makeFile([await value.blob()], getName(value)));\n  } else if (isAsyncIterable(value)) {\n    form.append(key, makeFile([await new Response(ReadableStreamFrom(value)).blob()], getName(value)));\n  } else if (isNamedBlob(value)) {\n    form.append(key, value, getName(value));\n  } else if (Array.isArray(value)) {\n    await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));\n  } else if (typeof value === 'object') {\n    await Promise.all(\n      Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)),\n    );\n  } else {\n    throw new TypeError(\n      `Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`,\n    );\n  }\n};\n"
  },
  {
    "path": "src/internal/utils/base64.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { OpenAIError } from '../../core/error';\nimport { encodeUTF8 } from './bytes';\n\nexport const toBase64 = (data: string | Uint8Array | null | undefined): string => {\n  if (!data) return '';\n\n  if (typeof (globalThis as any).Buffer !== 'undefined') {\n    return (globalThis as any).Buffer.from(data).toString('base64');\n  }\n\n  if (typeof data === 'string') {\n    data = encodeUTF8(data);\n  }\n\n  if (typeof btoa !== 'undefined') {\n    return btoa(String.fromCharCode.apply(null, data as any));\n  }\n\n  throw new OpenAIError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');\n};\n\nexport const fromBase64 = (str: string): Uint8Array => {\n  if (typeof (globalThis as any).Buffer !== 'undefined') {\n    const buf = (globalThis as any).Buffer.from(str, 'base64');\n    return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);\n  }\n\n  if (typeof atob !== 'undefined') {\n    const bstr = atob(str);\n    const buf = new Uint8Array(bstr.length);\n    for (let i = 0; i < bstr.length; i++) {\n      buf[i] = bstr.charCodeAt(i);\n    }\n    return buf;\n  }\n\n  throw new OpenAIError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');\n};\n\n/**\n * Converts a Base64 encoded string to a Float32Array.\n * @param base64Str - The Base64 encoded string.\n * @returns An Array of numbers interpreted as Float32 values.\n */\nexport const toFloat32Array = (base64Str: string): Array<number> => {\n  if (typeof Buffer !== 'undefined') {\n    // for Node.js environment\n    const buf = Buffer.from(base64Str, 'base64');\n    return Array.from(\n      new Float32Array(buf.buffer, buf.byteOffset, buf.length / Float32Array.BYTES_PER_ELEMENT),\n    );\n  } else {\n    // for legacy web platform APIs\n    const binaryStr = atob(base64Str);\n    const len = binaryStr.length;\n    const bytes = new Uint8Array(len);\n    for (let i = 0; i < len; i++) {\n      bytes[i] = binaryStr.charCodeAt(i);\n    }\n    return Array.from(new Float32Array(bytes.buffer));\n  }\n};\n"
  },
  {
    "path": "src/internal/utils/bytes.ts",
    "content": "export function concatBytes(buffers: Uint8Array[]): Uint8Array {\n  let length = 0;\n  for (const buffer of buffers) {\n    length += buffer.length;\n  }\n  const output = new Uint8Array(length);\n  let index = 0;\n  for (const buffer of buffers) {\n    output.set(buffer, index);\n    index += buffer.length;\n  }\n\n  return output;\n}\n\nlet encodeUTF8_: (str: string) => Uint8Array;\nexport function encodeUTF8(str: string) {\n  let encoder;\n  return (\n    encodeUTF8_ ??\n    ((encoder = new (globalThis as any).TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder)))\n  )(str);\n}\n\nlet decodeUTF8_: (bytes: Uint8Array) => string;\nexport function decodeUTF8(bytes: Uint8Array) {\n  let decoder;\n  return (\n    decodeUTF8_ ??\n    ((decoder = new (globalThis as any).TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder)))\n  )(bytes);\n}\n"
  },
  {
    "path": "src/internal/utils/env.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\n/**\n * Read an environment variable.\n *\n * Trims beginning and trailing whitespace.\n *\n * Will return undefined if the environment variable doesn't exist or cannot be accessed.\n */\nexport const readEnv = (env: string): string | undefined => {\n  if (typeof (globalThis as any).process !== 'undefined') {\n    return (globalThis as any).process.env?.[env]?.trim() ?? undefined;\n  }\n  if (typeof (globalThis as any).Deno !== 'undefined') {\n    return (globalThis as any).Deno.env?.get?.(env)?.trim();\n  }\n  return undefined;\n};\n"
  },
  {
    "path": "src/internal/utils/log.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { hasOwn } from './values';\nimport { type OpenAI } from '../../client';\nimport { RequestOptions } from '../request-options';\n\ntype LogFn = (message: string, ...rest: unknown[]) => void;\nexport type Logger = {\n  error: LogFn;\n  warn: LogFn;\n  info: LogFn;\n  debug: LogFn;\n};\nexport type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug';\n\nconst levelNumbers = {\n  off: 0,\n  error: 200,\n  warn: 300,\n  info: 400,\n  debug: 500,\n};\n\nexport const parseLogLevel = (\n  maybeLevel: string | undefined,\n  sourceName: string,\n  client: OpenAI,\n): LogLevel | undefined => {\n  if (!maybeLevel) {\n    return undefined;\n  }\n  if (hasOwn(levelNumbers, maybeLevel)) {\n    return maybeLevel;\n  }\n  loggerFor(client).warn(\n    `${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify(\n      Object.keys(levelNumbers),\n    )}`,\n  );\n  return undefined;\n};\n\nfunction noop() {}\n\nfunction makeLogFn(fnLevel: keyof Logger, logger: Logger | undefined, logLevel: LogLevel) {\n  if (!logger || levelNumbers[fnLevel] > levelNumbers[logLevel]) {\n    return noop;\n  } else {\n    // Don't wrap logger functions, we want the stacktrace intact!\n    return logger[fnLevel].bind(logger);\n  }\n}\n\nconst noopLogger = {\n  error: noop,\n  warn: noop,\n  info: noop,\n  debug: noop,\n};\n\nlet cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();\n\nexport function loggerFor(client: OpenAI): Logger {\n  const logger = client.logger;\n  const logLevel = client.logLevel ?? 'off';\n  if (!logger) {\n    return noopLogger;\n  }\n\n  const cachedLogger = cachedLoggers.get(logger);\n  if (cachedLogger && cachedLogger[0] === logLevel) {\n    return cachedLogger[1];\n  }\n\n  const levelLogger = {\n    error: makeLogFn('error', logger, logLevel),\n    warn: makeLogFn('warn', logger, logLevel),\n    info: makeLogFn('info', logger, logLevel),\n    debug: makeLogFn('debug', logger, logLevel),\n  };\n\n  cachedLoggers.set(logger, [logLevel, levelLogger]);\n\n  return levelLogger;\n}\n\nexport const formatRequestDetails = (details: {\n  options?: RequestOptions | undefined;\n  headers?: Headers | Record<string, string> | undefined;\n  retryOfRequestLogID?: string | undefined;\n  retryOf?: string | undefined;\n  url?: string | undefined;\n  status?: number | undefined;\n  method?: string | undefined;\n  durationMs?: number | undefined;\n  message?: unknown;\n  body?: unknown;\n}) => {\n  if (details.options) {\n    details.options = { ...details.options };\n    delete details.options['headers']; // redundant + leaks internals\n  }\n  if (details.headers) {\n    details.headers = Object.fromEntries(\n      (details.headers instanceof Headers ? [...details.headers] : Object.entries(details.headers)).map(\n        ([name, value]) => [\n          name,\n          (\n            name.toLowerCase() === 'authorization' ||\n            name.toLowerCase() === 'cookie' ||\n            name.toLowerCase() === 'set-cookie'\n          ) ?\n            '***'\n          : value,\n        ],\n      ),\n    );\n  }\n  if ('retryOfRequestLogID' in details) {\n    if (details.retryOfRequestLogID) {\n      details.retryOf = details.retryOfRequestLogID;\n    }\n    delete details.retryOfRequestLogID;\n  }\n  return details;\n};\n"
  },
  {
    "path": "src/internal/utils/path.ts",
    "content": "import { OpenAIError } from '../../core/error';\n\n/**\n * Percent-encode everything that isn't safe to have in a path without encoding safe chars.\n *\n * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:\n * > unreserved  = ALPHA / DIGIT / \"-\" / \".\" / \"_\" / \"~\"\n * > sub-delims  = \"!\" / \"$\" / \"&\" / \"'\" / \"(\" / \")\" / \"*\" / \"+\" / \",\" / \";\" / \"=\"\n * > pchar       = unreserved / pct-encoded / sub-delims / \":\" / \"@\"\n */\nexport function encodeURIPath(str: string) {\n  return str.replace(/[^A-Za-z0-9\\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);\n}\n\nconst EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));\n\nexport const createPathTagFunction = (pathEncoder = encodeURIPath) =>\n  function path(statics: readonly string[], ...params: readonly unknown[]): string {\n    // If there are no params, no processing is needed.\n    if (statics.length === 1) return statics[0]!;\n\n    let postPath = false;\n    const invalidSegments = [];\n    const path = statics.reduce((previousValue, currentValue, index) => {\n      if (/[?#]/.test(currentValue)) {\n        postPath = true;\n      }\n      const value = params[index];\n      let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);\n      if (\n        index !== params.length &&\n        (value == null ||\n          (typeof value === 'object' &&\n            // handle values from other realms\n            value.toString ===\n              Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)\n                ?.toString))\n      ) {\n        encoded = value + '';\n        invalidSegments.push({\n          start: previousValue.length + currentValue.length,\n          length: encoded.length,\n          error: `Value of type ${Object.prototype.toString\n            .call(value)\n            .slice(8, -1)} is not a valid path parameter`,\n        });\n      }\n      return previousValue + currentValue + (index === params.length ? '' : encoded);\n    }, '');\n\n    const pathOnly = path.split(/[?#]/, 1)[0]!;\n    const invalidSegmentPattern = /(?<=^|\\/)(?:\\.|%2e){1,2}(?=\\/|$)/gi;\n    let match;\n\n    // Find all invalid segments\n    while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {\n      invalidSegments.push({\n        start: match.index,\n        length: match[0].length,\n        error: `Value \"${match[0]}\" can\\'t be safely passed as a path parameter`,\n      });\n    }\n\n    invalidSegments.sort((a, b) => a.start - b.start);\n\n    if (invalidSegments.length > 0) {\n      let lastEnd = 0;\n      const underline = invalidSegments.reduce((acc, segment) => {\n        const spaces = ' '.repeat(segment.start - lastEnd);\n        const arrows = '^'.repeat(segment.length);\n        lastEnd = segment.start + segment.length;\n        return acc + spaces + arrows;\n      }, '');\n\n      throw new OpenAIError(\n        `Path parameters result in path with invalid segments:\\n${invalidSegments\n          .map((e) => e.error)\n          .join('\\n')}\\n${path}\\n${underline}`,\n      );\n    }\n\n    return path;\n  };\n\n/**\n * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.\n */\nexport const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);\n"
  },
  {
    "path": "src/internal/utils/query.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport * as qs from '../qs/stringify';\n\nexport function stringifyQuery(query: object | Record<string, unknown>) {\n  return qs.stringify(query, { arrayFormat: 'brackets' });\n}\n"
  },
  {
    "path": "src/internal/utils/sleep.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));\n"
  },
  {
    "path": "src/internal/utils/uuid.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\n/**\n * https://stackoverflow.com/a/2117523\n */\nexport let uuid4 = function () {\n  const { crypto } = globalThis as any;\n  if (crypto?.randomUUID) {\n    uuid4 = crypto.randomUUID.bind(crypto);\n    return crypto.randomUUID();\n  }\n  const u8 = new Uint8Array(1);\n  const randomByte = crypto ? () => crypto.getRandomValues(u8)[0]! : () => (Math.random() * 0xff) & 0xff;\n  return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) =>\n    (+c ^ (randomByte() & (15 >> (+c / 4)))).toString(16),\n  );\n};\n"
  },
  {
    "path": "src/internal/utils/values.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { OpenAIError } from '../../core/error';\n\n// https://url.spec.whatwg.org/#url-scheme-string\nconst startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;\n\nexport const isAbsoluteURL = (url: string): boolean => {\n  return startsWithSchemeRegexp.test(url);\n};\n\nexport let isArray = (val: unknown): val is unknown[] => ((isArray = Array.isArray), isArray(val));\nexport let isReadonlyArray = isArray as (val: unknown) => val is readonly unknown[];\n\n/** Returns an object if the given value isn't an object, otherwise returns as-is */\nexport function maybeObj(x: unknown): object {\n  if (typeof x !== 'object') {\n    return {};\n  }\n\n  return x ?? {};\n}\n\n// https://stackoverflow.com/a/34491287\nexport function isEmptyObj(obj: Object | null | undefined): boolean {\n  if (!obj) return true;\n  for (const _k in obj) return false;\n  return true;\n}\n\n// https://eslint.org/docs/latest/rules/no-prototype-builtins\nexport function hasOwn<T extends object = object>(obj: T, key: PropertyKey): key is keyof T {\n  return Object.prototype.hasOwnProperty.call(obj, key);\n}\n\nexport function isObj(obj: unknown): obj is Record<string, unknown> {\n  return obj != null && typeof obj === 'object' && !Array.isArray(obj);\n}\n\nexport const ensurePresent = <T>(value: T | null | undefined): T => {\n  if (value == null) {\n    throw new OpenAIError(`Expected a value to be given but received ${value} instead.`);\n  }\n\n  return value;\n};\n\nexport const validatePositiveInteger = (name: string, n: unknown): number => {\n  if (typeof n !== 'number' || !Number.isInteger(n)) {\n    throw new OpenAIError(`${name} must be an integer`);\n  }\n  if (n < 0) {\n    throw new OpenAIError(`${name} must be a positive integer`);\n  }\n  return n;\n};\n\nexport const coerceInteger = (value: unknown): number => {\n  if (typeof value === 'number') return Math.round(value);\n  if (typeof value === 'string') return parseInt(value, 10);\n\n  throw new OpenAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`);\n};\n\nexport const coerceFloat = (value: unknown): number => {\n  if (typeof value === 'number') return value;\n  if (typeof value === 'string') return parseFloat(value);\n\n  throw new OpenAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`);\n};\n\nexport const coerceBoolean = (value: unknown): boolean => {\n  if (typeof value === 'boolean') return value;\n  if (typeof value === 'string') return value === 'true';\n  return Boolean(value);\n};\n\nexport const maybeCoerceInteger = (value: unknown): number | undefined => {\n  if (value == null) {\n    return undefined;\n  }\n  return coerceInteger(value);\n};\n\nexport const maybeCoerceFloat = (value: unknown): number | undefined => {\n  if (value == null) {\n    return undefined;\n  }\n  return coerceFloat(value);\n};\n\nexport const maybeCoerceBoolean = (value: unknown): boolean | undefined => {\n  if (value == null) {\n    return undefined;\n  }\n  return coerceBoolean(value);\n};\n\nexport const safeJSON = (text: string) => {\n  try {\n    return JSON.parse(text);\n  } catch (err) {\n    return undefined;\n  }\n};\n"
  },
  {
    "path": "src/internal/utils.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './utils/values';\nexport * from './utils/base64';\nexport * from './utils/env';\nexport * from './utils/log';\nexport * from './utils/uuid';\nexport * from './utils/sleep';\nexport * from './utils/query';\n"
  },
  {
    "path": "src/lib/.keep",
    "content": "File generated from our OpenAPI spec by Stainless.\n\nThis directory can be used to store custom files to expand the SDK.\nIt is ignored by Stainless code generation and its content (other than this keep file) won't be touched.\n"
  },
  {
    "path": "src/lib/AbstractChatCompletionRunner.ts",
    "content": "import { OpenAIError } from '../error';\nimport type OpenAI from '../index';\nimport type { RequestOptions } from '../internal/request-options';\nimport { isAutoParsableTool, parseChatCompletion } from '../lib/parser';\nimport type {\n  ChatCompletion,\n  ChatCompletionCreateParams,\n  ChatCompletionMessage,\n  ChatCompletionMessageFunctionToolCall,\n  ChatCompletionMessageParam,\n  ChatCompletionTool,\n  ParsedChatCompletion,\n} from '../resources/chat/completions';\nimport type { CompletionUsage } from '../resources/completions';\nimport type { ChatCompletionToolRunnerParams } from './ChatCompletionRunner';\nimport type { ChatCompletionStreamingToolRunnerParams } from './ChatCompletionStreamingRunner';\nimport { isAssistantMessage, isToolMessage } from './chatCompletionUtils';\nimport { BaseEvents, EventStream } from './EventStream';\nimport {\n  isRunnableFunctionWithParse,\n  type BaseFunctionsArgs,\n  type RunnableFunction,\n  type RunnableToolFunction,\n} from './RunnableFunction';\n\nconst DEFAULT_MAX_CHAT_COMPLETIONS = 10;\nexport interface RunnerOptions extends RequestOptions {\n  /** How many requests to make before canceling. Default 10. */\n  maxChatCompletions?: number;\n}\n\nexport class AbstractChatCompletionRunner<\n  EventTypes extends AbstractChatCompletionRunnerEvents,\n  ParsedT,\n> extends EventStream<EventTypes> {\n  protected _chatCompletions: ParsedChatCompletion<ParsedT>[] = [];\n  messages: ChatCompletionMessageParam[] = [];\n\n  protected _addChatCompletion(\n    this: AbstractChatCompletionRunner<AbstractChatCompletionRunnerEvents, ParsedT>,\n    chatCompletion: ParsedChatCompletion<ParsedT>,\n  ): ParsedChatCompletion<ParsedT> {\n    this._chatCompletions.push(chatCompletion);\n    this._emit('chatCompletion', chatCompletion);\n    const message = chatCompletion.choices[0]?.message;\n    if (message) this._addMessage(message as ChatCompletionMessageParam);\n    return chatCompletion;\n  }\n\n  protected _addMessage(\n    this: AbstractChatCompletionRunner<AbstractChatCompletionRunnerEvents, ParsedT>,\n    message: ChatCompletionMessageParam,\n    emit = true,\n  ) {\n    if (!('content' in message)) message.content = null;\n\n    this.messages.push(message);\n\n    if (emit) {\n      this._emit('message', message);\n      if (isToolMessage(message) && message.content) {\n        // Note, this assumes that {role: 'tool', content: …} is always the result of a call of tool of type=function.\n        this._emit('functionToolCallResult', message.content as string);\n      } else if (isAssistantMessage(message) && message.tool_calls) {\n        for (const tool_call of message.tool_calls) {\n          if (tool_call.type === 'function') {\n            this._emit('functionToolCall', tool_call.function);\n          }\n        }\n      }\n    }\n  }\n\n  /**\n   * @returns a promise that resolves with the final ChatCompletion, or rejects\n   * if an error occurred or the stream ended prematurely without producing a ChatCompletion.\n   */\n  async finalChatCompletion(): Promise<ParsedChatCompletion<ParsedT>> {\n    await this.done();\n    const completion = this._chatCompletions[this._chatCompletions.length - 1];\n    if (!completion) throw new OpenAIError('stream ended without producing a ChatCompletion');\n    return completion;\n  }\n\n  #getFinalContent(): string | null {\n    return this.#getFinalMessage().content ?? null;\n  }\n\n  /**\n   * @returns a promise that resolves with the content of the final ChatCompletionMessage, or rejects\n   * if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage.\n   */\n  async finalContent(): Promise<string | null> {\n    await this.done();\n    return this.#getFinalContent();\n  }\n\n  #getFinalMessage(): ChatCompletionMessage {\n    let i = this.messages.length;\n    while (i-- > 0) {\n      const message = this.messages[i];\n      if (isAssistantMessage(message)) {\n        // TODO: support audio here\n        const ret: Omit<ChatCompletionMessage, 'audio'> = {\n          ...message,\n          content: (message as ChatCompletionMessage).content ?? null,\n          refusal: (message as ChatCompletionMessage).refusal ?? null,\n        };\n        return ret;\n      }\n    }\n    throw new OpenAIError('stream ended without producing a ChatCompletionMessage with role=assistant');\n  }\n\n  /**\n   * @returns a promise that resolves with the the final assistant ChatCompletionMessage response,\n   * or rejects if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage.\n   */\n  async finalMessage(): Promise<ChatCompletionMessage> {\n    await this.done();\n    return this.#getFinalMessage();\n  }\n\n  #getFinalFunctionToolCall(): ChatCompletionMessageFunctionToolCall.Function | undefined {\n    for (let i = this.messages.length - 1; i >= 0; i--) {\n      const message = this.messages[i];\n      if (isAssistantMessage(message) && message?.tool_calls?.length) {\n        return message.tool_calls.filter((x) => x.type === 'function').at(-1)?.function;\n      }\n    }\n\n    return;\n  }\n\n  /**\n   * @returns a promise that resolves with the content of the final FunctionCall, or rejects\n   * if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage.\n   */\n  async finalFunctionToolCall(): Promise<ChatCompletionMessageFunctionToolCall.Function | undefined> {\n    await this.done();\n    return this.#getFinalFunctionToolCall();\n  }\n\n  #getFinalFunctionToolCallResult(): string | undefined {\n    for (let i = this.messages.length - 1; i >= 0; i--) {\n      const message = this.messages[i];\n      if (\n        isToolMessage(message) &&\n        message.content != null &&\n        typeof message.content === 'string' &&\n        this.messages.some(\n          (x) =>\n            x.role === 'assistant' &&\n            x.tool_calls?.some((y) => y.type === 'function' && y.id === message.tool_call_id),\n        )\n      ) {\n        return message.content;\n      }\n    }\n\n    return;\n  }\n\n  async finalFunctionToolCallResult(): Promise<string | undefined> {\n    await this.done();\n    return this.#getFinalFunctionToolCallResult();\n  }\n\n  #calculateTotalUsage(): CompletionUsage {\n    const total: CompletionUsage = {\n      completion_tokens: 0,\n      prompt_tokens: 0,\n      total_tokens: 0,\n    };\n    for (const { usage } of this._chatCompletions) {\n      if (usage) {\n        total.completion_tokens += usage.completion_tokens;\n        total.prompt_tokens += usage.prompt_tokens;\n        total.total_tokens += usage.total_tokens;\n      }\n    }\n    return total;\n  }\n\n  async totalUsage(): Promise<CompletionUsage> {\n    await this.done();\n    return this.#calculateTotalUsage();\n  }\n\n  allChatCompletions(): ChatCompletion[] {\n    return [...this._chatCompletions];\n  }\n\n  protected override _emitFinal(\n    this: AbstractChatCompletionRunner<AbstractChatCompletionRunnerEvents, ParsedT>,\n  ) {\n    const completion = this._chatCompletions[this._chatCompletions.length - 1];\n    if (completion) this._emit('finalChatCompletion', completion);\n    const finalMessage = this.#getFinalMessage();\n    if (finalMessage) this._emit('finalMessage', finalMessage);\n    const finalContent = this.#getFinalContent();\n    if (finalContent) this._emit('finalContent', finalContent);\n\n    const finalFunctionCall = this.#getFinalFunctionToolCall();\n    if (finalFunctionCall) this._emit('finalFunctionToolCall', finalFunctionCall);\n\n    const finalFunctionCallResult = this.#getFinalFunctionToolCallResult();\n    if (finalFunctionCallResult != null) this._emit('finalFunctionToolCallResult', finalFunctionCallResult);\n\n    if (this._chatCompletions.some((c) => c.usage)) {\n      this._emit('totalUsage', this.#calculateTotalUsage());\n    }\n  }\n\n  #validateParams(params: ChatCompletionCreateParams): void {\n    if (params.n != null && params.n > 1) {\n      throw new OpenAIError(\n        'ChatCompletion convenience helpers only support n=1 at this time. To use n>1, please use chat.completions.create() directly.',\n      );\n    }\n  }\n\n  protected async _createChatCompletion(\n    client: OpenAI,\n    params: ChatCompletionCreateParams,\n    options?: RequestOptions,\n  ): Promise<ParsedChatCompletion<ParsedT>> {\n    const signal = options?.signal;\n    if (signal) {\n      if (signal.aborted) this.controller.abort();\n      signal.addEventListener('abort', () => this.controller.abort());\n    }\n    this.#validateParams(params);\n\n    const chatCompletion = await client.chat.completions.create(\n      { ...params, stream: false },\n      { ...options, signal: this.controller.signal },\n    );\n    this._connected();\n    return this._addChatCompletion(parseChatCompletion(chatCompletion, params));\n  }\n\n  protected async _runChatCompletion(\n    client: OpenAI,\n    params: ChatCompletionCreateParams,\n    options?: RequestOptions,\n  ): Promise<ChatCompletion> {\n    for (const message of params.messages) {\n      this._addMessage(message, false);\n    }\n    return await this._createChatCompletion(client, params, options);\n  }\n\n  protected async _runTools<FunctionsArgs extends BaseFunctionsArgs>(\n    client: OpenAI,\n    params:\n      | ChatCompletionToolRunnerParams<FunctionsArgs>\n      | ChatCompletionStreamingToolRunnerParams<FunctionsArgs>,\n    options?: RunnerOptions,\n  ) {\n    const role = 'tool' as const;\n    const { tool_choice = 'auto', stream, ...restParams } = params;\n    const singleFunctionToCall =\n      typeof tool_choice !== 'string' && tool_choice.type === 'function' && tool_choice?.function?.name;\n    const { maxChatCompletions = DEFAULT_MAX_CHAT_COMPLETIONS } = options || {};\n\n    // TODO(someday): clean this logic up\n    const inputTools = params.tools.map((tool): RunnableToolFunction<any> => {\n      if (isAutoParsableTool(tool)) {\n        if (!tool.$callback) {\n          throw new OpenAIError('Tool given to `.runTools()` that does not have an associated function');\n        }\n\n        return {\n          type: 'function',\n          function: {\n            function: tool.$callback,\n            name: tool.function.name,\n            description: tool.function.description || '',\n            parameters: tool.function.parameters as any,\n            parse: tool.$parseRaw,\n            strict: true,\n          },\n        };\n      }\n\n      return tool as any as RunnableToolFunction<any>;\n    });\n\n    const functionsByName: Record<string, RunnableFunction<any>> = {};\n    for (const f of inputTools) {\n      if (f.type === 'function') {\n        functionsByName[f.function.name || f.function.function.name] = f.function;\n      }\n    }\n\n    const tools: ChatCompletionTool[] =\n      'tools' in params ?\n        inputTools.map((t) =>\n          t.type === 'function' ?\n            {\n              type: 'function',\n              function: {\n                name: t.function.name || t.function.function.name,\n                parameters: t.function.parameters as Record<string, unknown>,\n                description: t.function.description,\n                strict: t.function.strict,\n              },\n            }\n          : (t as unknown as ChatCompletionTool),\n        )\n      : (undefined as any);\n\n    for (const message of params.messages) {\n      this._addMessage(message, false);\n    }\n\n    for (let i = 0; i < maxChatCompletions; ++i) {\n      const chatCompletion: ChatCompletion = await this._createChatCompletion(\n        client,\n        {\n          ...restParams,\n          tool_choice,\n          tools,\n          messages: [...this.messages],\n        },\n        options,\n      );\n      const message = chatCompletion.choices[0]?.message;\n      if (!message) {\n        throw new OpenAIError(`missing message in ChatCompletion response`);\n      }\n      if (!message.tool_calls?.length) {\n        return;\n      }\n\n      for (const tool_call of message.tool_calls) {\n        if (tool_call.type !== 'function') continue;\n        const tool_call_id = tool_call.id;\n        const { name, arguments: args } = tool_call.function;\n        const fn = functionsByName[name];\n\n        if (!fn) {\n          const content = `Invalid tool_call: ${JSON.stringify(name)}. Available options are: ${Object.keys(\n            functionsByName,\n          )\n            .map((name) => JSON.stringify(name))\n            .join(', ')}. Please try again`;\n\n          this._addMessage({ role, tool_call_id, content });\n          continue;\n        } else if (singleFunctionToCall && singleFunctionToCall !== name) {\n          const content = `Invalid tool_call: ${JSON.stringify(name)}. ${JSON.stringify(\n            singleFunctionToCall,\n          )} requested. Please try again`;\n\n          this._addMessage({ role, tool_call_id, content });\n          continue;\n        }\n\n        let parsed;\n        try {\n          parsed = isRunnableFunctionWithParse(fn) ? await fn.parse(args) : args;\n        } catch (error) {\n          const content = error instanceof Error ? error.message : String(error);\n          this._addMessage({ role, tool_call_id, content });\n          continue;\n        }\n\n        // @ts-expect-error it can't rule out `never` type.\n        const rawContent = await fn.function(parsed, this);\n        const content = this.#stringifyFunctionCallResult(rawContent);\n        this._addMessage({ role, tool_call_id, content });\n\n        if (singleFunctionToCall) {\n          return;\n        }\n      }\n    }\n\n    return;\n  }\n\n  #stringifyFunctionCallResult(rawContent: unknown): string {\n    return (\n      typeof rawContent === 'string' ? rawContent\n      : rawContent === undefined ? 'undefined'\n      : JSON.stringify(rawContent)\n    );\n  }\n}\n\nexport interface AbstractChatCompletionRunnerEvents extends BaseEvents {\n  functionToolCall: (functionCall: ChatCompletionMessageFunctionToolCall.Function) => void;\n  message: (message: ChatCompletionMessageParam) => void;\n  chatCompletion: (completion: ChatCompletion) => void;\n  finalContent: (contentSnapshot: string) => void;\n  finalMessage: (message: ChatCompletionMessageParam) => void;\n  finalChatCompletion: (completion: ChatCompletion) => void;\n  finalFunctionToolCall: (functionCall: ChatCompletionMessageFunctionToolCall.Function) => void;\n  functionToolCallResult: (content: string) => void;\n  finalFunctionToolCallResult: (content: string) => void;\n  totalUsage: (usage: CompletionUsage) => void;\n}\n"
  },
  {
    "path": "src/lib/AssistantStream.ts",
    "content": "import {\n  TextContentBlock,\n  ImageFileContentBlock,\n  Message,\n  MessageContentDelta,\n  Text,\n  ImageFile,\n  TextDelta,\n  MessageDelta,\n  MessageContent,\n} from '../resources/beta/threads/messages';\nimport { RequestOptions } from '../internal/request-options';\nimport {\n  Run,\n  RunCreateParamsBase,\n  RunCreateParamsStreaming,\n  Runs,\n  RunSubmitToolOutputsParamsBase,\n  RunSubmitToolOutputsParamsStreaming,\n} from '../resources/beta/threads/runs/runs';\nimport { type ReadableStream } from '../internal/shim-types';\nimport { Stream } from '../streaming';\nimport { APIUserAbortError, OpenAIError } from '../error';\nimport {\n  AssistantStreamEvent,\n  MessageStreamEvent,\n  RunStepStreamEvent,\n  RunStreamEvent,\n} from '../resources/beta/assistants';\nimport { RunStep, RunStepDelta, ToolCall, ToolCallDelta } from '../resources/beta/threads/runs/steps';\nimport { ThreadCreateAndRunParamsBase, Threads } from '../resources/beta/threads/threads';\nimport { BaseEvents, EventStream } from './EventStream';\nimport { isObj } from '../internal/utils';\n\nexport interface AssistantStreamEvents extends BaseEvents {\n  run: (run: Run) => void;\n\n  //New event structure\n  messageCreated: (message: Message) => void;\n  messageDelta: (message: MessageDelta, snapshot: Message) => void;\n  messageDone: (message: Message) => void;\n\n  runStepCreated: (runStep: RunStep) => void;\n  runStepDelta: (delta: RunStepDelta, snapshot: Runs.RunStep) => void;\n  runStepDone: (runStep: Runs.RunStep, snapshot: Runs.RunStep) => void;\n\n  toolCallCreated: (toolCall: ToolCall) => void;\n  toolCallDelta: (delta: ToolCallDelta, snapshot: ToolCall) => void;\n  toolCallDone: (toolCall: ToolCall) => void;\n\n  textCreated: (content: Text) => void;\n  textDelta: (delta: TextDelta, snapshot: Text) => void;\n  textDone: (content: Text, snapshot: Message) => void;\n\n  //No created or delta as this is not streamed\n  imageFileDone: (content: ImageFile, snapshot: Message) => void;\n\n  event: (event: AssistantStreamEvent) => void;\n}\n\nexport type ThreadCreateAndRunParamsBaseStream = Omit<ThreadCreateAndRunParamsBase, 'stream'> & {\n  stream?: true;\n};\n\nexport type RunCreateParamsBaseStream = Omit<RunCreateParamsBase, 'stream'> & {\n  stream?: true;\n};\n\nexport type RunSubmitToolOutputsParamsStream = Omit<RunSubmitToolOutputsParamsBase, 'stream'> & {\n  stream?: true;\n};\n\nexport class AssistantStream\n  extends EventStream<AssistantStreamEvents>\n  implements AsyncIterable<AssistantStreamEvent>\n{\n  //Track all events in a single list for reference\n  #events: AssistantStreamEvent[] = [];\n\n  //Used to accumulate deltas\n  //We are accumulating many types so the value here is not strict\n  #runStepSnapshots: { [id: string]: Runs.RunStep } = {};\n  #messageSnapshots: { [id: string]: Message } = {};\n  #messageSnapshot: Message | undefined;\n  #finalRun: Run | undefined;\n  #currentContentIndex: number | undefined;\n  #currentContent: MessageContent | undefined;\n  #currentToolCallIndex: number | undefined;\n  #currentToolCall: ToolCall | undefined;\n\n  //For current snapshot methods\n  #currentEvent: AssistantStreamEvent | undefined;\n  #currentRunSnapshot: Run | undefined;\n  #currentRunStepSnapshot: Runs.RunStep | undefined;\n\n  [Symbol.asyncIterator](): AsyncIterator<AssistantStreamEvent> {\n    const pushQueue: AssistantStreamEvent[] = [];\n    const readQueue: {\n      resolve: (chunk: AssistantStreamEvent | undefined) => void;\n      reject: (err: unknown) => void;\n    }[] = [];\n    let done = false;\n\n    //Catch all for passing along all events\n    this.on('event', (event) => {\n      const reader = readQueue.shift();\n      if (reader) {\n        reader.resolve(event);\n      } else {\n        pushQueue.push(event);\n      }\n    });\n\n    this.on('end', () => {\n      done = true;\n      for (const reader of readQueue) {\n        reader.resolve(undefined);\n      }\n      readQueue.length = 0;\n    });\n\n    this.on('abort', (err) => {\n      done = true;\n      for (const reader of readQueue) {\n        reader.reject(err);\n      }\n      readQueue.length = 0;\n    });\n\n    this.on('error', (err) => {\n      done = true;\n      for (const reader of readQueue) {\n        reader.reject(err);\n      }\n      readQueue.length = 0;\n    });\n\n    return {\n      next: async (): Promise<IteratorResult<AssistantStreamEvent>> => {\n        if (!pushQueue.length) {\n          if (done) {\n            return { value: undefined, done: true };\n          }\n          return new Promise<AssistantStreamEvent | undefined>((resolve, reject) =>\n            readQueue.push({ resolve, reject }),\n          ).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));\n        }\n        const chunk = pushQueue.shift()!;\n        return { value: chunk, done: false };\n      },\n      return: async () => {\n        this.abort();\n        return { value: undefined, done: true };\n      },\n    };\n  }\n\n  static fromReadableStream(stream: ReadableStream): AssistantStream {\n    const runner = new AssistantStream();\n    runner._run(() => runner._fromReadableStream(stream));\n    return runner;\n  }\n\n  protected async _fromReadableStream(\n    readableStream: ReadableStream,\n    options?: RequestOptions,\n  ): Promise<Run> {\n    const signal = options?.signal;\n    if (signal) {\n      if (signal.aborted) this.controller.abort();\n      signal.addEventListener('abort', () => this.controller.abort());\n    }\n    this._connected();\n    const stream = Stream.fromReadableStream<AssistantStreamEvent>(readableStream, this.controller);\n    for await (const event of stream) {\n      this.#addEvent(event);\n    }\n    if (stream.controller.signal?.aborted) {\n      throw new APIUserAbortError();\n    }\n    return this._addRun(this.#endRequest());\n  }\n\n  toReadableStream(): ReadableStream {\n    const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);\n    return stream.toReadableStream();\n  }\n\n  static createToolAssistantStream(\n    runId: string,\n    runs: Runs,\n    params: RunSubmitToolOutputsParamsStream,\n    options: RequestOptions | undefined,\n  ): AssistantStream {\n    const runner = new AssistantStream();\n    runner._run(() =>\n      runner._runToolAssistantStream(runId, runs, params, {\n        ...options,\n        headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },\n      }),\n    );\n    return runner;\n  }\n\n  protected async _createToolAssistantStream(\n    run: Runs,\n    runId: string,\n    params: RunSubmitToolOutputsParamsStream,\n    options?: RequestOptions,\n  ): Promise<Run> {\n    const signal = options?.signal;\n    if (signal) {\n      if (signal.aborted) this.controller.abort();\n      signal.addEventListener('abort', () => this.controller.abort());\n    }\n\n    const body: RunSubmitToolOutputsParamsStreaming = { ...params, stream: true };\n    const stream = await run.submitToolOutputs(runId, body, {\n      ...options,\n      signal: this.controller.signal,\n    });\n\n    this._connected();\n\n    for await (const event of stream) {\n      this.#addEvent(event);\n    }\n    if (stream.controller.signal?.aborted) {\n      throw new APIUserAbortError();\n    }\n\n    return this._addRun(this.#endRequest());\n  }\n\n  static createThreadAssistantStream(\n    params: ThreadCreateAndRunParamsBaseStream,\n    thread: Threads,\n    options?: RequestOptions,\n  ): AssistantStream {\n    const runner = new AssistantStream();\n    runner._run(() =>\n      runner._threadAssistantStream(params, thread, {\n        ...options,\n        headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },\n      }),\n    );\n    return runner;\n  }\n\n  static createAssistantStream(\n    threadId: string,\n    runs: Runs,\n    params: RunCreateParamsBaseStream,\n    options?: RequestOptions,\n  ): AssistantStream {\n    const runner = new AssistantStream();\n    runner._run(() =>\n      runner._runAssistantStream(threadId, runs, params, {\n        ...options,\n        headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },\n      }),\n    );\n    return runner;\n  }\n\n  currentEvent(): AssistantStreamEvent | undefined {\n    return this.#currentEvent;\n  }\n\n  currentRun(): Run | undefined {\n    return this.#currentRunSnapshot;\n  }\n\n  currentMessageSnapshot(): Message | undefined {\n    return this.#messageSnapshot;\n  }\n\n  currentRunStepSnapshot(): Runs.RunStep | undefined {\n    return this.#currentRunStepSnapshot;\n  }\n\n  async finalRunSteps(): Promise<Runs.RunStep[]> {\n    await this.done();\n\n    return Object.values(this.#runStepSnapshots);\n  }\n\n  async finalMessages(): Promise<Message[]> {\n    await this.done();\n\n    return Object.values(this.#messageSnapshots);\n  }\n\n  async finalRun(): Promise<Run> {\n    await this.done();\n    if (!this.#finalRun) throw Error('Final run was not received.');\n\n    return this.#finalRun;\n  }\n\n  protected async _createThreadAssistantStream(\n    thread: Threads,\n    params: ThreadCreateAndRunParamsBase,\n    options?: RequestOptions,\n  ): Promise<Run> {\n    const signal = options?.signal;\n    if (signal) {\n      if (signal.aborted) this.controller.abort();\n      signal.addEventListener('abort', () => this.controller.abort());\n    }\n\n    const body: RunCreateParamsStreaming = { ...params, stream: true };\n    const stream = await thread.createAndRun(body, { ...options, signal: this.controller.signal });\n\n    this._connected();\n\n    for await (const event of stream) {\n      this.#addEvent(event);\n    }\n    if (stream.controller.signal?.aborted) {\n      throw new APIUserAbortError();\n    }\n\n    return this._addRun(this.#endRequest());\n  }\n\n  protected async _createAssistantStream(\n    run: Runs,\n    threadId: string,\n    params: RunCreateParamsBase,\n    options?: RequestOptions,\n  ): Promise<Run> {\n    const signal = options?.signal;\n    if (signal) {\n      if (signal.aborted) this.controller.abort();\n      signal.addEventListener('abort', () => this.controller.abort());\n    }\n\n    const body: RunCreateParamsStreaming = { ...params, stream: true };\n    const stream = await run.create(threadId, body, { ...options, signal: this.controller.signal });\n\n    this._connected();\n\n    for await (const event of stream) {\n      this.#addEvent(event);\n    }\n    if (stream.controller.signal?.aborted) {\n      throw new APIUserAbortError();\n    }\n\n    return this._addRun(this.#endRequest());\n  }\n\n  #addEvent(event: AssistantStreamEvent) {\n    if (this.ended) return;\n\n    this.#currentEvent = event;\n\n    this.#handleEvent(event);\n\n    switch (event.event) {\n      case 'thread.created':\n        //No action on this event.\n        break;\n\n      case 'thread.run.created':\n      case 'thread.run.queued':\n      case 'thread.run.in_progress':\n      case 'thread.run.requires_action':\n      case 'thread.run.completed':\n      case 'thread.run.incomplete':\n      case 'thread.run.failed':\n      case 'thread.run.cancelling':\n      case 'thread.run.cancelled':\n      case 'thread.run.expired':\n        this.#handleRun(event);\n        break;\n\n      case 'thread.run.step.created':\n      case 'thread.run.step.in_progress':\n      case 'thread.run.step.delta':\n      case 'thread.run.step.completed':\n      case 'thread.run.step.failed':\n      case 'thread.run.step.cancelled':\n      case 'thread.run.step.expired':\n        this.#handleRunStep(event);\n        break;\n\n      case 'thread.message.created':\n      case 'thread.message.in_progress':\n      case 'thread.message.delta':\n      case 'thread.message.completed':\n      case 'thread.message.incomplete':\n        this.#handleMessage(event);\n        break;\n\n      case 'error':\n        //This is included for completeness, but errors are processed in the SSE event processing so this should not occur\n        throw new Error(\n          'Encountered an error event in event processing - errors should be processed earlier',\n        );\n      default:\n        assertNever(event);\n    }\n  }\n\n  #endRequest(): Run {\n    if (this.ended) {\n      throw new OpenAIError(`stream has ended, this shouldn't happen`);\n    }\n\n    if (!this.#finalRun) throw Error('Final run has not been received');\n\n    return this.#finalRun;\n  }\n\n  #handleMessage(this: AssistantStream, event: MessageStreamEvent) {\n    const [accumulatedMessage, newContent] = this.#accumulateMessage(event, this.#messageSnapshot);\n    this.#messageSnapshot = accumulatedMessage;\n    this.#messageSnapshots[accumulatedMessage.id] = accumulatedMessage;\n\n    for (const content of newContent) {\n      const snapshotContent = accumulatedMessage.content[content.index];\n      if (snapshotContent?.type == 'text') {\n        this._emit('textCreated', snapshotContent.text);\n      }\n    }\n\n    switch (event.event) {\n      case 'thread.message.created':\n        this._emit('messageCreated', event.data);\n        break;\n\n      case 'thread.message.in_progress':\n        break;\n\n      case 'thread.message.delta':\n        this._emit('messageDelta', event.data.delta, accumulatedMessage);\n\n        if (event.data.delta.content) {\n          for (const content of event.data.delta.content) {\n            //If it is text delta, emit a text delta event\n            if (content.type == 'text' && content.text) {\n              let textDelta = content.text;\n              let snapshot = accumulatedMessage.content[content.index];\n              if (snapshot && snapshot.type == 'text') {\n                this._emit('textDelta', textDelta, snapshot.text);\n              } else {\n                throw Error('The snapshot associated with this text delta is not text or missing');\n              }\n            }\n\n            if (content.index != this.#currentContentIndex) {\n              //See if we have in progress content\n              if (this.#currentContent) {\n                switch (this.#currentContent.type) {\n                  case 'text':\n                    this._emit('textDone', this.#currentContent.text, this.#messageSnapshot);\n                    break;\n                  case 'image_file':\n                    this._emit('imageFileDone', this.#currentContent.image_file, this.#messageSnapshot);\n                    break;\n                }\n              }\n\n              this.#currentContentIndex = content.index;\n            }\n\n            this.#currentContent = accumulatedMessage.content[content.index];\n          }\n        }\n\n        break;\n\n      case 'thread.message.completed':\n      case 'thread.message.incomplete':\n        //We emit the latest content we were working on on completion (including incomplete)\n        if (this.#currentContentIndex !== undefined) {\n          const currentContent = event.data.content[this.#currentContentIndex];\n          if (currentContent) {\n            switch (currentContent.type) {\n              case 'image_file':\n                this._emit('imageFileDone', currentContent.image_file, this.#messageSnapshot);\n                break;\n              case 'text':\n                this._emit('textDone', currentContent.text, this.#messageSnapshot);\n                break;\n            }\n          }\n        }\n\n        if (this.#messageSnapshot) {\n          this._emit('messageDone', event.data);\n        }\n\n        this.#messageSnapshot = undefined;\n    }\n  }\n\n  #handleRunStep(this: AssistantStream, event: RunStepStreamEvent) {\n    const accumulatedRunStep = this.#accumulateRunStep(event);\n    this.#currentRunStepSnapshot = accumulatedRunStep;\n\n    switch (event.event) {\n      case 'thread.run.step.created':\n        this._emit('runStepCreated', event.data);\n        break;\n      case 'thread.run.step.delta':\n        const delta = event.data.delta;\n        if (\n          delta.step_details &&\n          delta.step_details.type == 'tool_calls' &&\n          delta.step_details.tool_calls &&\n          accumulatedRunStep.step_details.type == 'tool_calls'\n        ) {\n          for (const toolCall of delta.step_details.tool_calls) {\n            if (toolCall.index == this.#currentToolCallIndex) {\n              this._emit(\n                'toolCallDelta',\n                toolCall,\n                accumulatedRunStep.step_details.tool_calls[toolCall.index] as ToolCall,\n              );\n            } else {\n              if (this.#currentToolCall) {\n                this._emit('toolCallDone', this.#currentToolCall);\n              }\n\n              this.#currentToolCallIndex = toolCall.index;\n              this.#currentToolCall = accumulatedRunStep.step_details.tool_calls[toolCall.index];\n              if (this.#currentToolCall) this._emit('toolCallCreated', this.#currentToolCall);\n            }\n          }\n        }\n\n        this._emit('runStepDelta', event.data.delta, accumulatedRunStep);\n        break;\n      case 'thread.run.step.completed':\n      case 'thread.run.step.failed':\n      case 'thread.run.step.cancelled':\n      case 'thread.run.step.expired':\n        this.#currentRunStepSnapshot = undefined;\n        const details = event.data.step_details;\n        if (details.type == 'tool_calls') {\n          if (this.#currentToolCall) {\n            this._emit('toolCallDone', this.#currentToolCall as ToolCall);\n            this.#currentToolCall = undefined;\n          }\n        }\n        this._emit('runStepDone', event.data, accumulatedRunStep);\n        break;\n      case 'thread.run.step.in_progress':\n        break;\n    }\n  }\n\n  #handleEvent(this: AssistantStream, event: AssistantStreamEvent) {\n    this.#events.push(event);\n    this._emit('event', event);\n  }\n\n  #accumulateRunStep(event: RunStepStreamEvent): Runs.RunStep {\n    switch (event.event) {\n      case 'thread.run.step.created':\n        this.#runStepSnapshots[event.data.id] = event.data;\n        return event.data;\n\n      case 'thread.run.step.delta':\n        let snapshot = this.#runStepSnapshots[event.data.id] as Runs.RunStep;\n        if (!snapshot) {\n          throw Error('Received a RunStepDelta before creation of a snapshot');\n        }\n\n        let data = event.data;\n\n        if (data.delta) {\n          const accumulated = AssistantStream.accumulateDelta(snapshot, data.delta) as Runs.RunStep;\n          this.#runStepSnapshots[event.data.id] = accumulated;\n        }\n\n        return this.#runStepSnapshots[event.data.id] as Runs.RunStep;\n\n      case 'thread.run.step.completed':\n      case 'thread.run.step.failed':\n      case 'thread.run.step.cancelled':\n      case 'thread.run.step.expired':\n      case 'thread.run.step.in_progress':\n        this.#runStepSnapshots[event.data.id] = event.data;\n        break;\n    }\n\n    if (this.#runStepSnapshots[event.data.id]) return this.#runStepSnapshots[event.data.id] as Runs.RunStep;\n    throw new Error('No snapshot available');\n  }\n\n  #accumulateMessage(\n    event: AssistantStreamEvent,\n    snapshot: Message | undefined,\n  ): [Message, MessageContentDelta[]] {\n    let newContent: MessageContentDelta[] = [];\n\n    switch (event.event) {\n      case 'thread.message.created':\n        //On creation the snapshot is just the initial message\n        return [event.data, newContent];\n\n      case 'thread.message.delta':\n        if (!snapshot) {\n          throw Error(\n            'Received a delta with no existing snapshot (there should be one from message creation)',\n          );\n        }\n\n        let data = event.data;\n\n        //If this delta does not have content, nothing to process\n        if (data.delta.content) {\n          for (const contentElement of data.delta.content) {\n            if (contentElement.index in snapshot.content) {\n              let currentContent = snapshot.content[contentElement.index];\n              snapshot.content[contentElement.index] = this.#accumulateContent(\n                contentElement,\n                currentContent,\n              );\n            } else {\n              snapshot.content[contentElement.index] = contentElement as MessageContent;\n              // This is a new element\n              newContent.push(contentElement);\n            }\n          }\n        }\n\n        return [snapshot, newContent];\n\n      case 'thread.message.in_progress':\n      case 'thread.message.completed':\n      case 'thread.message.incomplete':\n        //No changes on other thread events\n        if (snapshot) {\n          return [snapshot, newContent];\n        } else {\n          throw Error('Received thread message event with no existing snapshot');\n        }\n    }\n    throw Error('Tried to accumulate a non-message event');\n  }\n\n  #accumulateContent(\n    contentElement: MessageContentDelta,\n    currentContent: MessageContent | undefined,\n  ): TextContentBlock | ImageFileContentBlock {\n    return AssistantStream.accumulateDelta(currentContent as unknown as Record<any, any>, contentElement) as\n      | TextContentBlock\n      | ImageFileContentBlock;\n  }\n\n  static accumulateDelta(acc: Record<string, any>, delta: Record<string, any>): Record<string, any> {\n    for (const [key, deltaValue] of Object.entries(delta)) {\n      if (!acc.hasOwnProperty(key)) {\n        acc[key] = deltaValue;\n        continue;\n      }\n\n      let accValue = acc[key];\n      if (accValue === null || accValue === undefined) {\n        acc[key] = deltaValue;\n        continue;\n      }\n\n      // We don't accumulate these special properties\n      if (key === 'index' || key === 'type') {\n        acc[key] = deltaValue;\n        continue;\n      }\n\n      // Type-specific accumulation logic\n      if (typeof accValue === 'string' && typeof deltaValue === 'string') {\n        accValue += deltaValue;\n      } else if (typeof accValue === 'number' && typeof deltaValue === 'number') {\n        accValue += deltaValue;\n      } else if (isObj(accValue) && isObj(deltaValue)) {\n        accValue = this.accumulateDelta(accValue as Record<string, any>, deltaValue as Record<string, any>);\n      } else if (Array.isArray(accValue) && Array.isArray(deltaValue)) {\n        if (accValue.every((x) => typeof x === 'string' || typeof x === 'number')) {\n          accValue.push(...deltaValue); // Use spread syntax for efficient addition\n          continue;\n        }\n\n        for (const deltaEntry of deltaValue) {\n          if (!isObj(deltaEntry)) {\n            throw new Error(`Expected array delta entry to be an object but got: ${deltaEntry}`);\n          }\n\n          const index = deltaEntry['index'];\n          if (index == null) {\n            console.error(deltaEntry);\n            throw new Error('Expected array delta entry to have an `index` property');\n          }\n\n          if (typeof index !== 'number') {\n            throw new Error(`Expected array delta entry \\`index\\` property to be a number but got ${index}`);\n          }\n\n          const accEntry = accValue[index];\n          if (accEntry == null) {\n            accValue.push(deltaEntry);\n          } else {\n            accValue[index] = this.accumulateDelta(accEntry, deltaEntry);\n          }\n        }\n        continue;\n      } else {\n        throw Error(`Unhandled record type: ${key}, deltaValue: ${deltaValue}, accValue: ${accValue}`);\n      }\n      acc[key] = accValue;\n    }\n\n    return acc;\n  }\n\n  #handleRun(this: AssistantStream, event: RunStreamEvent) {\n    this.#currentRunSnapshot = event.data;\n\n    switch (event.event) {\n      case 'thread.run.created':\n        break;\n      case 'thread.run.queued':\n        break;\n      case 'thread.run.in_progress':\n        break;\n      case 'thread.run.requires_action':\n      case 'thread.run.cancelled':\n      case 'thread.run.failed':\n      case 'thread.run.completed':\n      case 'thread.run.expired':\n      case 'thread.run.incomplete':\n        this.#finalRun = event.data;\n        if (this.#currentToolCall) {\n          this._emit('toolCallDone', this.#currentToolCall);\n          this.#currentToolCall = undefined;\n        }\n        break;\n      case 'thread.run.cancelling':\n        break;\n    }\n  }\n\n  protected _addRun(run: Run): Run {\n    return run;\n  }\n\n  protected async _threadAssistantStream(\n    params: ThreadCreateAndRunParamsBase,\n    thread: Threads,\n    options?: RequestOptions,\n  ): Promise<Run> {\n    return await this._createThreadAssistantStream(thread, params, options);\n  }\n\n  protected async _runAssistantStream(\n    threadId: string,\n    runs: Runs,\n    params: RunCreateParamsBase,\n    options?: RequestOptions,\n  ): Promise<Run> {\n    return await this._createAssistantStream(runs, threadId, params, options);\n  }\n\n  protected async _runToolAssistantStream(\n    runId: string,\n    runs: Runs,\n    params: RunSubmitToolOutputsParamsStream,\n    options?: RequestOptions,\n  ): Promise<Run> {\n    return await this._createToolAssistantStream(runs, runId, params, options);\n  }\n}\n\nfunction assertNever(_x: never) {}\n"
  },
  {
    "path": "src/lib/ChatCompletionRunner.ts",
    "content": "import {\n  type ChatCompletionMessageParam,\n  type ChatCompletionCreateParamsNonStreaming,\n} from '../resources/chat/completions';\nimport { type BaseFunctionsArgs, RunnableTools } from './RunnableFunction';\nimport {\n  AbstractChatCompletionRunner,\n  AbstractChatCompletionRunnerEvents,\n  RunnerOptions,\n} from './AbstractChatCompletionRunner';\nimport { isAssistantMessage } from './chatCompletionUtils';\nimport OpenAI from '../index';\nimport { AutoParseableTool } from '../lib/parser';\n\nexport interface ChatCompletionRunnerEvents extends AbstractChatCompletionRunnerEvents {\n  content: (content: string) => void;\n}\n\nexport type ChatCompletionToolRunnerParams<FunctionsArgs extends BaseFunctionsArgs> = Omit<\n  ChatCompletionCreateParamsNonStreaming,\n  'tools'\n> & {\n  tools: RunnableTools<FunctionsArgs> | AutoParseableTool<any, true>[];\n};\n\nexport class ChatCompletionRunner<ParsedT = null> extends AbstractChatCompletionRunner<\n  ChatCompletionRunnerEvents,\n  ParsedT\n> {\n  static runTools<ParsedT>(\n    client: OpenAI,\n    params: ChatCompletionToolRunnerParams<any[]>,\n    options?: RunnerOptions,\n  ): ChatCompletionRunner<ParsedT> {\n    const runner = new ChatCompletionRunner<ParsedT>();\n    const opts = {\n      ...options,\n      headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'runTools' },\n    };\n    runner._run(() => runner._runTools(client, params, opts));\n    return runner;\n  }\n\n  override _addMessage(\n    this: ChatCompletionRunner<ParsedT>,\n    message: ChatCompletionMessageParam,\n    emit: boolean = true,\n  ) {\n    super._addMessage(message, emit);\n    if (isAssistantMessage(message) && message.content) {\n      this._emit('content', message.content as string);\n    }\n  }\n}\n"
  },
  {
    "path": "src/lib/ChatCompletionStream.ts",
    "content": "import { partialParse } from '../_vendor/partial-json-parser/parser';\nimport {\n  APIUserAbortError,\n  ContentFilterFinishReasonError,\n  LengthFinishReasonError,\n  OpenAIError,\n} from '../error';\nimport OpenAI from '../index';\nimport { RequestOptions } from '../internal/request-options';\nimport { type ReadableStream } from '../internal/shim-types';\nimport {\n  AutoParseableResponseFormat,\n  hasAutoParseableInput,\n  isAutoParsableResponseFormat,\n  isAutoParsableTool,\n  isChatCompletionFunctionTool,\n  maybeParseChatCompletion,\n  shouldParseToolCall,\n} from '../lib/parser';\nimport { ChatCompletionFunctionTool, ParsedChatCompletion } from '../resources/chat/completions';\nimport {\n  ChatCompletionTokenLogprob,\n  type ChatCompletion,\n  type ChatCompletionChunk,\n  type ChatCompletionCreateParams,\n  type ChatCompletionCreateParamsBase,\n  type ChatCompletionCreateParamsStreaming,\n  type ChatCompletionRole,\n} from '../resources/chat/completions/completions';\nimport { Stream } from '../streaming';\nimport {\n  AbstractChatCompletionRunner,\n  type AbstractChatCompletionRunnerEvents,\n} from './AbstractChatCompletionRunner';\n\nexport interface ContentDeltaEvent {\n  delta: string;\n  snapshot: string;\n  parsed: unknown | null;\n}\n\nexport interface ContentDoneEvent<ParsedT = null> {\n  content: string;\n  parsed: ParsedT | null;\n}\n\nexport interface RefusalDeltaEvent {\n  delta: string;\n  snapshot: string;\n}\n\nexport interface RefusalDoneEvent {\n  refusal: string;\n}\n\nexport interface FunctionToolCallArgumentsDeltaEvent {\n  name: string;\n\n  index: number;\n\n  arguments: string;\n\n  parsed_arguments: unknown;\n\n  arguments_delta: string;\n}\n\nexport interface FunctionToolCallArgumentsDoneEvent {\n  name: string;\n\n  index: number;\n\n  arguments: string;\n\n  parsed_arguments: unknown;\n}\n\nexport interface LogProbsContentDeltaEvent {\n  content: Array<ChatCompletionTokenLogprob>;\n  snapshot: Array<ChatCompletionTokenLogprob>;\n}\n\nexport interface LogProbsContentDoneEvent {\n  content: Array<ChatCompletionTokenLogprob>;\n}\n\nexport interface LogProbsRefusalDeltaEvent {\n  refusal: Array<ChatCompletionTokenLogprob>;\n  snapshot: Array<ChatCompletionTokenLogprob>;\n}\n\nexport interface LogProbsRefusalDoneEvent {\n  refusal: Array<ChatCompletionTokenLogprob>;\n}\n\nexport interface ChatCompletionStreamEvents<ParsedT = null> extends AbstractChatCompletionRunnerEvents {\n  content: (contentDelta: string, contentSnapshot: string) => void;\n  chunk: (chunk: ChatCompletionChunk, snapshot: ChatCompletionSnapshot) => void;\n\n  'content.delta': (props: ContentDeltaEvent) => void;\n  'content.done': (props: ContentDoneEvent<ParsedT>) => void;\n\n  'refusal.delta': (props: RefusalDeltaEvent) => void;\n  'refusal.done': (props: RefusalDoneEvent) => void;\n\n  'tool_calls.function.arguments.delta': (props: FunctionToolCallArgumentsDeltaEvent) => void;\n  'tool_calls.function.arguments.done': (props: FunctionToolCallArgumentsDoneEvent) => void;\n\n  'logprobs.content.delta': (props: LogProbsContentDeltaEvent) => void;\n  'logprobs.content.done': (props: LogProbsContentDoneEvent) => void;\n\n  'logprobs.refusal.delta': (props: LogProbsRefusalDeltaEvent) => void;\n  'logprobs.refusal.done': (props: LogProbsRefusalDoneEvent) => void;\n}\n\nexport type ChatCompletionStreamParams = Omit<ChatCompletionCreateParamsBase, 'stream'> & {\n  stream?: true;\n};\n\ninterface ChoiceEventState {\n  content_done: boolean;\n  refusal_done: boolean;\n  logprobs_content_done: boolean;\n  logprobs_refusal_done: boolean;\n  current_tool_call_index: number | null;\n  done_tool_calls: Set<number>;\n}\n\nexport class ChatCompletionStream<ParsedT = null>\n  extends AbstractChatCompletionRunner<ChatCompletionStreamEvents<ParsedT>, ParsedT>\n  implements AsyncIterable<ChatCompletionChunk>\n{\n  #params: ChatCompletionCreateParams | null;\n  #choiceEventStates: ChoiceEventState[];\n  #currentChatCompletionSnapshot: ChatCompletionSnapshot | undefined;\n\n  constructor(params: ChatCompletionCreateParams | null) {\n    super();\n    this.#params = params;\n    this.#choiceEventStates = [];\n  }\n\n  get currentChatCompletionSnapshot(): ChatCompletionSnapshot | undefined {\n    return this.#currentChatCompletionSnapshot;\n  }\n\n  /**\n   * Intended for use on the frontend, consuming a stream produced with\n   * `.toReadableStream()` on the backend.\n   *\n   * Note that messages sent to the model do not appear in `.on('message')`\n   * in this context.\n   */\n  static fromReadableStream(stream: ReadableStream): ChatCompletionStream<null> {\n    const runner = new ChatCompletionStream(null);\n    runner._run(() => runner._fromReadableStream(stream));\n    return runner;\n  }\n\n  static createChatCompletion<ParsedT>(\n    client: OpenAI,\n    params: ChatCompletionStreamParams,\n    options?: RequestOptions,\n  ): ChatCompletionStream<ParsedT> {\n    const runner = new ChatCompletionStream<ParsedT>(params as ChatCompletionCreateParamsStreaming);\n    runner._run(() =>\n      runner._runChatCompletion(\n        client,\n        { ...params, stream: true },\n        { ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } },\n      ),\n    );\n    return runner;\n  }\n\n  #beginRequest() {\n    if (this.ended) return;\n    this.#currentChatCompletionSnapshot = undefined;\n  }\n\n  #getChoiceEventState(choice: ChatCompletionSnapshot.Choice): ChoiceEventState {\n    let state = this.#choiceEventStates[choice.index];\n    if (state) {\n      return state;\n    }\n\n    state = {\n      content_done: false,\n      refusal_done: false,\n      logprobs_content_done: false,\n      logprobs_refusal_done: false,\n      done_tool_calls: new Set(),\n      current_tool_call_index: null,\n    };\n    this.#choiceEventStates[choice.index] = state;\n    return state;\n  }\n\n  #addChunk(this: ChatCompletionStream<ParsedT>, chunk: ChatCompletionChunk) {\n    if (this.ended) return;\n\n    const completion = this.#accumulateChatCompletion(chunk);\n    this._emit('chunk', chunk, completion);\n\n    for (const choice of chunk.choices) {\n      const choiceSnapshot = completion.choices[choice.index]!;\n\n      if (\n        choice.delta.content != null &&\n        choiceSnapshot.message?.role === 'assistant' &&\n        choiceSnapshot.message?.content\n      ) {\n        this._emit('content', choice.delta.content, choiceSnapshot.message.content);\n        this._emit('content.delta', {\n          delta: choice.delta.content,\n          snapshot: choiceSnapshot.message.content,\n          parsed: choiceSnapshot.message.parsed,\n        });\n      }\n\n      if (\n        choice.delta.refusal != null &&\n        choiceSnapshot.message?.role === 'assistant' &&\n        choiceSnapshot.message?.refusal\n      ) {\n        this._emit('refusal.delta', {\n          delta: choice.delta.refusal,\n          snapshot: choiceSnapshot.message.refusal,\n        });\n      }\n\n      if (choice.logprobs?.content != null && choiceSnapshot.message?.role === 'assistant') {\n        this._emit('logprobs.content.delta', {\n          content: choice.logprobs?.content,\n          snapshot: choiceSnapshot.logprobs?.content ?? [],\n        });\n      }\n\n      if (choice.logprobs?.refusal != null && choiceSnapshot.message?.role === 'assistant') {\n        this._emit('logprobs.refusal.delta', {\n          refusal: choice.logprobs?.refusal,\n          snapshot: choiceSnapshot.logprobs?.refusal ?? [],\n        });\n      }\n\n      const state = this.#getChoiceEventState(choiceSnapshot);\n\n      if (choiceSnapshot.finish_reason) {\n        this.#emitContentDoneEvents(choiceSnapshot);\n\n        if (state.current_tool_call_index != null) {\n          this.#emitToolCallDoneEvent(choiceSnapshot, state.current_tool_call_index);\n        }\n      }\n\n      for (const toolCall of choice.delta.tool_calls ?? []) {\n        if (state.current_tool_call_index !== toolCall.index) {\n          this.#emitContentDoneEvents(choiceSnapshot);\n\n          // new tool call started, the previous one is done\n          if (state.current_tool_call_index != null) {\n            this.#emitToolCallDoneEvent(choiceSnapshot, state.current_tool_call_index);\n          }\n        }\n\n        state.current_tool_call_index = toolCall.index;\n      }\n\n      for (const toolCallDelta of choice.delta.tool_calls ?? []) {\n        const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallDelta.index];\n        if (!toolCallSnapshot?.type) {\n          continue;\n        }\n\n        if (toolCallSnapshot?.type === 'function') {\n          this._emit('tool_calls.function.arguments.delta', {\n            name: toolCallSnapshot.function?.name,\n            index: toolCallDelta.index,\n            arguments: toolCallSnapshot.function.arguments,\n            parsed_arguments: toolCallSnapshot.function.parsed_arguments,\n            arguments_delta: toolCallDelta.function?.arguments ?? '',\n          });\n        } else {\n          assertNever(toolCallSnapshot?.type);\n        }\n      }\n    }\n  }\n\n  #emitToolCallDoneEvent(choiceSnapshot: ChatCompletionSnapshot.Choice, toolCallIndex: number) {\n    const state = this.#getChoiceEventState(choiceSnapshot);\n    if (state.done_tool_calls.has(toolCallIndex)) {\n      // we've already fired the done event\n      return;\n    }\n\n    const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallIndex];\n    if (!toolCallSnapshot) {\n      throw new Error('no tool call snapshot');\n    }\n    if (!toolCallSnapshot.type) {\n      throw new Error('tool call snapshot missing `type`');\n    }\n\n    if (toolCallSnapshot.type === 'function') {\n      const inputTool = this.#params?.tools?.find(\n        (tool) => isChatCompletionFunctionTool(tool) && tool.function.name === toolCallSnapshot.function.name,\n      ) as ChatCompletionFunctionTool | undefined; // TS doesn't narrow based on isChatCompletionTool\n\n      this._emit('tool_calls.function.arguments.done', {\n        name: toolCallSnapshot.function.name,\n        index: toolCallIndex,\n        arguments: toolCallSnapshot.function.arguments,\n        parsed_arguments:\n          isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCallSnapshot.function.arguments)\n          : inputTool?.function.strict ? JSON.parse(toolCallSnapshot.function.arguments)\n          : null,\n      });\n    } else {\n      assertNever(toolCallSnapshot.type);\n    }\n  }\n\n  #emitContentDoneEvents(choiceSnapshot: ChatCompletionSnapshot.Choice) {\n    const state = this.#getChoiceEventState(choiceSnapshot);\n\n    if (choiceSnapshot.message.content && !state.content_done) {\n      state.content_done = true;\n\n      const responseFormat = this.#getAutoParseableResponseFormat();\n\n      this._emit('content.done', {\n        content: choiceSnapshot.message.content,\n        parsed: responseFormat ? responseFormat.$parseRaw(choiceSnapshot.message.content) : (null as any),\n      });\n    }\n\n    if (choiceSnapshot.message.refusal && !state.refusal_done) {\n      state.refusal_done = true;\n\n      this._emit('refusal.done', { refusal: choiceSnapshot.message.refusal });\n    }\n\n    if (choiceSnapshot.logprobs?.content && !state.logprobs_content_done) {\n      state.logprobs_content_done = true;\n\n      this._emit('logprobs.content.done', { content: choiceSnapshot.logprobs.content });\n    }\n\n    if (choiceSnapshot.logprobs?.refusal && !state.logprobs_refusal_done) {\n      state.logprobs_refusal_done = true;\n\n      this._emit('logprobs.refusal.done', { refusal: choiceSnapshot.logprobs.refusal });\n    }\n  }\n\n  #endRequest(): ParsedChatCompletion<ParsedT> {\n    if (this.ended) {\n      throw new OpenAIError(`stream has ended, this shouldn't happen`);\n    }\n    const snapshot = this.#currentChatCompletionSnapshot;\n    if (!snapshot) {\n      throw new OpenAIError(`request ended without sending any chunks`);\n    }\n    this.#currentChatCompletionSnapshot = undefined;\n    this.#choiceEventStates = [];\n    return finalizeChatCompletion(snapshot, this.#params);\n  }\n\n  protected override async _createChatCompletion(\n    client: OpenAI,\n    params: ChatCompletionCreateParams,\n    options?: RequestOptions,\n  ): Promise<ParsedChatCompletion<ParsedT>> {\n    super._createChatCompletion;\n    const signal = options?.signal;\n    if (signal) {\n      if (signal.aborted) this.controller.abort();\n      signal.addEventListener('abort', () => this.controller.abort());\n    }\n    this.#beginRequest();\n\n    const stream = await client.chat.completions.create(\n      { ...params, stream: true },\n      { ...options, signal: this.controller.signal },\n    );\n    this._connected();\n    for await (const chunk of stream) {\n      this.#addChunk(chunk);\n    }\n    if (stream.controller.signal?.aborted) {\n      throw new APIUserAbortError();\n    }\n    return this._addChatCompletion(this.#endRequest());\n  }\n\n  protected async _fromReadableStream(\n    readableStream: ReadableStream,\n    options?: RequestOptions,\n  ): Promise<ChatCompletion> {\n    const signal = options?.signal;\n    if (signal) {\n      if (signal.aborted) this.controller.abort();\n      signal.addEventListener('abort', () => this.controller.abort());\n    }\n    this.#beginRequest();\n    this._connected();\n    const stream = Stream.fromReadableStream<ChatCompletionChunk>(readableStream, this.controller);\n    let chatId;\n    for await (const chunk of stream) {\n      if (chatId && chatId !== chunk.id) {\n        // A new request has been made.\n        this._addChatCompletion(this.#endRequest());\n      }\n\n      this.#addChunk(chunk);\n      chatId = chunk.id;\n    }\n    if (stream.controller.signal?.aborted) {\n      throw new APIUserAbortError();\n    }\n    return this._addChatCompletion(this.#endRequest());\n  }\n\n  #getAutoParseableResponseFormat(): AutoParseableResponseFormat<ParsedT> | null {\n    const responseFormat = this.#params?.response_format;\n    if (isAutoParsableResponseFormat<ParsedT>(responseFormat)) {\n      return responseFormat;\n    }\n\n    return null;\n  }\n\n  #accumulateChatCompletion(chunk: ChatCompletionChunk): ChatCompletionSnapshot {\n    let snapshot = this.#currentChatCompletionSnapshot;\n    const { choices, ...rest } = chunk;\n    if (!snapshot) {\n      snapshot = this.#currentChatCompletionSnapshot = {\n        ...rest,\n        choices: [],\n      };\n    } else {\n      Object.assign(snapshot, rest);\n    }\n\n    for (const { delta, finish_reason, index, logprobs = null, ...other } of chunk.choices) {\n      let choice = snapshot.choices[index];\n      if (!choice) {\n        choice = snapshot.choices[index] = { finish_reason, index, message: {}, logprobs, ...other };\n      }\n\n      if (logprobs) {\n        if (!choice.logprobs) {\n          choice.logprobs = Object.assign({}, logprobs);\n        } else {\n          const { content, refusal, ...rest } = logprobs;\n          assertIsEmpty(rest);\n          Object.assign(choice.logprobs, rest);\n\n          if (content) {\n            choice.logprobs.content ??= [];\n            choice.logprobs.content.push(...content);\n          }\n\n          if (refusal) {\n            choice.logprobs.refusal ??= [];\n            choice.logprobs.refusal.push(...refusal);\n          }\n        }\n      }\n\n      if (finish_reason) {\n        choice.finish_reason = finish_reason;\n\n        if (this.#params && hasAutoParseableInput(this.#params)) {\n          if (finish_reason === 'length') {\n            throw new LengthFinishReasonError();\n          }\n\n          if (finish_reason === 'content_filter') {\n            throw new ContentFilterFinishReasonError();\n          }\n        }\n      }\n\n      Object.assign(choice, other);\n\n      if (!delta) continue; // Shouldn't happen; just in case.\n\n      const { content, refusal, function_call, role, tool_calls, ...rest } = delta;\n      assertIsEmpty(rest);\n      Object.assign(choice.message, rest);\n\n      if (refusal) {\n        choice.message.refusal = (choice.message.refusal || '') + refusal;\n      }\n\n      if (role) choice.message.role = role;\n      if (function_call) {\n        if (!choice.message.function_call) {\n          choice.message.function_call = function_call;\n        } else {\n          if (function_call.name) choice.message.function_call.name = function_call.name;\n          if (function_call.arguments) {\n            choice.message.function_call.arguments ??= '';\n            choice.message.function_call.arguments += function_call.arguments;\n          }\n        }\n      }\n      if (content) {\n        choice.message.content = (choice.message.content || '') + content;\n\n        if (!choice.message.refusal && this.#getAutoParseableResponseFormat()) {\n          choice.message.parsed = partialParse(choice.message.content);\n        }\n      }\n\n      if (tool_calls) {\n        if (!choice.message.tool_calls) choice.message.tool_calls = [];\n\n        for (const { index, id, type, function: fn, ...rest } of tool_calls) {\n          const tool_call = (choice.message.tool_calls[index] ??=\n            {} as ChatCompletionSnapshot.Choice.Message.ToolCall);\n          Object.assign(tool_call, rest);\n          if (id) tool_call.id = id;\n          if (type) tool_call.type = type;\n          if (fn) tool_call.function ??= { name: fn.name ?? '', arguments: '' };\n          if (fn?.name) tool_call.function!.name = fn.name;\n          if (fn?.arguments) {\n            tool_call.function!.arguments += fn.arguments;\n\n            if (shouldParseToolCall(this.#params, tool_call)) {\n              tool_call.function!.parsed_arguments = partialParse(tool_call.function!.arguments);\n            }\n          }\n        }\n      }\n    }\n    return snapshot;\n  }\n\n  [Symbol.asyncIterator](this: ChatCompletionStream<ParsedT>): AsyncIterator<ChatCompletionChunk> {\n    const pushQueue: ChatCompletionChunk[] = [];\n    const readQueue: {\n      resolve: (chunk: ChatCompletionChunk | undefined) => void;\n      reject: (err: unknown) => void;\n    }[] = [];\n    let done = false;\n\n    this.on('chunk', (chunk) => {\n      const reader = readQueue.shift();\n      if (reader) {\n        reader.resolve(chunk);\n      } else {\n        pushQueue.push(chunk);\n      }\n    });\n\n    this.on('end', () => {\n      done = true;\n      for (const reader of readQueue) {\n        reader.resolve(undefined);\n      }\n      readQueue.length = 0;\n    });\n\n    this.on('abort', (err) => {\n      done = true;\n      for (const reader of readQueue) {\n        reader.reject(err);\n      }\n      readQueue.length = 0;\n    });\n\n    this.on('error', (err) => {\n      done = true;\n      for (const reader of readQueue) {\n        reader.reject(err);\n      }\n      readQueue.length = 0;\n    });\n\n    return {\n      next: async (): Promise<IteratorResult<ChatCompletionChunk>> => {\n        if (!pushQueue.length) {\n          if (done) {\n            return { value: undefined, done: true };\n          }\n          return new Promise<ChatCompletionChunk | undefined>((resolve, reject) =>\n            readQueue.push({ resolve, reject }),\n          ).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));\n        }\n        const chunk = pushQueue.shift()!;\n        return { value: chunk, done: false };\n      },\n      return: async () => {\n        this.abort();\n        return { value: undefined, done: true };\n      },\n    };\n  }\n\n  toReadableStream(): ReadableStream {\n    const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);\n    return stream.toReadableStream();\n  }\n}\n\nfunction finalizeChatCompletion<ParsedT>(\n  snapshot: ChatCompletionSnapshot,\n  params: ChatCompletionCreateParams | null,\n): ParsedChatCompletion<ParsedT> {\n  const { id, choices, created, model, system_fingerprint, ...rest } = snapshot;\n  const completion: ChatCompletion = {\n    ...rest,\n    id,\n    choices: choices.map(\n      ({ message, finish_reason, index, logprobs, ...choiceRest }): ChatCompletion.Choice => {\n        if (!finish_reason) {\n          throw new OpenAIError(`missing finish_reason for choice ${index}`);\n        }\n\n        const { content = null, function_call, tool_calls, ...messageRest } = message;\n        const role = message.role as 'assistant'; // this is what we expect; in theory it could be different which would make our types a slight lie but would be fine.\n        if (!role) {\n          throw new OpenAIError(`missing role for choice ${index}`);\n        }\n\n        if (function_call) {\n          const { arguments: args, name } = function_call;\n          if (args == null) {\n            throw new OpenAIError(`missing function_call.arguments for choice ${index}`);\n          }\n\n          if (!name) {\n            throw new OpenAIError(`missing function_call.name for choice ${index}`);\n          }\n\n          return {\n            ...choiceRest,\n            message: {\n              content,\n              function_call: { arguments: args, name },\n              role,\n              refusal: message.refusal ?? null,\n            },\n            finish_reason,\n            index,\n            logprobs,\n          };\n        }\n\n        if (tool_calls) {\n          return {\n            ...choiceRest,\n            index,\n            finish_reason,\n            logprobs,\n            message: {\n              ...messageRest,\n              role,\n              content,\n              refusal: message.refusal ?? null,\n              tool_calls: tool_calls.map((tool_call, i) => {\n                const { function: fn, type, id, ...toolRest } = tool_call;\n                const { arguments: args, name, ...fnRest } = fn || {};\n                if (id == null) {\n                  throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].id\\n${str(snapshot)}`);\n                }\n                if (type == null) {\n                  throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].type\\n${str(snapshot)}`);\n                }\n                if (name == null) {\n                  throw new OpenAIError(\n                    `missing choices[${index}].tool_calls[${i}].function.name\\n${str(snapshot)}`,\n                  );\n                }\n                if (args == null) {\n                  throw new OpenAIError(\n                    `missing choices[${index}].tool_calls[${i}].function.arguments\\n${str(snapshot)}`,\n                  );\n                }\n\n                return { ...toolRest, id, type, function: { ...fnRest, name, arguments: args } };\n              }),\n            },\n          };\n        }\n        return {\n          ...choiceRest,\n          message: { ...messageRest, content, role, refusal: message.refusal ?? null },\n          finish_reason,\n          index,\n          logprobs,\n        };\n      },\n    ),\n    created,\n    model,\n    object: 'chat.completion',\n    ...(system_fingerprint ? { system_fingerprint } : {}),\n  };\n\n  return maybeParseChatCompletion(completion, params);\n}\n\nfunction str(x: unknown) {\n  return JSON.stringify(x);\n}\n\n/**\n * Represents a streamed chunk of a chat completion response returned by model,\n * based on the provided input.\n */\nexport interface ChatCompletionSnapshot {\n  /**\n   * A unique identifier for the chat completion.\n   */\n  id: string;\n\n  /**\n   * A list of chat completion choices. Can be more than one if `n` is greater\n   * than 1.\n   */\n  choices: Array<ChatCompletionSnapshot.Choice>;\n\n  /**\n   * The Unix timestamp (in seconds) of when the chat completion was created.\n   */\n  created: number;\n\n  /**\n   * The model to generate the completion.\n   */\n  model: string;\n\n  // Note we do not include an \"object\" type on the snapshot,\n  // because the object is not a valid \"chat.completion\" until finalized.\n  // object: 'chat.completion';\n\n  /**\n   * This fingerprint represents the backend configuration that the model runs with.\n   *\n   * Can be used in conjunction with the `seed` request parameter to understand when\n   * backend changes have been made that might impact determinism.\n   */\n  system_fingerprint?: string;\n}\n\nexport namespace ChatCompletionSnapshot {\n  export interface Choice {\n    /**\n     * A chat completion delta generated by streamed model responses.\n     */\n    message: Choice.Message;\n\n    /**\n     * The reason the model stopped generating tokens. This will be `stop` if the model\n     * hit a natural stop point or a provided stop sequence, `length` if the maximum\n     * number of tokens specified in the request was reached, `content_filter` if\n     * content was omitted due to a flag from our content filters, or `function_call`\n     * if the model called a function.\n     */\n    finish_reason: ChatCompletion.Choice['finish_reason'] | null;\n\n    /**\n     * Log probability information for the choice.\n     */\n    logprobs: ChatCompletion.Choice.Logprobs | null;\n\n    /**\n     * The index of the choice in the list of choices.\n     */\n    index: number;\n  }\n\n  export namespace Choice {\n    /**\n     * A chat completion delta generated by streamed model responses.\n     */\n    export interface Message {\n      /**\n       * The contents of the chunk message.\n       */\n      content?: string | null;\n\n      refusal?: string | null;\n\n      parsed?: unknown | null;\n\n      /**\n       * The name and arguments of a function that should be called, as generated by the\n       * model.\n       */\n      function_call?: Message.FunctionCall;\n\n      tool_calls?: Array<Message.ToolCall>;\n\n      /**\n       * The role of the author of this message.\n       */\n      role?: ChatCompletionRole;\n    }\n\n    export namespace Message {\n      export interface ToolCall {\n        /**\n         * The ID of the tool call.\n         */\n        id: string;\n\n        function: ToolCall.Function;\n\n        /**\n         * The type of the tool.\n         */\n        type: 'function';\n      }\n\n      export namespace ToolCall {\n        export interface Function {\n          /**\n           * The arguments to call the function with, as generated by the model in JSON\n           * format. Note that the model does not always generate valid JSON, and may\n           * hallucinate parameters not defined by your function schema. Validate the\n           * arguments in your code before calling your function.\n           */\n          arguments: string;\n\n          parsed_arguments?: unknown;\n\n          /**\n           * The name of the function to call.\n           */\n          name: string;\n        }\n      }\n\n      /**\n       * The name and arguments of a function that should be called, as generated by the\n       * model.\n       */\n      export interface FunctionCall {\n        /**\n         * The arguments to call the function with, as generated by the model in JSON\n         * format. Note that the model does not always generate valid JSON, and may\n         * hallucinate parameters not defined by your function schema. Validate the\n         * arguments in your code before calling your function.\n         */\n        arguments?: string;\n\n        /**\n         * The name of the function to call.\n         */\n        name?: string;\n      }\n    }\n  }\n}\n\ntype AssertIsEmpty<T extends {}> = keyof T extends never ? T : never;\n\n/**\n * Ensures the given argument is an empty object, useful for\n * asserting that all known properties on an object have been\n * destructured.\n */\nfunction assertIsEmpty<T extends {}>(obj: AssertIsEmpty<T>): asserts obj is AssertIsEmpty<T> {\n  return;\n}\n\nfunction assertNever(_x: never) {}\n"
  },
  {
    "path": "src/lib/ChatCompletionStreamingRunner.ts",
    "content": "import {\n  type ChatCompletionChunk,\n  type ChatCompletionCreateParamsStreaming,\n} from '../resources/chat/completions';\nimport { RunnerOptions, type AbstractChatCompletionRunnerEvents } from './AbstractChatCompletionRunner';\nimport { type ReadableStream } from '../internal/shim-types';\nimport { RunnableTools, type BaseFunctionsArgs } from './RunnableFunction';\nimport { ChatCompletionSnapshot, ChatCompletionStream } from './ChatCompletionStream';\nimport OpenAI from '../index';\nimport { AutoParseableTool } from '../lib/parser';\n\nexport interface ChatCompletionStreamEvents extends AbstractChatCompletionRunnerEvents {\n  content: (contentDelta: string, contentSnapshot: string) => void;\n  chunk: (chunk: ChatCompletionChunk, snapshot: ChatCompletionSnapshot) => void;\n}\n\nexport type ChatCompletionStreamingToolRunnerParams<FunctionsArgs extends BaseFunctionsArgs> = Omit<\n  ChatCompletionCreateParamsStreaming,\n  'tools'\n> & {\n  tools: RunnableTools<FunctionsArgs> | AutoParseableTool<any, true>[];\n};\n\nexport class ChatCompletionStreamingRunner<ParsedT = null>\n  extends ChatCompletionStream<ParsedT>\n  implements AsyncIterable<ChatCompletionChunk>\n{\n  static override fromReadableStream(stream: ReadableStream): ChatCompletionStreamingRunner<null> {\n    const runner = new ChatCompletionStreamingRunner(null);\n    runner._run(() => runner._fromReadableStream(stream));\n    return runner;\n  }\n\n  static runTools<T extends (string | object)[], ParsedT = null>(\n    client: OpenAI,\n    params: ChatCompletionStreamingToolRunnerParams<T>,\n    options?: RunnerOptions,\n  ): ChatCompletionStreamingRunner<ParsedT> {\n    const runner = new ChatCompletionStreamingRunner<ParsedT>(\n      // @ts-expect-error TODO these types are incompatible\n      params,\n    );\n    const opts = {\n      ...options,\n      headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'runTools' },\n    };\n    runner._run(() => runner._runTools(client, params, opts));\n    return runner;\n  }\n}\n"
  },
  {
    "path": "src/lib/EventEmitter.ts",
    "content": "type EventListener<Events, EventType extends keyof Events> = Events[EventType];\n\ntype EventListeners<Events, EventType extends keyof Events> = Array<{\n  listener: EventListener<Events, EventType>;\n  once?: boolean;\n}>;\n\nexport type EventParameters<Events, EventType extends keyof Events> = {\n  [Event in EventType]: EventListener<Events, EventType> extends (...args: infer P) => any ? P : never;\n}[EventType];\n\nexport class EventEmitter<EventTypes extends Record<string, (...args: any) => any>> {\n  #listeners: {\n    [Event in keyof EventTypes]?: EventListeners<EventTypes, Event>;\n  } = {};\n\n  /**\n   * Adds the listener function to the end of the listeners array for the event.\n   * No checks are made to see if the listener has already been added. Multiple calls passing\n   * the same combination of event and listener will result in the listener being added, and\n   * called, multiple times.\n   * @returns this, so that calls can be chained\n   */\n  on<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n    const listeners: EventListeners<EventTypes, Event> =\n      this.#listeners[event] || (this.#listeners[event] = []);\n    listeners.push({ listener });\n    return this;\n  }\n\n  /**\n   * Removes the specified listener from the listener array for the event.\n   * off() will remove, at most, one instance of a listener from the listener array. If any single\n   * listener has been added multiple times to the listener array for the specified event, then\n   * off() must be called multiple times to remove each instance.\n   * @returns this, so that calls can be chained\n   */\n  off<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n    const listeners = this.#listeners[event];\n    if (!listeners) return this;\n    const index = listeners.findIndex((l) => l.listener === listener);\n    if (index >= 0) listeners.splice(index, 1);\n    return this;\n  }\n\n  /**\n   * Adds a one-time listener function for the event. The next time the event is triggered,\n   * this listener is removed and then invoked.\n   * @returns this, so that calls can be chained\n   */\n  once<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n    const listeners: EventListeners<EventTypes, Event> =\n      this.#listeners[event] || (this.#listeners[event] = []);\n    listeners.push({ listener, once: true });\n    return this;\n  }\n\n  /**\n   * This is similar to `.once()`, but returns a Promise that resolves the next time\n   * the event is triggered, instead of calling a listener callback.\n   * @returns a Promise that resolves the next time given event is triggered,\n   * or rejects if an error is emitted.  (If you request the 'error' event,\n   * returns a promise that resolves with the error).\n   *\n   * Example:\n   *\n   *   const message = await stream.emitted('message') // rejects if the stream errors\n   */\n  emitted<Event extends keyof EventTypes>(\n    event: Event,\n  ): Promise<\n    EventParameters<EventTypes, Event> extends [infer Param] ? Param\n    : EventParameters<EventTypes, Event> extends [] ? void\n    : EventParameters<EventTypes, Event>\n  > {\n    return new Promise((resolve, reject) => {\n      // TODO: handle errors\n      this.once(event, resolve as any);\n    });\n  }\n\n  protected _emit<Event extends keyof EventTypes>(\n    this: EventEmitter<EventTypes>,\n    event: Event,\n    ...args: EventParameters<EventTypes, Event>\n  ) {\n    const listeners: EventListeners<EventTypes, Event> | undefined = this.#listeners[event];\n    if (listeners) {\n      this.#listeners[event] = listeners.filter((l) => !l.once) as any;\n      listeners.forEach(({ listener }: any) => listener(...(args as any)));\n    }\n  }\n\n  protected _hasListener(event: keyof EventTypes): boolean {\n    const listeners = this.#listeners[event];\n    return listeners && listeners.length > 0;\n  }\n}\n"
  },
  {
    "path": "src/lib/EventStream.ts",
    "content": "import { APIUserAbortError, OpenAIError } from '../error';\n\nexport class EventStream<EventTypes extends BaseEvents> {\n  controller: AbortController = new AbortController();\n\n  #connectedPromise: Promise<void>;\n  #resolveConnectedPromise: () => void = () => {};\n  #rejectConnectedPromise: (error: OpenAIError) => void = () => {};\n\n  #endPromise: Promise<void>;\n  #resolveEndPromise: () => void = () => {};\n  #rejectEndPromise: (error: OpenAIError) => void = () => {};\n\n  #listeners: {\n    [Event in keyof EventTypes]?: EventListeners<EventTypes, Event>;\n  } = {};\n\n  #ended = false;\n  #errored = false;\n  #aborted = false;\n  #catchingPromiseCreated = false;\n\n  constructor() {\n    this.#connectedPromise = new Promise<void>((resolve, reject) => {\n      this.#resolveConnectedPromise = resolve;\n      this.#rejectConnectedPromise = reject;\n    });\n\n    this.#endPromise = new Promise<void>((resolve, reject) => {\n      this.#resolveEndPromise = resolve;\n      this.#rejectEndPromise = reject;\n    });\n\n    // Don't let these promises cause unhandled rejection errors.\n    // we will manually cause an unhandled rejection error later\n    // if the user hasn't registered any error listener or called\n    // any promise-returning method.\n    this.#connectedPromise.catch(() => {});\n    this.#endPromise.catch(() => {});\n  }\n\n  protected _run(this: EventStream<EventTypes>, executor: () => Promise<any>) {\n    // Unfortunately if we call `executor()` immediately we get runtime errors about\n    // references to `this` before the `super()` constructor call returns.\n    setTimeout(() => {\n      executor().then(() => {\n        this._emitFinal();\n        this._emit('end');\n      }, this.#handleError.bind(this));\n    }, 0);\n  }\n\n  protected _connected(this: EventStream<EventTypes>) {\n    if (this.ended) return;\n    this.#resolveConnectedPromise();\n    this._emit('connect');\n  }\n\n  get ended(): boolean {\n    return this.#ended;\n  }\n\n  get errored(): boolean {\n    return this.#errored;\n  }\n\n  get aborted(): boolean {\n    return this.#aborted;\n  }\n\n  abort() {\n    this.controller.abort();\n  }\n\n  /**\n   * Adds the listener function to the end of the listeners array for the event.\n   * No checks are made to see if the listener has already been added. Multiple calls passing\n   * the same combination of event and listener will result in the listener being added, and\n   * called, multiple times.\n   * @returns this ChatCompletionStream, so that calls can be chained\n   */\n  on<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n    const listeners: EventListeners<EventTypes, Event> =\n      this.#listeners[event] || (this.#listeners[event] = []);\n    listeners.push({ listener });\n    return this;\n  }\n\n  /**\n   * Removes the specified listener from the listener array for the event.\n   * off() will remove, at most, one instance of a listener from the listener array. If any single\n   * listener has been added multiple times to the listener array for the specified event, then\n   * off() must be called multiple times to remove each instance.\n   * @returns this ChatCompletionStream, so that calls can be chained\n   */\n  off<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n    const listeners = this.#listeners[event];\n    if (!listeners) return this;\n    const index = listeners.findIndex((l) => l.listener === listener);\n    if (index >= 0) listeners.splice(index, 1);\n    return this;\n  }\n\n  /**\n   * Adds a one-time listener function for the event. The next time the event is triggered,\n   * this listener is removed and then invoked.\n   * @returns this ChatCompletionStream, so that calls can be chained\n   */\n  once<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n    const listeners: EventListeners<EventTypes, Event> =\n      this.#listeners[event] || (this.#listeners[event] = []);\n    listeners.push({ listener, once: true });\n    return this;\n  }\n\n  /**\n   * This is similar to `.once()`, but returns a Promise that resolves the next time\n   * the event is triggered, instead of calling a listener callback.\n   * @returns a Promise that resolves the next time given event is triggered,\n   * or rejects if an error is emitted.  (If you request the 'error' event,\n   * returns a promise that resolves with the error).\n   *\n   * Example:\n   *\n   *   const message = await stream.emitted('message') // rejects if the stream errors\n   */\n  emitted<Event extends keyof EventTypes>(\n    event: Event,\n  ): Promise<\n    EventParameters<EventTypes, Event> extends [infer Param] ? Param\n    : EventParameters<EventTypes, Event> extends [] ? void\n    : EventParameters<EventTypes, Event>\n  > {\n    return new Promise((resolve, reject) => {\n      this.#catchingPromiseCreated = true;\n      if (event !== 'error') this.once('error', reject);\n      this.once(event, resolve as any);\n    });\n  }\n\n  async done(): Promise<void> {\n    this.#catchingPromiseCreated = true;\n    await this.#endPromise;\n  }\n\n  #handleError(this: EventStream<EventTypes>, error: unknown) {\n    this.#errored = true;\n    if (error instanceof Error && error.name === 'AbortError') {\n      error = new APIUserAbortError();\n    }\n    if (error instanceof APIUserAbortError) {\n      this.#aborted = true;\n      return this._emit('abort', error);\n    }\n    if (error instanceof OpenAIError) {\n      return this._emit('error', error);\n    }\n    if (error instanceof Error) {\n      const openAIError: OpenAIError = new OpenAIError(error.message);\n      // @ts-ignore\n      openAIError.cause = error;\n      return this._emit('error', openAIError);\n    }\n    return this._emit('error', new OpenAIError(String(error)));\n  }\n\n  _emit<Event extends keyof BaseEvents>(event: Event, ...args: EventParameters<BaseEvents, Event>): void;\n  _emit<Event extends keyof EventTypes>(event: Event, ...args: EventParameters<EventTypes, Event>): void;\n  _emit<Event extends keyof EventTypes>(\n    this: EventStream<EventTypes>,\n    event: Event,\n    ...args: EventParameters<EventTypes, Event>\n  ) {\n    // make sure we don't emit any events after end\n    if (this.#ended) {\n      return;\n    }\n\n    if (event === 'end') {\n      this.#ended = true;\n      this.#resolveEndPromise();\n    }\n\n    const listeners: EventListeners<EventTypes, Event> | undefined = this.#listeners[event];\n    if (listeners) {\n      this.#listeners[event] = listeners.filter((l) => !l.once) as any;\n      listeners.forEach(({ listener }: any) => listener(...(args as any)));\n    }\n\n    if (event === 'abort') {\n      const error = args[0] as APIUserAbortError;\n      if (!this.#catchingPromiseCreated && !listeners?.length) {\n        Promise.reject(error);\n      }\n      this.#rejectConnectedPromise(error);\n      this.#rejectEndPromise(error);\n      this._emit('end');\n      return;\n    }\n\n    if (event === 'error') {\n      // NOTE: _emit('error', error) should only be called from #handleError().\n\n      const error = args[0] as OpenAIError;\n      if (!this.#catchingPromiseCreated && !listeners?.length) {\n        // Trigger an unhandled rejection if the user hasn't registered any error handlers.\n        // If you are seeing stack traces here, make sure to handle errors via either:\n        // - runner.on('error', () => ...)\n        // - await runner.done()\n        // - await runner.finalChatCompletion()\n        // - etc.\n        Promise.reject(error);\n      }\n      this.#rejectConnectedPromise(error);\n      this.#rejectEndPromise(error);\n      this._emit('end');\n    }\n  }\n\n  protected _emitFinal(): void {}\n}\n\ntype EventListener<Events, EventType extends keyof Events> = Events[EventType];\n\ntype EventListeners<Events, EventType extends keyof Events> = Array<{\n  listener: EventListener<Events, EventType>;\n  once?: boolean;\n}>;\n\nexport type EventParameters<Events, EventType extends keyof Events> = {\n  [Event in EventType]: EventListener<Events, EventType> extends (...args: infer P) => any ? P : never;\n}[EventType];\n\nexport interface BaseEvents {\n  connect: () => void;\n  error: (error: OpenAIError) => void;\n  abort: (error: APIUserAbortError) => void;\n  end: () => void;\n}\n"
  },
  {
    "path": "src/lib/ResponsesParser.ts",
    "content": "import { OpenAIError } from '../error';\nimport type { ChatCompletionTool } from '../resources/chat/completions';\nimport {\n  ResponseTextConfig,\n  type FunctionTool,\n  type ParsedContent,\n  type ParsedResponse,\n  type ParsedResponseFunctionToolCall,\n  type ParsedResponseOutputItem,\n  type Response,\n  type ResponseCreateParamsBase,\n  type ResponseCreateParamsNonStreaming,\n  type ResponseFunctionToolCall,\n  type Tool,\n} from '../resources/responses/responses';\nimport { type AutoParseableTextFormat, isAutoParsableResponseFormat } from '../lib/parser';\n\nexport type ParseableToolsParams = Array<Tool> | ChatCompletionTool | null;\n\nexport type ResponseCreateParamsWithTools = ResponseCreateParamsBase & {\n  tools?: ParseableToolsParams;\n};\n\ntype TextConfigParams = { text?: ResponseTextConfig };\n\nexport type ExtractParsedContentFromParams<Params extends TextConfigParams> =\n  NonNullable<Params['text']>['format'] extends AutoParseableTextFormat<infer P> ? P : null;\n\nexport function maybeParseResponse<\n  Params extends ResponseCreateParamsBase | null,\n  ParsedT = Params extends null ? null : ExtractParsedContentFromParams<NonNullable<Params>>,\n>(response: Response, params: Params): ParsedResponse<ParsedT> {\n  if (!params || !hasAutoParseableInput(params)) {\n    return {\n      ...response,\n      output_parsed: null,\n      output: response.output.map((item) => {\n        if (item.type === 'function_call') {\n          return {\n            ...item,\n            parsed_arguments: null,\n          };\n        }\n\n        if (item.type === 'message') {\n          return {\n            ...item,\n            content: item.content.map((content) => ({\n              ...content,\n              parsed: null,\n            })),\n          };\n        } else {\n          return item;\n        }\n      }),\n    };\n  }\n\n  return parseResponse(response, params);\n}\n\nexport function parseResponse<\n  Params extends ResponseCreateParamsBase,\n  ParsedT = ExtractParsedContentFromParams<Params>,\n>(response: Response, params: Params): ParsedResponse<ParsedT> {\n  const output: Array<ParsedResponseOutputItem<ParsedT>> = response.output.map(\n    (item): ParsedResponseOutputItem<ParsedT> => {\n      if (item.type === 'function_call') {\n        return {\n          ...item,\n          parsed_arguments: parseToolCall(params, item),\n        };\n      }\n      if (item.type === 'message') {\n        const content: Array<ParsedContent<ParsedT>> = item.content.map((content) => {\n          if (content.type === 'output_text') {\n            return {\n              ...content,\n              parsed: parseTextFormat(params, content.text),\n            };\n          }\n\n          return content;\n        });\n\n        return {\n          ...item,\n          content,\n        };\n      }\n\n      return item;\n    },\n  );\n\n  const parsed: Omit<ParsedResponse<ParsedT>, 'output_parsed'> = Object.assign({}, response, { output });\n  if (!Object.getOwnPropertyDescriptor(response, 'output_text')) {\n    addOutputText(parsed);\n  }\n\n  Object.defineProperty(parsed, 'output_parsed', {\n    enumerable: true,\n    get() {\n      for (const output of parsed.output) {\n        if (output.type !== 'message') {\n          continue;\n        }\n\n        for (const content of output.content) {\n          if (content.type === 'output_text' && content.parsed !== null) {\n            return content.parsed;\n          }\n        }\n      }\n\n      return null;\n    },\n  });\n\n  return parsed as ParsedResponse<ParsedT>;\n}\n\nfunction parseTextFormat<\n  Params extends ResponseCreateParamsBase,\n  ParsedT = ExtractParsedContentFromParams<Params>,\n>(params: Params, content: string): ParsedT | null {\n  if (params.text?.format?.type !== 'json_schema') {\n    return null;\n  }\n\n  if ('$parseRaw' in params.text?.format) {\n    const text_format = params.text?.format as unknown as AutoParseableTextFormat<ParsedT>;\n    return text_format.$parseRaw(content);\n  }\n\n  return JSON.parse(content);\n}\n\nexport function hasAutoParseableInput(params: ResponseCreateParamsWithTools): boolean {\n  if (isAutoParsableResponseFormat(params.text?.format)) {\n    return true;\n  }\n\n  return false;\n}\n\ntype ToolOptions = {\n  name: string;\n  arguments: any;\n  function?: ((args: any) => any) | undefined;\n};\n\nexport type AutoParseableResponseTool<\n  OptionsT extends ToolOptions,\n  HasFunction = OptionsT['function'] extends Function ? true : false,\n> = FunctionTool & {\n  __arguments: OptionsT['arguments']; // type-level only\n  __name: OptionsT['name']; // type-level only\n\n  $brand: 'auto-parseable-tool';\n  $callback: ((args: OptionsT['arguments']) => any) | undefined;\n  $parseRaw(args: string): OptionsT['arguments'];\n};\n\nexport function makeParseableResponseTool<OptionsT extends ToolOptions>(\n  tool: FunctionTool,\n  {\n    parser,\n    callback,\n  }: {\n    parser: (content: string) => OptionsT['arguments'];\n    callback: ((args: any) => any) | undefined;\n  },\n): AutoParseableResponseTool<OptionsT['arguments']> {\n  const obj = { ...tool };\n\n  Object.defineProperties(obj, {\n    $brand: {\n      value: 'auto-parseable-tool',\n      enumerable: false,\n    },\n    $parseRaw: {\n      value: parser,\n      enumerable: false,\n    },\n    $callback: {\n      value: callback,\n      enumerable: false,\n    },\n  });\n\n  return obj as AutoParseableResponseTool<OptionsT['arguments']>;\n}\n\nexport function isAutoParsableTool(tool: any): tool is AutoParseableResponseTool<any> {\n  return tool?.['$brand'] === 'auto-parseable-tool';\n}\n\nfunction getInputToolByName(input_tools: Array<Tool>, name: string): FunctionTool | undefined {\n  return input_tools.find((tool) => tool.type === 'function' && tool.name === name) as\n    | FunctionTool\n    | undefined;\n}\n\nfunction parseToolCall<Params extends ResponseCreateParamsBase>(\n  params: Params,\n  toolCall: ResponseFunctionToolCall,\n): ParsedResponseFunctionToolCall {\n  const inputTool = getInputToolByName(params.tools ?? [], toolCall.name);\n\n  return {\n    ...toolCall,\n    ...toolCall,\n    parsed_arguments:\n      isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCall.arguments)\n      : inputTool?.strict ? JSON.parse(toolCall.arguments)\n      : null,\n  };\n}\n\nexport function shouldParseToolCall(\n  params: ResponseCreateParamsNonStreaming | null | undefined,\n  toolCall: ResponseFunctionToolCall,\n): boolean {\n  if (!params) {\n    return false;\n  }\n\n  const inputTool = getInputToolByName(params.tools ?? [], toolCall.name);\n  return isAutoParsableTool(inputTool) || inputTool?.strict || false;\n}\n\nexport function validateInputTools(tools: ChatCompletionTool[] | undefined) {\n  for (const tool of tools ?? []) {\n    if (tool.type !== 'function') {\n      throw new OpenAIError(\n        `Currently only \\`function\\` tool types support auto-parsing; Received \\`${tool.type}\\``,\n      );\n    }\n\n    if (tool.function.strict !== true) {\n      throw new OpenAIError(\n        `The \\`${tool.function.name}\\` tool is not marked with \\`strict: true\\`. Only strict function tools can be auto-parsed`,\n      );\n    }\n  }\n}\n\nexport function addOutputText(rsp: Response): void {\n  const texts: string[] = [];\n  for (const output of rsp.output) {\n    if (output.type !== 'message') {\n      continue;\n    }\n\n    for (const content of output.content) {\n      if (content.type === 'output_text') {\n        texts.push(content.text);\n      }\n    }\n  }\n\n  rsp.output_text = texts.join('');\n}\n"
  },
  {
    "path": "src/lib/RunnableFunction.ts",
    "content": "import { type ChatCompletionRunner } from './ChatCompletionRunner';\nimport { type ChatCompletionStreamingRunner } from './ChatCompletionStreamingRunner';\nimport { JSONSchema } from './jsonschema';\n\ntype PromiseOrValue<T> = T | Promise<T>;\n\nexport type RunnableFunctionWithParse<Args extends object> = {\n  /**\n   * @param args the return value from `parse`.\n   * @param runner the runner evaluating this callback.\n   * @returns a string to send back to OpenAI.\n   */\n  function: (\n    args: Args,\n    runner: ChatCompletionRunner<unknown> | ChatCompletionStreamingRunner<unknown>,\n  ) => PromiseOrValue<unknown>;\n  /**\n   * @param input the raw args from the OpenAI function call.\n   * @returns the parsed arguments to pass to `function`\n   */\n  parse: (input: string) => PromiseOrValue<Args>;\n  /**\n   * The parameters the function accepts, describes as a JSON Schema object.\n   */\n  parameters: JSONSchema;\n  /**\n   * A description of what the function does, used by the model to choose when and how to call the function.\n   */\n  description: string;\n  /**\n   * The name of the function to be called. Will default to function.name if omitted.\n   */\n  name?: string | undefined;\n  strict?: boolean | undefined;\n};\n\nexport type RunnableFunctionWithoutParse = {\n  /**\n   * @param args the raw args from the OpenAI function call.\n   * @returns a string to send back to OpenAI\n   */\n  function: (\n    args: string,\n    runner: ChatCompletionRunner<unknown> | ChatCompletionStreamingRunner<unknown>,\n  ) => PromiseOrValue<unknown>;\n  /**\n   * The parameters the function accepts, describes as a JSON Schema object.\n   */\n  parameters: JSONSchema;\n  /**\n   * A description of what the function does, used by the model to choose when and how to call the function.\n   */\n  description: string;\n  /**\n   * The name of the function to be called. Will default to function.name if omitted.\n   */\n  name?: string | undefined;\n  strict?: boolean | undefined;\n};\n\nexport type RunnableFunction<Args extends object | string> =\n  Args extends string ? RunnableFunctionWithoutParse\n  : Args extends object ? RunnableFunctionWithParse<Args>\n  : never;\n\nexport type RunnableToolFunction<Args extends object | string> =\n  Args extends string ? RunnableToolFunctionWithoutParse\n  : Args extends object ? RunnableToolFunctionWithParse<Args>\n  : never;\n\nexport type RunnableToolFunctionWithoutParse = {\n  type: 'function';\n  function: RunnableFunctionWithoutParse;\n};\nexport type RunnableToolFunctionWithParse<Args extends object> = {\n  type: 'function';\n  function: RunnableFunctionWithParse<Args>;\n};\n\nexport function isRunnableFunctionWithParse<Args extends object>(\n  fn: any,\n): fn is RunnableFunctionWithParse<Args> {\n  return typeof (fn as any).parse === 'function';\n}\n\nexport type BaseFunctionsArgs = readonly (object | string)[];\n\nexport type RunnableFunctions<FunctionsArgs extends BaseFunctionsArgs> =\n  [any[]] extends [FunctionsArgs] ? readonly RunnableFunction<any>[]\n  : {\n      [Index in keyof FunctionsArgs]: Index extends number ? RunnableFunction<FunctionsArgs[Index]>\n      : FunctionsArgs[Index];\n    };\n\nexport type RunnableTools<FunctionsArgs extends BaseFunctionsArgs> =\n  [any[]] extends [FunctionsArgs] ? readonly RunnableToolFunction<any>[]\n  : {\n      [Index in keyof FunctionsArgs]: Index extends number ? RunnableToolFunction<FunctionsArgs[Index]>\n      : FunctionsArgs[Index];\n    };\n\n/**\n * This is helper class for passing a `function` and `parse` where the `function`\n * argument type matches the `parse` return type.\n */\nexport class ParsingToolFunction<Args extends object> {\n  type: 'function';\n  function: RunnableFunctionWithParse<Args>;\n\n  constructor(input: RunnableFunctionWithParse<Args>) {\n    this.type = 'function';\n    this.function = input;\n  }\n}\n"
  },
  {
    "path": "src/lib/Util.ts",
    "content": "/**\n * Like `Promise.allSettled()` but throws an error if any promises are rejected.\n */\nexport const allSettledWithThrow = async <R>(promises: Promise<R>[]): Promise<R[]> => {\n  const results = await Promise.allSettled(promises);\n  const rejected = results.filter((result): result is PromiseRejectedResult => result.status === 'rejected');\n  if (rejected.length) {\n    for (const result of rejected) {\n      console.error(result.reason);\n    }\n\n    throw new Error(`${rejected.length} promise(s) failed - see the above errors`);\n  }\n\n  // Note: TS was complaining about using `.filter().map()` here for some reason\n  const values: R[] = [];\n  for (const result of results) {\n    if (result.status === 'fulfilled') {\n      values.push(result.value);\n    }\n  }\n  return values;\n};\n"
  },
  {
    "path": "src/lib/chatCompletionUtils.ts",
    "content": "import {\n  type ChatCompletionAssistantMessageParam,\n  type ChatCompletionMessageParam,\n  type ChatCompletionToolMessageParam,\n} from '../resources';\n\nexport const isAssistantMessage = (\n  message: ChatCompletionMessageParam | null | undefined,\n): message is ChatCompletionAssistantMessageParam => {\n  return message?.role === 'assistant';\n};\n\nexport const isToolMessage = (\n  message: ChatCompletionMessageParam | null | undefined,\n): message is ChatCompletionToolMessageParam => {\n  return message?.role === 'tool';\n};\n\nexport function isPresent<T>(obj: T | null | undefined): obj is T {\n  return obj != null;\n}\n"
  },
  {
    "path": "src/lib/jsonschema.ts",
    "content": "// File mostly copied from @types/json-schema, but stripped down a bit for brevity\n// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/817274f3280152ba2929a6067c93df8b34c4c9aa/types/json-schema/index.d.ts\n//\n// ==================================================================================================\n// JSON Schema Draft 07\n// ==================================================================================================\n// https://tools.ietf.org/html/draft-handrews-json-schema-validation-01\n// --------------------------------------------------------------------------------------------------\n\n/**\n * Primitive type\n * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1\n */\nexport type JSONSchemaTypeName =\n  | ({} & string)\n  | 'string'\n  | 'number'\n  | 'integer'\n  | 'boolean'\n  | 'object'\n  | 'array'\n  | 'null';\n\n/**\n * Primitive type\n * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1\n */\nexport type JSONSchemaType =\n  | string //\n  | number\n  | boolean\n  | JSONSchemaObject\n  | JSONSchemaArray\n  | null;\n\n// Workaround for infinite type recursion\nexport interface JSONSchemaObject {\n  [key: string]: JSONSchemaType;\n}\n\n// Workaround for infinite type recursion\n// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540\nexport interface JSONSchemaArray extends Array<JSONSchemaType> {}\n\n/**\n * Meta schema\n *\n * Recommended values:\n * - 'http://json-schema.org/schema#'\n * - 'http://json-schema.org/hyper-schema#'\n * - 'http://json-schema.org/draft-07/schema#'\n * - 'http://json-schema.org/draft-07/hyper-schema#'\n *\n * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5\n */\nexport type JSONSchemaVersion = string;\n\n/**\n * JSON Schema v7\n * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01\n */\nexport type JSONSchemaDefinition = JSONSchema | boolean;\nexport interface JSONSchema {\n  $id?: string | undefined;\n  $comment?: string | undefined;\n\n  /**\n   * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1\n   */\n  type?: JSONSchemaTypeName | JSONSchemaTypeName[] | undefined;\n  enum?: JSONSchemaType[] | undefined;\n  const?: JSONSchemaType | undefined;\n\n  /**\n   * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2\n   */\n  multipleOf?: number | undefined;\n  maximum?: number | undefined;\n  exclusiveMaximum?: number | undefined;\n  minimum?: number | undefined;\n  exclusiveMinimum?: number | undefined;\n\n  /**\n   * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3\n   */\n  maxLength?: number | undefined;\n  minLength?: number | undefined;\n  pattern?: string | undefined;\n\n  /**\n   * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4\n   */\n  items?: JSONSchemaDefinition | JSONSchemaDefinition[] | undefined;\n  additionalItems?: JSONSchemaDefinition | undefined;\n  maxItems?: number | undefined;\n  minItems?: number | undefined;\n  uniqueItems?: boolean | undefined;\n  contains?: JSONSchemaDefinition | undefined;\n\n  /**\n   * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5\n   */\n  maxProperties?: number | undefined;\n  minProperties?: number | undefined;\n  required?: string[] | undefined;\n  properties?:\n    | {\n        [key: string]: JSONSchemaDefinition;\n      }\n    | undefined;\n  patternProperties?:\n    | {\n        [key: string]: JSONSchemaDefinition;\n      }\n    | undefined;\n  additionalProperties?: JSONSchemaDefinition | undefined;\n  propertyNames?: JSONSchemaDefinition | undefined;\n\n  /**\n   * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6\n   */\n  if?: JSONSchemaDefinition | undefined;\n  then?: JSONSchemaDefinition | undefined;\n  else?: JSONSchemaDefinition | undefined;\n\n  /**\n   * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7\n   */\n  allOf?: JSONSchemaDefinition[] | undefined;\n  anyOf?: JSONSchemaDefinition[] | undefined;\n  oneOf?: JSONSchemaDefinition[] | undefined;\n  not?: JSONSchemaDefinition | undefined;\n\n  /**\n   * @see https://json-schema.org/draft/2020-12/json-schema-core.html#section-8.2.4\n   */\n  $defs?:\n    | {\n        [key: string]: JSONSchemaDefinition;\n      }\n    | undefined;\n\n  /**\n   * @deprecated Use $defs instead (draft 2019-09+)\n   * @see https://tools.ietf.org/doc/html/draft-handrews-json-schema-validation-01#page-22\n   */\n  definitions?:\n    | {\n        [key: string]: JSONSchemaDefinition;\n      }\n    | undefined;\n\n  /**\n   * @see https://json-schema.org/draft/2020-12/json-schema-core#ref\n   */\n  $ref?: string | undefined;\n\n  /**\n   * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7\n   */\n  format?: string | undefined;\n\n  /**\n   * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10\n   */\n  title?: string | undefined;\n  description?: string | undefined;\n  default?: JSONSchemaType | undefined;\n  readOnly?: boolean | undefined;\n  writeOnly?: boolean | undefined;\n  examples?: JSONSchemaType | undefined;\n}\n"
  },
  {
    "path": "src/lib/parser.ts",
    "content": "import { ContentFilterFinishReasonError, LengthFinishReasonError, OpenAIError } from '../error';\nimport {\n  ChatCompletion,\n  ChatCompletionCreateParams,\n  ChatCompletionCreateParamsBase,\n  ChatCompletionFunctionTool,\n  ChatCompletionMessage,\n  ChatCompletionMessageFunctionToolCall,\n  ChatCompletionStreamingToolRunnerParams,\n  ChatCompletionStreamParams,\n  ChatCompletionToolRunnerParams,\n  ParsedChatCompletion,\n  ParsedChoice,\n  ParsedFunctionToolCall,\n} from '../resources/chat/completions';\nimport { type ResponseFormatTextJSONSchemaConfig } from '../resources/responses/responses';\nimport { ResponseFormatJSONSchema } from '../resources/shared';\n\ntype AnyChatCompletionCreateParams =\n  | ChatCompletionCreateParams\n  | ChatCompletionToolRunnerParams<any>\n  | ChatCompletionStreamingToolRunnerParams<any>\n  | ChatCompletionStreamParams;\n\ntype Unpacked<T> = T extends (infer U)[] ? U : T;\n\ntype ToolCall = Unpacked<ChatCompletionCreateParamsBase['tools']>;\n\nexport function isChatCompletionFunctionTool(tool: ToolCall): tool is ChatCompletionFunctionTool {\n  return tool !== undefined && 'function' in tool && tool.function !== undefined;\n}\n\nexport type ExtractParsedContentFromParams<Params extends AnyChatCompletionCreateParams> =\n  Params['response_format'] extends AutoParseableResponseFormat<infer P> ? P : null;\n\nexport type AutoParseableResponseFormat<ParsedT> = ResponseFormatJSONSchema & {\n  __output: ParsedT; // type-level only\n\n  $brand: 'auto-parseable-response-format';\n  $parseRaw(content: string): ParsedT;\n};\n\nexport function makeParseableResponseFormat<ParsedT>(\n  response_format: ResponseFormatJSONSchema,\n  parser: (content: string) => ParsedT,\n): AutoParseableResponseFormat<ParsedT> {\n  const obj = { ...response_format };\n\n  Object.defineProperties(obj, {\n    $brand: {\n      value: 'auto-parseable-response-format',\n      enumerable: false,\n    },\n    $parseRaw: {\n      value: parser,\n      enumerable: false,\n    },\n  });\n\n  return obj as AutoParseableResponseFormat<ParsedT>;\n}\n\nexport type AutoParseableTextFormat<ParsedT> = ResponseFormatTextJSONSchemaConfig & {\n  __output: ParsedT; // type-level only\n\n  $brand: 'auto-parseable-response-format';\n  $parseRaw(content: string): ParsedT;\n};\n\nexport function makeParseableTextFormat<ParsedT>(\n  response_format: ResponseFormatTextJSONSchemaConfig,\n  parser: (content: string) => ParsedT,\n): AutoParseableTextFormat<ParsedT> {\n  const obj = { ...response_format };\n\n  Object.defineProperties(obj, {\n    $brand: {\n      value: 'auto-parseable-response-format',\n      enumerable: false,\n    },\n    $parseRaw: {\n      value: parser,\n      enumerable: false,\n    },\n  });\n\n  return obj as AutoParseableTextFormat<ParsedT>;\n}\n\nexport function isAutoParsableResponseFormat<ParsedT>(\n  response_format: any,\n): response_format is AutoParseableResponseFormat<ParsedT> {\n  return response_format?.['$brand'] === 'auto-parseable-response-format';\n}\n\ntype ToolOptions = {\n  name: string;\n  arguments: any;\n  function?: ((args: any) => any) | undefined;\n};\n\nexport type AutoParseableTool<\n  OptionsT extends ToolOptions,\n  HasFunction = OptionsT['function'] extends Function ? true : false,\n> = ChatCompletionFunctionTool & {\n  __arguments: OptionsT['arguments']; // type-level only\n  __name: OptionsT['name']; // type-level only\n  __hasFunction: HasFunction; // type-level only\n\n  $brand: 'auto-parseable-tool';\n  $callback: ((args: OptionsT['arguments']) => any) | undefined;\n  $parseRaw(args: string): OptionsT['arguments'];\n};\n\nexport function makeParseableTool<OptionsT extends ToolOptions>(\n  tool: ChatCompletionFunctionTool,\n  {\n    parser,\n    callback,\n  }: {\n    parser: (content: string) => OptionsT['arguments'];\n    callback: ((args: any) => any) | undefined;\n  },\n): AutoParseableTool<OptionsT['arguments']> {\n  const obj = { ...tool };\n\n  Object.defineProperties(obj, {\n    $brand: {\n      value: 'auto-parseable-tool',\n      enumerable: false,\n    },\n    $parseRaw: {\n      value: parser,\n      enumerable: false,\n    },\n    $callback: {\n      value: callback,\n      enumerable: false,\n    },\n  });\n\n  return obj as AutoParseableTool<OptionsT['arguments']>;\n}\n\nexport function isAutoParsableTool(tool: any): tool is AutoParseableTool<any> {\n  return tool?.['$brand'] === 'auto-parseable-tool';\n}\n\nexport function maybeParseChatCompletion<\n  Params extends ChatCompletionCreateParams | null,\n  ParsedT = Params extends null ? null : ExtractParsedContentFromParams<NonNullable<Params>>,\n>(completion: ChatCompletion, params: Params): ParsedChatCompletion<ParsedT> {\n  if (!params || !hasAutoParseableInput(params)) {\n    return {\n      ...completion,\n      choices: completion.choices.map((choice) => {\n        assertToolCallsAreChatCompletionFunctionToolCalls(choice.message.tool_calls);\n\n        return {\n          ...choice,\n          message: {\n            ...choice.message,\n            parsed: null,\n            ...(choice.message.tool_calls ?\n              {\n                tool_calls: choice.message.tool_calls,\n              }\n            : undefined),\n          },\n        };\n      }),\n    } as ParsedChatCompletion<ParsedT>;\n  }\n\n  return parseChatCompletion(completion, params);\n}\n\nexport function parseChatCompletion<\n  Params extends ChatCompletionCreateParams,\n  ParsedT = ExtractParsedContentFromParams<Params>,\n>(completion: ChatCompletion, params: Params): ParsedChatCompletion<ParsedT> {\n  const choices: Array<ParsedChoice<ParsedT>> = completion.choices.map((choice): ParsedChoice<ParsedT> => {\n    if (choice.finish_reason === 'length') {\n      throw new LengthFinishReasonError();\n    }\n\n    if (choice.finish_reason === 'content_filter') {\n      throw new ContentFilterFinishReasonError();\n    }\n\n    assertToolCallsAreChatCompletionFunctionToolCalls(choice.message.tool_calls);\n\n    return {\n      ...choice,\n      message: {\n        ...choice.message,\n        ...(choice.message.tool_calls ?\n          {\n            tool_calls:\n              choice.message.tool_calls?.map((toolCall) => parseToolCall(params, toolCall)) ?? undefined,\n          }\n        : undefined),\n        parsed:\n          choice.message.content && !choice.message.refusal ?\n            parseResponseFormat(params, choice.message.content)\n          : null,\n      },\n    } as ParsedChoice<ParsedT>;\n  });\n\n  return { ...completion, choices };\n}\n\nfunction parseResponseFormat<\n  Params extends ChatCompletionCreateParams,\n  ParsedT = ExtractParsedContentFromParams<Params>,\n>(params: Params, content: string): ParsedT | null {\n  if (params.response_format?.type !== 'json_schema') {\n    return null;\n  }\n\n  if (params.response_format?.type === 'json_schema') {\n    if ('$parseRaw' in params.response_format) {\n      const response_format = params.response_format as AutoParseableResponseFormat<ParsedT>;\n\n      return response_format.$parseRaw(content);\n    }\n\n    return JSON.parse(content);\n  }\n\n  return null;\n}\n\nfunction parseToolCall<Params extends ChatCompletionCreateParams>(\n  params: Params,\n  toolCall: ChatCompletionMessageFunctionToolCall,\n): ParsedFunctionToolCall {\n  const inputTool = params.tools?.find(\n    (inputTool) =>\n      isChatCompletionFunctionTool(inputTool) && inputTool.function?.name === toolCall.function.name,\n  ) as ChatCompletionFunctionTool | undefined; // TS doesn't narrow based on isChatCompletionTool\n  return {\n    ...toolCall,\n    function: {\n      ...toolCall.function,\n      parsed_arguments:\n        isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCall.function.arguments)\n        : inputTool?.function.strict ? JSON.parse(toolCall.function.arguments)\n        : null,\n    },\n  };\n}\n\nexport function shouldParseToolCall(\n  params: ChatCompletionCreateParams | null | undefined,\n  toolCall: ChatCompletionMessageFunctionToolCall,\n): boolean {\n  if (!params || !('tools' in params) || !params.tools) {\n    return false;\n  }\n\n  const inputTool = params.tools?.find(\n    (inputTool) =>\n      isChatCompletionFunctionTool(inputTool) && inputTool.function?.name === toolCall.function.name,\n  );\n  return (\n    isChatCompletionFunctionTool(inputTool) &&\n    (isAutoParsableTool(inputTool) || inputTool?.function.strict || false)\n  );\n}\n\nexport function hasAutoParseableInput(params: AnyChatCompletionCreateParams): boolean {\n  if (isAutoParsableResponseFormat(params.response_format)) {\n    return true;\n  }\n\n  return (\n    params.tools?.some(\n      (t) => isAutoParsableTool(t) || (t.type === 'function' && t.function.strict === true),\n    ) ?? false\n  );\n}\n\nexport function assertToolCallsAreChatCompletionFunctionToolCalls(\n  toolCalls: ChatCompletionMessage['tool_calls'],\n): asserts toolCalls is ChatCompletionMessageFunctionToolCall[] {\n  for (const toolCall of toolCalls || []) {\n    if (toolCall.type !== 'function') {\n      throw new OpenAIError(\n        `Currently only \\`function\\` tool calls are supported; Received \\`${toolCall.type}\\``,\n      );\n    }\n  }\n}\n\nexport function validateInputTools(tools: ChatCompletionCreateParamsBase['tools']) {\n  for (const tool of tools ?? []) {\n    if (tool.type !== 'function') {\n      throw new OpenAIError(\n        `Currently only \\`function\\` tool types support auto-parsing; Received \\`${tool.type}\\``,\n      );\n    }\n\n    if (tool.function.strict !== true) {\n      throw new OpenAIError(\n        `The \\`${tool.function.name}\\` tool is not marked with \\`strict: true\\`. Only strict function tools can be auto-parsed`,\n      );\n    }\n  }\n}\n"
  },
  {
    "path": "src/lib/responses/EventTypes.ts",
    "content": "import {\n  ResponseAudioDeltaEvent,\n  ResponseAudioDoneEvent,\n  ResponseAudioTranscriptDeltaEvent,\n  ResponseAudioTranscriptDoneEvent,\n  ResponseCodeInterpreterCallCodeDeltaEvent,\n  ResponseCodeInterpreterCallCodeDoneEvent,\n  ResponseCodeInterpreterCallCompletedEvent,\n  ResponseCodeInterpreterCallInProgressEvent,\n  ResponseCodeInterpreterCallInterpretingEvent,\n  ResponseCompletedEvent,\n  ResponseContentPartAddedEvent,\n  ResponseContentPartDoneEvent,\n  ResponseCreatedEvent,\n  ResponseErrorEvent,\n  ResponseFailedEvent,\n  ResponseFileSearchCallCompletedEvent,\n  ResponseFileSearchCallInProgressEvent,\n  ResponseFileSearchCallSearchingEvent,\n  ResponseFunctionCallArgumentsDeltaEvent as RawResponseFunctionCallArgumentsDeltaEvent,\n  ResponseFunctionCallArgumentsDoneEvent,\n  ResponseInProgressEvent,\n  ResponseOutputItemAddedEvent,\n  ResponseOutputItemDoneEvent,\n  ResponseRefusalDeltaEvent,\n  ResponseRefusalDoneEvent,\n  ResponseTextDeltaEvent as RawResponseTextDeltaEvent,\n  ResponseTextDoneEvent,\n  ResponseIncompleteEvent,\n  ResponseWebSearchCallCompletedEvent,\n  ResponseWebSearchCallInProgressEvent,\n  ResponseWebSearchCallSearchingEvent,\n} from '../../resources/responses/responses';\n\nexport type ResponseFunctionCallArgumentsDeltaEvent = RawResponseFunctionCallArgumentsDeltaEvent & {\n  snapshot: string;\n};\n\nexport type ResponseTextDeltaEvent = RawResponseTextDeltaEvent & {\n  snapshot: string;\n};\n\nexport type ParsedResponseStreamEvent =\n  | ResponseAudioDeltaEvent\n  | ResponseAudioDoneEvent\n  | ResponseAudioTranscriptDeltaEvent\n  | ResponseAudioTranscriptDoneEvent\n  | ResponseCodeInterpreterCallCodeDeltaEvent\n  | ResponseCodeInterpreterCallCodeDoneEvent\n  | ResponseCodeInterpreterCallCompletedEvent\n  | ResponseCodeInterpreterCallInProgressEvent\n  | ResponseCodeInterpreterCallInterpretingEvent\n  | ResponseCompletedEvent\n  | ResponseContentPartAddedEvent\n  | ResponseContentPartDoneEvent\n  | ResponseCreatedEvent\n  | ResponseErrorEvent\n  | ResponseFileSearchCallCompletedEvent\n  | ResponseFileSearchCallInProgressEvent\n  | ResponseFileSearchCallSearchingEvent\n  | ResponseFunctionCallArgumentsDeltaEvent\n  | ResponseFunctionCallArgumentsDoneEvent\n  | ResponseInProgressEvent\n  | ResponseFailedEvent\n  | ResponseIncompleteEvent\n  | ResponseOutputItemAddedEvent\n  | ResponseOutputItemDoneEvent\n  | ResponseRefusalDeltaEvent\n  | ResponseRefusalDoneEvent\n  | ResponseTextDeltaEvent\n  | ResponseTextDoneEvent\n  | ResponseWebSearchCallCompletedEvent\n  | ResponseWebSearchCallInProgressEvent\n  | ResponseWebSearchCallSearchingEvent;\n"
  },
  {
    "path": "src/lib/responses/ResponseStream.ts",
    "content": "import {\n  ResponseTextConfig,\n  type ParsedResponse,\n  type Response,\n  type ResponseCreateParamsBase,\n  type ResponseCreateParamsStreaming,\n  type ResponseStreamEvent,\n} from '../../resources/responses/responses';\nimport { RequestOptions } from '../../internal/request-options';\nimport { APIUserAbortError, OpenAIError } from '../../error';\nimport OpenAI from '../../index';\nimport { type BaseEvents, EventStream } from '../EventStream';\nimport { type ResponseFunctionCallArgumentsDeltaEvent, type ResponseTextDeltaEvent } from './EventTypes';\nimport { maybeParseResponse, ParseableToolsParams } from '../ResponsesParser';\nimport { Stream } from '../../streaming';\n\nexport type ResponseStreamParams = ResponseCreateAndStreamParams | ResponseStreamByIdParams;\n\nexport type ResponseCreateAndStreamParams = Omit<ResponseCreateParamsBase, 'stream'> & {\n  stream?: true;\n};\n\nexport type ResponseStreamByIdParams = {\n  /**\n   * The ID of the response to stream.\n   */\n  response_id: string;\n  /**\n   * If provided, the stream will start after the event with the given sequence number.\n   */\n  starting_after?: number;\n  /**\n   * Configuration options for a text response from the model. Can be plain text or\n   * structured JSON data. Learn more:\n   *\n   * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n   * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n   */\n  text?: ResponseTextConfig;\n\n  /**\n   * An array of tools the model may call while generating a response. When continuing a stream, provide\n   * the same tools as the original request.\n   */\n  tools?: ParseableToolsParams;\n};\n\ntype ResponseEvents = BaseEvents &\n  Omit<\n    {\n      [K in ResponseStreamEvent['type']]: (event: Extract<ResponseStreamEvent, { type: K }>) => void;\n    },\n    'response.output_text.delta' | 'response.function_call_arguments.delta'\n  > & {\n    event: (event: ResponseStreamEvent) => void;\n    'response.output_text.delta': (event: ResponseTextDeltaEvent) => void;\n    'response.function_call_arguments.delta': (event: ResponseFunctionCallArgumentsDeltaEvent) => void;\n  };\n\nexport type ResponseStreamingParams = Omit<ResponseCreateParamsBase, 'stream'> & {\n  stream?: true;\n};\n\nexport class ResponseStream<ParsedT = null>\n  extends EventStream<ResponseEvents>\n  implements AsyncIterable<ResponseStreamEvent>\n{\n  #params: ResponseStreamingParams | null;\n  #currentResponseSnapshot: Response | undefined;\n  #finalResponse: ParsedResponse<ParsedT> | undefined;\n\n  constructor(params: ResponseStreamingParams | null) {\n    super();\n    this.#params = params;\n  }\n\n  static createResponse<ParsedT>(\n    client: OpenAI,\n    params: ResponseStreamParams,\n    options?: RequestOptions,\n  ): ResponseStream<ParsedT> {\n    const runner = new ResponseStream<ParsedT>(params as ResponseCreateParamsStreaming);\n    runner._run(() =>\n      runner._createOrRetrieveResponse(client, params, {\n        ...options,\n        headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },\n      }),\n    );\n    return runner;\n  }\n\n  #beginRequest() {\n    if (this.ended) return;\n    this.#currentResponseSnapshot = undefined;\n  }\n\n  #addEvent(this: ResponseStream<ParsedT>, event: ResponseStreamEvent, starting_after: number | null) {\n    if (this.ended) return;\n\n    const maybeEmit = (name: string, event: ResponseStreamEvent & { snapshot?: string }) => {\n      if (starting_after == null || event.sequence_number > starting_after) {\n        this._emit(name as any, event);\n      }\n    };\n\n    const response = this.#accumulateResponse(event);\n    maybeEmit('event', event);\n\n    switch (event.type) {\n      case 'response.output_text.delta': {\n        const output = response.output[event.output_index];\n        if (!output) {\n          throw new OpenAIError(`missing output at index ${event.output_index}`);\n        }\n        if (output.type === 'message') {\n          const content = output.content[event.content_index];\n          if (!content) {\n            throw new OpenAIError(`missing content at index ${event.content_index}`);\n          }\n          if (content.type !== 'output_text') {\n            throw new OpenAIError(`expected content to be 'output_text', got ${content.type}`);\n          }\n\n          maybeEmit('response.output_text.delta', {\n            ...event,\n            snapshot: content.text,\n          });\n        }\n        break;\n      }\n      case 'response.function_call_arguments.delta': {\n        const output = response.output[event.output_index];\n        if (!output) {\n          throw new OpenAIError(`missing output at index ${event.output_index}`);\n        }\n        if (output.type === 'function_call') {\n          maybeEmit('response.function_call_arguments.delta', {\n            ...event,\n            snapshot: output.arguments,\n          });\n        }\n        break;\n      }\n      default:\n        maybeEmit(event.type, event);\n        break;\n    }\n  }\n\n  #endRequest(): ParsedResponse<ParsedT> {\n    if (this.ended) {\n      throw new OpenAIError(`stream has ended, this shouldn't happen`);\n    }\n    const snapshot = this.#currentResponseSnapshot;\n    if (!snapshot) {\n      throw new OpenAIError(`request ended without sending any events`);\n    }\n    this.#currentResponseSnapshot = undefined;\n    const parsedResponse = finalizeResponse<ParsedT>(snapshot, this.#params);\n    this.#finalResponse = parsedResponse;\n\n    return parsedResponse;\n  }\n\n  protected async _createOrRetrieveResponse(\n    client: OpenAI,\n    params: ResponseStreamParams,\n    options?: RequestOptions,\n  ): Promise<ParsedResponse<ParsedT>> {\n    const signal = options?.signal;\n    if (signal) {\n      if (signal.aborted) this.controller.abort();\n      signal.addEventListener('abort', () => this.controller.abort());\n    }\n    this.#beginRequest();\n\n    let stream: Stream<ResponseStreamEvent> | undefined;\n    let starting_after: number | null = null;\n    if ('response_id' in params) {\n      stream = await client.responses.retrieve(\n        params.response_id,\n        { stream: true },\n        { ...options, signal: this.controller.signal, stream: true },\n      );\n      starting_after = params.starting_after ?? null;\n    } else {\n      stream = await client.responses.create(\n        { ...params, stream: true },\n        { ...options, signal: this.controller.signal },\n      );\n    }\n\n    this._connected();\n    for await (const event of stream) {\n      this.#addEvent(event, starting_after);\n    }\n    if (stream.controller.signal?.aborted) {\n      throw new APIUserAbortError();\n    }\n    return this.#endRequest();\n  }\n\n  #accumulateResponse(event: ResponseStreamEvent): Response {\n    let snapshot = this.#currentResponseSnapshot;\n    if (!snapshot) {\n      if (event.type !== 'response.created') {\n        throw new OpenAIError(\n          `When snapshot hasn't been set yet, expected 'response.created' event, got ${event.type}`,\n        );\n      }\n      snapshot = this.#currentResponseSnapshot = event.response;\n      return snapshot;\n    }\n\n    switch (event.type) {\n      case 'response.output_item.added': {\n        snapshot.output.push(event.item);\n        break;\n      }\n      case 'response.content_part.added': {\n        const output = snapshot.output[event.output_index];\n        if (!output) {\n          throw new OpenAIError(`missing output at index ${event.output_index}`);\n        }\n        const type = output.type;\n        const part = event.part;\n        if (type === 'message' && part.type !== 'reasoning_text') {\n          output.content.push(part);\n        } else if (type === 'reasoning' && part.type === 'reasoning_text') {\n          if (!output.content) {\n            output.content = [];\n          }\n          output.content.push(part);\n        }\n        break;\n      }\n      case 'response.output_text.delta': {\n        const output = snapshot.output[event.output_index];\n        if (!output) {\n          throw new OpenAIError(`missing output at index ${event.output_index}`);\n        }\n        if (output.type === 'message') {\n          const content = output.content[event.content_index];\n          if (!content) {\n            throw new OpenAIError(`missing content at index ${event.content_index}`);\n          }\n          if (content.type !== 'output_text') {\n            throw new OpenAIError(`expected content to be 'output_text', got ${content.type}`);\n          }\n          content.text += event.delta;\n        }\n        break;\n      }\n      case 'response.function_call_arguments.delta': {\n        const output = snapshot.output[event.output_index];\n        if (!output) {\n          throw new OpenAIError(`missing output at index ${event.output_index}`);\n        }\n        if (output.type === 'function_call') {\n          output.arguments += event.delta;\n        }\n        break;\n      }\n      case 'response.reasoning_text.delta': {\n        const output = snapshot.output[event.output_index];\n        if (!output) {\n          throw new OpenAIError(`missing output at index ${event.output_index}`);\n        }\n        if (output.type === 'reasoning') {\n          const content = output.content?.[event.content_index];\n          if (!content) {\n            throw new OpenAIError(`missing content at index ${event.content_index}`);\n          }\n          if (content.type !== 'reasoning_text') {\n            throw new OpenAIError(`expected content to be 'reasoning_text', got ${content.type}`);\n          }\n          content.text += event.delta;\n        }\n        break;\n      }\n      case 'response.completed': {\n        this.#currentResponseSnapshot = event.response;\n        break;\n      }\n    }\n\n    return snapshot;\n  }\n\n  [Symbol.asyncIterator](this: ResponseStream<ParsedT>): AsyncIterator<ResponseStreamEvent> {\n    const pushQueue: ResponseStreamEvent[] = [];\n    const readQueue: {\n      resolve: (event: ResponseStreamEvent | undefined) => void;\n      reject: (err: unknown) => void;\n    }[] = [];\n    let done = false;\n\n    this.on('event', (event) => {\n      const reader = readQueue.shift();\n      if (reader) {\n        reader.resolve(event);\n      } else {\n        pushQueue.push(event);\n      }\n    });\n\n    this.on('end', () => {\n      done = true;\n      for (const reader of readQueue) {\n        reader.resolve(undefined);\n      }\n      readQueue.length = 0;\n    });\n\n    this.on('abort', (err) => {\n      done = true;\n      for (const reader of readQueue) {\n        reader.reject(err);\n      }\n      readQueue.length = 0;\n    });\n\n    this.on('error', (err) => {\n      done = true;\n      for (const reader of readQueue) {\n        reader.reject(err);\n      }\n      readQueue.length = 0;\n    });\n\n    return {\n      next: async (): Promise<IteratorResult<ResponseStreamEvent>> => {\n        if (!pushQueue.length) {\n          if (done) {\n            return { value: undefined, done: true };\n          }\n          return new Promise<ResponseStreamEvent | undefined>((resolve, reject) =>\n            readQueue.push({ resolve, reject }),\n          ).then((event) => (event ? { value: event, done: false } : { value: undefined, done: true }));\n        }\n        const event = pushQueue.shift()!;\n        return { value: event, done: false };\n      },\n      return: async () => {\n        this.abort();\n        return { value: undefined, done: true };\n      },\n    };\n  }\n\n  /**\n   * @returns a promise that resolves with the final Response, or rejects\n   * if an error occurred or the stream ended prematurely without producing a REsponse.\n   */\n  async finalResponse(): Promise<ParsedResponse<ParsedT>> {\n    await this.done();\n    const response = this.#finalResponse;\n    if (!response) throw new OpenAIError('stream ended without producing a ChatCompletion');\n    return response;\n  }\n}\n\nfunction finalizeResponse<ParsedT>(\n  snapshot: Response,\n  params: ResponseStreamingParams | null,\n): ParsedResponse<ParsedT> {\n  return maybeParseResponse(snapshot, params);\n}\n"
  },
  {
    "path": "src/lib/transform.ts",
    "content": "import type { JSONSchema, JSONSchemaDefinition } from './jsonschema';\n\nexport function toStrictJsonSchema(schema: JSONSchema): JSONSchema {\n  if (schema.type !== 'object') {\n    throw new Error(\n      `Root schema must have type: 'object' but got type: ${schema.type ? `'${schema.type}'` : 'undefined'}`,\n    );\n  }\n\n  const schemaCopy = structuredClone(schema);\n  return ensureStrictJsonSchema(schemaCopy, [], schemaCopy);\n}\n\nfunction isNullable(schema: JSONSchemaDefinition): boolean {\n  if (typeof schema === 'boolean') {\n    return false;\n  }\n  if (schema.type === 'null') {\n    return true;\n  }\n  for (const oneOfVariant of schema.oneOf ?? []) {\n    if (isNullable(oneOfVariant)) {\n      return true;\n    }\n  }\n  for (const allOfVariant of schema.anyOf ?? []) {\n    if (isNullable(allOfVariant)) {\n      return true;\n    }\n  }\n  return false;\n}\n\n/**\n * Mutates the given JSON schema to ensure it conforms to the `strict` standard\n * that the API expects.\n */\nfunction ensureStrictJsonSchema(\n  jsonSchema: JSONSchemaDefinition,\n  path: string[],\n  root: JSONSchema,\n): JSONSchema {\n  if (typeof jsonSchema === 'boolean') {\n    throw new TypeError(`Expected object schema but got boolean; path=${path.join('/')}`);\n  }\n\n  if (!isObject(jsonSchema)) {\n    throw new TypeError(`Expected ${JSON.stringify(jsonSchema)} to be an object; path=${path.join('/')}`);\n  }\n\n  // Handle $defs (non-standard but sometimes used)\n  const defs = (jsonSchema as any).$defs;\n  if (isObject(defs)) {\n    for (const [defName, defSchema] of Object.entries(defs)) {\n      ensureStrictJsonSchema(defSchema as JSONSchema, [...path, '$defs', defName], root);\n    }\n  }\n\n  // Handle definitions (draft-04 style, deprecated in draft-07 but still used)\n  const definitions = (jsonSchema as any).definitions;\n  if (isObject(definitions)) {\n    for (const [definitionName, definitionSchema] of Object.entries(definitions)) {\n      ensureStrictJsonSchema(definitionSchema as JSONSchema, [...path, 'definitions', definitionName], root);\n    }\n  }\n\n  // Add additionalProperties: false to object types\n  const typ = jsonSchema.type;\n  if (typ === 'object' && !('additionalProperties' in jsonSchema)) {\n    jsonSchema.additionalProperties = false;\n  }\n\n  const required = jsonSchema.required ?? [];\n\n  // Handle object properties\n  const properties = jsonSchema.properties;\n  if (isObject(properties)) {\n    for (const [key, value] of Object.entries(properties)) {\n      if (!isNullable(value) && !required.includes(key)) {\n        throw new Error(\n          `Zod field at \\`${[...path, 'properties', key].join(\n            '/',\n          )}\\` uses \\`.optional()\\` without \\`.nullable()\\` which is not supported by the API. See: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required`,\n        );\n      }\n    }\n    jsonSchema.required = Object.keys(properties);\n    jsonSchema.properties = Object.fromEntries(\n      Object.entries(properties).map(([key, propSchema]) => [\n        key,\n        ensureStrictJsonSchema(propSchema, [...path, 'properties', key], root),\n      ]),\n    );\n  }\n\n  // Handle arrays\n  const items = jsonSchema.items;\n  if (isObject(items)) {\n    jsonSchema.items = ensureStrictJsonSchema(items, [...path, 'items'], root);\n  }\n\n  // Handle unions (anyOf)\n  const anyOf = jsonSchema.anyOf;\n  if (Array.isArray(anyOf)) {\n    jsonSchema.anyOf = anyOf.map((variant, i) =>\n      ensureStrictJsonSchema(variant, [...path, 'anyOf', String(i)], root),\n    );\n  }\n\n  // Handle intersections (allOf)\n  const allOf = jsonSchema.allOf;\n  if (Array.isArray(allOf)) {\n    if (allOf.length === 1) {\n      const resolved = ensureStrictJsonSchema(allOf[0]!, [...path, 'allOf', '0'], root);\n      Object.assign(jsonSchema, resolved);\n      delete jsonSchema.allOf;\n    } else {\n      jsonSchema.allOf = allOf.map((entry, i) =>\n        ensureStrictJsonSchema(entry, [...path, 'allOf', String(i)], root),\n      );\n    }\n  }\n\n  // Strip `null` defaults as there's no meaningful distinction\n  if (jsonSchema.default === null) {\n    delete jsonSchema.default;\n  }\n\n  // Handle $ref with additional properties\n  const ref = (jsonSchema as any).$ref;\n  if (ref && hasMoreThanNKeys(jsonSchema, 1)) {\n    if (typeof ref !== 'string') {\n      throw new TypeError(`Received non-string $ref - ${ref}; path=${path.join('/')}`);\n    }\n\n    const resolved = resolveRef(root, ref);\n    if (typeof resolved === 'boolean') {\n      throw new Error(`Expected \\`$ref: ${ref}\\` to resolve to an object schema but got boolean`);\n    }\n    if (!isObject(resolved)) {\n      throw new Error(\n        `Expected \\`$ref: ${ref}\\` to resolve to an object but got ${JSON.stringify(resolved)}`,\n      );\n    }\n\n    // Properties from the json schema take priority over the ones on the `$ref`\n    Object.assign(jsonSchema, { ...resolved, ...jsonSchema });\n    delete (jsonSchema as any).$ref;\n\n    // Since the schema expanded from `$ref` might not have `additionalProperties: false` applied,\n    // we call `ensureStrictJsonSchema` again to fix the inlined schema and ensure it's valid.\n    return ensureStrictJsonSchema(jsonSchema, path, root);\n  }\n\n  return jsonSchema;\n}\n\nfunction resolveRef(root: JSONSchema, ref: string): JSONSchemaDefinition {\n  if (!ref.startsWith('#/')) {\n    throw new Error(`Unexpected $ref format ${JSON.stringify(ref)}; Does not start with #/`);\n  }\n\n  const pathParts = ref.slice(2).split('/');\n  let resolved: any = root;\n\n  for (const key of pathParts) {\n    if (!isObject(resolved)) {\n      throw new Error(`encountered non-object entry while resolving ${ref} - ${JSON.stringify(resolved)}`);\n    }\n    const value = resolved[key];\n    if (value === undefined) {\n      throw new Error(`Key ${key} not found while resolving ${ref}`);\n    }\n    resolved = value;\n  }\n\n  return resolved;\n}\n\nfunction isObject<T>(obj: T | Array<any>): obj is Extract<T, Record<string, any>> {\n  return typeof obj === 'object' && obj !== null && !Array.isArray(obj);\n}\n\nfunction hasMoreThanNKeys(obj: Record<string, any>, n: number): boolean {\n  let i = 0;\n  for (const _ in obj) {\n    i++;\n    if (i > n) {\n      return true;\n    }\n  }\n  return false;\n}\n"
  },
  {
    "path": "src/pagination.ts",
    "content": "/** @deprecated Import from ./core/pagination instead */\nexport * from './core/pagination';\n"
  },
  {
    "path": "src/realtime/index.ts",
    "content": "export { OpenAIRealtimeError } from './internal-base';\n"
  },
  {
    "path": "src/realtime/internal-base.ts",
    "content": "import {\n  RealtimeClientEvent,\n  RealtimeServerEvent,\n  RealtimeErrorEvent,\n  RealtimeError,\n} from '../resources/realtime/realtime';\nimport { EventEmitter } from '../lib/EventEmitter';\nimport { OpenAIError } from '../error';\nimport OpenAI, { AzureOpenAI } from '../index';\n\nexport class OpenAIRealtimeError extends OpenAIError {\n  /**\n   * The error data that the API sent back in an `error` event.\n   */\n  error?: RealtimeError | undefined;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id?: string | undefined;\n\n  constructor(message: string, event: RealtimeErrorEvent | null) {\n    super(message);\n\n    this.error = event?.error;\n    this.event_id = event?.event_id;\n  }\n}\n\ntype Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};\n\ntype RealtimeEvents = Simplify<\n  {\n    event: (event: RealtimeServerEvent) => void;\n    error: (error: OpenAIRealtimeError) => void;\n  } & {\n    [EventType in Exclude<RealtimeServerEvent['type'], 'error'>]: (\n      event: Extract<RealtimeServerEvent, { type: EventType }>,\n    ) => unknown;\n  }\n>;\n\nexport abstract class OpenAIRealtimeEmitter extends EventEmitter<RealtimeEvents> {\n  /**\n   * Send an event to the API.\n   */\n  abstract send(event: RealtimeClientEvent): void;\n\n  /**\n   * Close the websocket connection.\n   */\n  abstract close(props?: { code: number; reason: string }): void;\n\n  protected _onError(event: null, message: string, cause: any): void;\n  protected _onError(event: RealtimeErrorEvent, message?: string | undefined): void;\n  protected _onError(event: RealtimeErrorEvent | null, message?: string | undefined, cause?: any): void {\n    message =\n      event?.error ?\n        `${event.error.message} code=${event.error.code} param=${event.error.param} type=${event.error.type} event_id=${event.error.event_id}`\n      : message ?? 'unknown error';\n\n    if (!this._hasListener('error')) {\n      const error = new OpenAIRealtimeError(\n        message +\n          `\\n\\nTo resolve these unhandled rejection errors you should bind an \\`error\\` callback, e.g. \\`rt.on('error', (error) => ...)\\` `,\n        event,\n      );\n      // @ts-ignore\n      error.cause = cause;\n      Promise.reject(error);\n      return;\n    }\n\n    const error = new OpenAIRealtimeError(message, event);\n    // @ts-ignore\n    error.cause = cause;\n\n    this._emit('error', error);\n  }\n}\n\nexport function isAzure(client: Pick<OpenAI, 'apiKey' | 'baseURL'>): client is AzureOpenAI {\n  return client instanceof AzureOpenAI;\n}\n\nexport function buildRealtimeURL(client: Pick<OpenAI, 'apiKey' | 'baseURL'>, model: string): URL {\n  const path = '/realtime';\n  const baseURL = client.baseURL;\n  const url = new URL(baseURL + (baseURL.endsWith('/') ? path.slice(1) : path));\n  url.protocol = 'wss';\n  if (isAzure(client)) {\n    url.searchParams.set('api-version', client.apiVersion);\n    url.searchParams.set('deployment', model);\n  } else {\n    url.searchParams.set('model', model);\n  }\n  return url;\n}\n"
  },
  {
    "path": "src/realtime/websocket.ts",
    "content": "import { AzureOpenAI, OpenAI } from '../index';\nimport { OpenAIError } from '../error';\nimport type { RealtimeClientEvent, RealtimeServerEvent } from '../resources/realtime/realtime';\nimport { OpenAIRealtimeEmitter, buildRealtimeURL, isAzure } from './internal-base';\nimport { isRunningInBrowser } from '../internal/detect-platform';\n\ninterface MessageEvent {\n  data: string;\n}\n\ntype _WebSocket =\n  typeof globalThis extends (\n    {\n      WebSocket: infer ws extends abstract new (...args: any) => any;\n    }\n  ) ?\n    // @ts-ignore\n    InstanceType<ws>\n  : any;\n\nexport class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {\n  url: URL;\n  socket: _WebSocket;\n\n  constructor(\n    props: {\n      model: string;\n      dangerouslyAllowBrowser?: boolean;\n      /**\n       * Callback to mutate the URL, needed for Azure.\n       * @internal\n       */\n      onURL?: (url: URL) => void;\n      /** Indicates the token was resolved by the factory just before connecting. @internal */\n      __resolvedApiKey?: boolean;\n    },\n    client?: Pick<OpenAI, 'apiKey' | 'baseURL'>,\n  ) {\n    super();\n    const hasProvider = typeof (client as any)?._options?.apiKey === 'function';\n    const dangerouslyAllowBrowser =\n      props.dangerouslyAllowBrowser ??\n      (client as any)?._options?.dangerouslyAllowBrowser ??\n      (client?.apiKey?.startsWith('ek_') ? true : null);\n    if (!dangerouslyAllowBrowser && isRunningInBrowser()) {\n      throw new OpenAIError(\n        \"It looks like you're running in a browser-like environment.\\n\\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\\n\\nYou can avoid this error by creating an ephemeral session token:\\nhttps://platform.openai.com/docs/api-reference/realtime-sessions\\n\",\n      );\n    }\n\n    client ??= new OpenAI({ dangerouslyAllowBrowser });\n\n    if (hasProvider && !props?.__resolvedApiKey) {\n      throw new Error(\n        [\n          'Cannot open Realtime WebSocket with a function-based apiKey.',\n          'Use the .create() method so that the key is resolved before connecting:',\n          'await OpenAIRealtimeWebSocket.create(client, { model })',\n        ].join('\\n'),\n      );\n    }\n\n    this.url = buildRealtimeURL(client, props.model);\n    props.onURL?.(this.url);\n\n    // @ts-ignore\n    this.socket = new WebSocket(this.url.toString(), [\n      'realtime',\n      ...(isAzure(client) ? [] : [`openai-insecure-api-key.${client.apiKey}`]),\n    ]);\n\n    this.socket.addEventListener('message', (websocketEvent: MessageEvent) => {\n      const event = (() => {\n        try {\n          return JSON.parse(websocketEvent.data.toString()) as RealtimeServerEvent;\n        } catch (err) {\n          this._onError(null, 'could not parse websocket event', err);\n          return null;\n        }\n      })();\n\n      if (event) {\n        this._emit('event', event);\n\n        if (event.type === 'error') {\n          this._onError(event);\n        } else {\n          // @ts-expect-error TS isn't smart enough to get the relationship right here\n          this._emit(event.type, event);\n        }\n      }\n    });\n\n    this.socket.addEventListener('error', (event: any) => {\n      this._onError(null, event.message, null);\n    });\n\n    if (isAzure(client)) {\n      if (this.url.searchParams.get('Authorization') !== null) {\n        this.url.searchParams.set('Authorization', '<REDACTED>');\n      } else {\n        this.url.searchParams.set('api-key', '<REDACTED>');\n      }\n    }\n  }\n\n  static async create(\n    client: Pick<OpenAI, 'apiKey' | 'baseURL' | '_callApiKey'>,\n    props: { model: string; dangerouslyAllowBrowser?: boolean },\n  ): Promise<OpenAIRealtimeWebSocket> {\n    return new OpenAIRealtimeWebSocket({ ...props, __resolvedApiKey: await client._callApiKey() }, client);\n  }\n\n  static async azure(\n    client: Pick<AzureOpenAI, '_callApiKey' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,\n    options: { deploymentName?: string; dangerouslyAllowBrowser?: boolean } = {},\n  ): Promise<OpenAIRealtimeWebSocket> {\n    const isApiKeyProvider = await client._callApiKey();\n    function onURL(url: URL) {\n      if (isApiKeyProvider) {\n        url.searchParams.set('Authorization', `Bearer ${client.apiKey}`);\n      } else {\n        url.searchParams.set('api-key', client.apiKey);\n      }\n    }\n    const deploymentName = options.deploymentName ?? client.deploymentName;\n    if (!deploymentName) {\n      throw new Error('No deployment name provided');\n    }\n    const { dangerouslyAllowBrowser } = options;\n    return new OpenAIRealtimeWebSocket(\n      {\n        model: deploymentName,\n        onURL,\n        ...(dangerouslyAllowBrowser ? { dangerouslyAllowBrowser } : {}),\n        __resolvedApiKey: isApiKeyProvider,\n      },\n      client,\n    );\n  }\n\n  send(event: RealtimeClientEvent) {\n    try {\n      this.socket.send(JSON.stringify(event));\n    } catch (err) {\n      this._onError(null, 'could not send data', err);\n    }\n  }\n\n  close(props?: { code: number; reason: string }) {\n    try {\n      this.socket.close(props?.code ?? 1000, props?.reason ?? 'OK');\n    } catch (err) {\n      this._onError(null, 'could not close the connection', err);\n    }\n  }\n}\n"
  },
  {
    "path": "src/realtime/ws.ts",
    "content": "import * as WS from 'ws';\nimport { AzureOpenAI, OpenAI } from '../index';\nimport type { RealtimeClientEvent, RealtimeServerEvent } from '../resources/realtime/realtime';\nimport { OpenAIRealtimeEmitter, buildRealtimeURL, isAzure } from './internal-base';\n\nexport class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {\n  url: URL;\n  socket: WS.WebSocket;\n\n  constructor(\n    props: {\n      model: string;\n      options?: WS.ClientOptions | undefined;\n      /** @internal */ __resolvedApiKey?: boolean;\n    },\n    client?: Pick<OpenAI, 'apiKey' | 'baseURL'>,\n  ) {\n    super();\n    client ??= new OpenAI();\n    const hasProvider = typeof (client as any)?._options?.apiKey === 'function';\n    if (hasProvider && !props.__resolvedApiKey) {\n      throw new Error(\n        [\n          'Cannot open Realtime WebSocket with a function-based apiKey.',\n          'Use the .create() method so that the key is resolved before connecting:',\n          'await OpenAIRealtimeWS.create(client, { model })',\n        ].join('\\n'),\n      );\n    }\n    this.url = buildRealtimeURL(client, props.model);\n    this.socket = new WS.WebSocket(this.url, {\n      ...props.options,\n      headers: {\n        ...props.options?.headers,\n        ...(isAzure(client) && !props.__resolvedApiKey ? {} : { Authorization: `Bearer ${client.apiKey}` }),\n      },\n    });\n\n    this.socket.on('message', (wsEvent) => {\n      const event = (() => {\n        try {\n          return JSON.parse(wsEvent.toString()) as RealtimeServerEvent;\n        } catch (err) {\n          this._onError(null, 'could not parse websocket event', err);\n          return null;\n        }\n      })();\n\n      if (event) {\n        this._emit('event', event);\n\n        if (event.type === 'error') {\n          this._onError(event);\n        } else {\n          // @ts-expect-error TS isn't smart enough to get the relationship right here\n          this._emit(event.type, event);\n        }\n      }\n    });\n\n    this.socket.on('error', (err) => {\n      this._onError(null, err.message, err);\n    });\n  }\n\n  static async create(\n    client: Pick<OpenAI, 'apiKey' | 'baseURL' | '_callApiKey'>,\n    props: { model: string; options?: WS.ClientOptions | undefined },\n  ): Promise<OpenAIRealtimeWS> {\n    return new OpenAIRealtimeWS({ ...props, __resolvedApiKey: await client._callApiKey() }, client);\n  }\n\n  static async azure(\n    client: Pick<AzureOpenAI, '_callApiKey' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,\n    props: { deploymentName?: string; options?: WS.ClientOptions | undefined } = {},\n  ): Promise<OpenAIRealtimeWS> {\n    const isApiKeyProvider = await client._callApiKey();\n    const deploymentName = props.deploymentName ?? client.deploymentName;\n    if (!deploymentName) {\n      throw new Error('No deployment name provided');\n    }\n    return new OpenAIRealtimeWS(\n      {\n        model: deploymentName,\n        options: {\n          ...props.options,\n          headers: {\n            ...props.options?.headers,\n            ...(isApiKeyProvider ? {} : { 'api-key': client.apiKey }),\n          },\n        },\n        __resolvedApiKey: isApiKeyProvider,\n      },\n      client,\n    );\n  }\n\n  send(event: RealtimeClientEvent) {\n    try {\n      this.socket.send(JSON.stringify(event));\n    } catch (err) {\n      this._onError(null, 'could not send data', err);\n    }\n  }\n\n  close(props?: { code: number; reason: string }) {\n    try {\n      this.socket.close(props?.code ?? 1000, props?.reason ?? 'OK');\n    } catch (err) {\n      this._onError(null, 'could not close the connection', err);\n    }\n  }\n}\n"
  },
  {
    "path": "src/resource.ts",
    "content": "/** @deprecated Import from ./core/resource instead */\nexport * from './core/resource';\n"
  },
  {
    "path": "src/resources/audio/audio.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as SpeechAPI from './speech';\nimport { Speech, SpeechCreateParams, SpeechModel } from './speech';\nimport * as TranscriptionsAPI from './transcriptions';\nimport {\n  Transcription,\n  TranscriptionCreateParams,\n  TranscriptionCreateParamsNonStreaming,\n  TranscriptionCreateParamsStreaming,\n  TranscriptionCreateResponse,\n  TranscriptionDiarized,\n  TranscriptionDiarizedSegment,\n  TranscriptionInclude,\n  TranscriptionSegment,\n  TranscriptionStreamEvent,\n  TranscriptionTextDeltaEvent,\n  TranscriptionTextDoneEvent,\n  TranscriptionTextSegmentEvent,\n  TranscriptionVerbose,\n  TranscriptionWord,\n  Transcriptions,\n} from './transcriptions';\nimport * as TranslationsAPI from './translations';\nimport {\n  Translation,\n  TranslationCreateParams,\n  TranslationCreateResponse,\n  TranslationVerbose,\n  Translations,\n} from './translations';\n\nexport class Audio extends APIResource {\n  transcriptions: TranscriptionsAPI.Transcriptions = new TranscriptionsAPI.Transcriptions(this._client);\n  translations: TranslationsAPI.Translations = new TranslationsAPI.Translations(this._client);\n  speech: SpeechAPI.Speech = new SpeechAPI.Speech(this._client);\n}\n\nexport type AudioModel =\n  | 'whisper-1'\n  | 'gpt-4o-transcribe'\n  | 'gpt-4o-mini-transcribe'\n  | 'gpt-4o-mini-transcribe-2025-12-15'\n  | 'gpt-4o-transcribe-diarize';\n\n/**\n * The format of the output, in one of these options: `json`, `text`, `srt`,\n * `verbose_json`, `vtt`, or `diarized_json`. For `gpt-4o-transcribe` and\n * `gpt-4o-mini-transcribe`, the only supported format is `json`. For\n * `gpt-4o-transcribe-diarize`, the supported formats are `json`, `text`, and\n * `diarized_json`, with `diarized_json` required to receive speaker annotations.\n */\nexport type AudioResponseFormat = 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt' | 'diarized_json';\n\nAudio.Transcriptions = Transcriptions;\nAudio.Translations = Translations;\nAudio.Speech = Speech;\n\nexport declare namespace Audio {\n  export { type AudioModel as AudioModel, type AudioResponseFormat as AudioResponseFormat };\n\n  export {\n    Transcriptions as Transcriptions,\n    type Transcription as Transcription,\n    type TranscriptionDiarized as TranscriptionDiarized,\n    type TranscriptionDiarizedSegment as TranscriptionDiarizedSegment,\n    type TranscriptionInclude as TranscriptionInclude,\n    type TranscriptionSegment as TranscriptionSegment,\n    type TranscriptionStreamEvent as TranscriptionStreamEvent,\n    type TranscriptionTextDeltaEvent as TranscriptionTextDeltaEvent,\n    type TranscriptionTextDoneEvent as TranscriptionTextDoneEvent,\n    type TranscriptionTextSegmentEvent as TranscriptionTextSegmentEvent,\n    type TranscriptionVerbose as TranscriptionVerbose,\n    type TranscriptionWord as TranscriptionWord,\n    type TranscriptionCreateResponse as TranscriptionCreateResponse,\n    type TranscriptionCreateParams as TranscriptionCreateParams,\n    type TranscriptionCreateParamsNonStreaming as TranscriptionCreateParamsNonStreaming,\n    type TranscriptionCreateParamsStreaming as TranscriptionCreateParamsStreaming,\n  };\n\n  export {\n    Translations as Translations,\n    type Translation as Translation,\n    type TranslationVerbose as TranslationVerbose,\n    type TranslationCreateResponse as TranslationCreateResponse,\n    type TranslationCreateParams as TranslationCreateParams,\n  };\n\n  export { Speech as Speech, type SpeechModel as SpeechModel, type SpeechCreateParams as SpeechCreateParams };\n}\n"
  },
  {
    "path": "src/resources/audio/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Audio, type AudioModel, type AudioResponseFormat } from './audio';\nexport { Speech, type SpeechModel, type SpeechCreateParams } from './speech';\nexport {\n  Transcriptions,\n  type Transcription,\n  type TranscriptionDiarized,\n  type TranscriptionDiarizedSegment,\n  type TranscriptionInclude,\n  type TranscriptionSegment,\n  type TranscriptionStreamEvent,\n  type TranscriptionTextDeltaEvent,\n  type TranscriptionTextDoneEvent,\n  type TranscriptionTextSegmentEvent,\n  type TranscriptionVerbose,\n  type TranscriptionWord,\n  type TranscriptionCreateResponse,\n  type TranscriptionCreateParams,\n  type TranscriptionCreateParamsNonStreaming,\n  type TranscriptionCreateParamsStreaming,\n} from './transcriptions';\nexport {\n  Translations,\n  type Translation,\n  type TranslationVerbose,\n  type TranslationCreateResponse,\n  type TranslationCreateParams,\n} from './translations';\n"
  },
  {
    "path": "src/resources/audio/speech.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport { APIPromise } from '../../core/api-promise';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\n\n/**\n * Turn audio into text or text into audio.\n */\nexport class Speech extends APIResource {\n  /**\n   * Generates audio from the input text.\n   *\n   * Returns the audio file content, or a stream of audio events.\n   *\n   * @example\n   * ```ts\n   * const speech = await client.audio.speech.create({\n   *   input: 'input',\n   *   model: 'string',\n   *   voice: 'string',\n   * });\n   *\n   * const content = await speech.blob();\n   * console.log(content);\n   * ```\n   */\n  create(body: SpeechCreateParams, options?: RequestOptions): APIPromise<Response> {\n    return this._client.post('/audio/speech', {\n      body,\n      ...options,\n      headers: buildHeaders([{ Accept: 'application/octet-stream' }, options?.headers]),\n      __binaryResponse: true,\n    });\n  }\n}\n\nexport type SpeechModel = 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts' | 'gpt-4o-mini-tts-2025-12-15';\n\nexport interface SpeechCreateParams {\n  /**\n   * The text to generate audio for. The maximum length is 4096 characters.\n   */\n  input: string;\n\n  /**\n   * One of the available [TTS models](https://platform.openai.com/docs/models#tts):\n   * `tts-1`, `tts-1-hd`, `gpt-4o-mini-tts`, or `gpt-4o-mini-tts-2025-12-15`.\n   */\n  model: (string & {}) | SpeechModel;\n\n  /**\n   * The voice to use when generating the audio. Supported built-in voices are\n   * `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`,\n   * `shimmer`, `verse`, `marin`, and `cedar`. You may also provide a custom voice\n   * object with an `id`, for example `{ \"id\": \"voice_1234\" }`. Previews of the\n   * voices are available in the\n   * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).\n   */\n  voice:\n    | string\n    | 'alloy'\n    | 'ash'\n    | 'ballad'\n    | 'coral'\n    | 'echo'\n    | 'sage'\n    | 'shimmer'\n    | 'verse'\n    | 'marin'\n    | 'cedar'\n    | SpeechCreateParams.ID;\n\n  /**\n   * Control the voice of your generated audio with additional instructions. Does not\n   * work with `tts-1` or `tts-1-hd`.\n   */\n  instructions?: string;\n\n  /**\n   * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`,\n   * `wav`, and `pcm`.\n   */\n  response_format?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm';\n\n  /**\n   * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is\n   * the default.\n   */\n  speed?: number;\n\n  /**\n   * The format to stream the audio in. Supported formats are `sse` and `audio`.\n   * `sse` is not supported for `tts-1` or `tts-1-hd`.\n   */\n  stream_format?: 'sse' | 'audio';\n}\n\nexport namespace SpeechCreateParams {\n  /**\n   * Custom voice reference.\n   */\n  export interface ID {\n    /**\n     * The custom voice ID, e.g. `voice_1234`.\n     */\n    id: string;\n  }\n}\n\nexport declare namespace Speech {\n  export { type SpeechModel as SpeechModel, type SpeechCreateParams as SpeechCreateParams };\n}\n"
  },
  {
    "path": "src/resources/audio/transcriptions.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as TranscriptionsAPI from './transcriptions';\nimport * as AudioAPI from './audio';\nimport { APIPromise } from '../../core/api-promise';\nimport { Stream } from '../../core/streaming';\nimport { type Uploadable } from '../../core/uploads';\nimport { RequestOptions } from '../../internal/request-options';\nimport { multipartFormRequestOptions } from '../../internal/uploads';\n\n/**\n * Turn audio into text or text into audio.\n */\nexport class Transcriptions extends APIResource {\n  /**\n   * Transcribes audio into the input language.\n   *\n   * Returns a transcription object in `json`, `diarized_json`, or `verbose_json`\n   * format, or a stream of transcript events.\n   *\n   * @example\n   * ```ts\n   * const transcription =\n   *   await client.audio.transcriptions.create({\n   *     file: fs.createReadStream('speech.mp3'),\n   *     model: 'gpt-4o-transcribe',\n   *   });\n   * ```\n   */\n  create(\n    body: TranscriptionCreateParamsNonStreaming<'json' | undefined>,\n    options?: RequestOptions,\n  ): APIPromise<Transcription>;\n  create(\n    body: TranscriptionCreateParamsNonStreaming<'verbose_json'>,\n    options?: RequestOptions,\n  ): APIPromise<TranscriptionVerbose>;\n  create(\n    body: TranscriptionCreateParamsNonStreaming<'srt' | 'vtt' | 'text'>,\n    options?: RequestOptions,\n  ): APIPromise<string>;\n  create(body: TranscriptionCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Transcription>;\n  create(\n    body: TranscriptionCreateParamsStreaming,\n    options?: RequestOptions,\n  ): APIPromise<Stream<TranscriptionStreamEvent>>;\n  create(\n    body: TranscriptionCreateParamsStreaming,\n    options?: RequestOptions,\n  ): APIPromise<TranscriptionCreateResponse | string | Stream<TranscriptionStreamEvent>>;\n  create(\n    body: TranscriptionCreateParams,\n    options?: RequestOptions,\n  ): APIPromise<TranscriptionCreateResponse | string | Stream<TranscriptionStreamEvent>> {\n    return this._client.post(\n      '/audio/transcriptions',\n      multipartFormRequestOptions(\n        {\n          body,\n          ...options,\n          stream: body.stream ?? false,\n          __metadata: { model: body.model },\n        },\n        this._client,\n      ),\n    );\n  }\n}\n\n/**\n * Represents a transcription response returned by model, based on the provided\n * input.\n */\nexport interface Transcription {\n  /**\n   * The transcribed text.\n   */\n  text: string;\n\n  /**\n   * The log probabilities of the tokens in the transcription. Only returned with the\n   * models `gpt-4o-transcribe` and `gpt-4o-mini-transcribe` if `logprobs` is added\n   * to the `include` array.\n   */\n  logprobs?: Array<Transcription.Logprob>;\n\n  /**\n   * Token usage statistics for the request.\n   */\n  usage?: Transcription.Tokens | Transcription.Duration;\n}\n\nexport namespace Transcription {\n  export interface Logprob {\n    /**\n     * The token in the transcription.\n     */\n    token?: string;\n\n    /**\n     * The bytes of the token.\n     */\n    bytes?: Array<number>;\n\n    /**\n     * The log probability of the token.\n     */\n    logprob?: number;\n  }\n\n  /**\n   * Usage statistics for models billed by token usage.\n   */\n  export interface Tokens {\n    /**\n     * Number of input tokens billed for this request.\n     */\n    input_tokens: number;\n\n    /**\n     * Number of output tokens generated.\n     */\n    output_tokens: number;\n\n    /**\n     * Total number of tokens used (input + output).\n     */\n    total_tokens: number;\n\n    /**\n     * The type of the usage object. Always `tokens` for this variant.\n     */\n    type: 'tokens';\n\n    /**\n     * Details about the input tokens billed for this request.\n     */\n    input_token_details?: Tokens.InputTokenDetails;\n  }\n\n  export namespace Tokens {\n    /**\n     * Details about the input tokens billed for this request.\n     */\n    export interface InputTokenDetails {\n      /**\n       * Number of audio tokens billed for this request.\n       */\n      audio_tokens?: number;\n\n      /**\n       * Number of text tokens billed for this request.\n       */\n      text_tokens?: number;\n    }\n  }\n\n  /**\n   * Usage statistics for models billed by audio input duration.\n   */\n  export interface Duration {\n    /**\n     * Duration of the input audio in seconds.\n     */\n    seconds: number;\n\n    /**\n     * The type of the usage object. Always `duration` for this variant.\n     */\n    type: 'duration';\n  }\n}\n\n/**\n * Represents a diarized transcription response returned by the model, including\n * the combined transcript and speaker-segment annotations.\n */\nexport interface TranscriptionDiarized {\n  /**\n   * Duration of the input audio in seconds.\n   */\n  duration: number;\n\n  /**\n   * Segments of the transcript annotated with timestamps and speaker labels.\n   */\n  segments: Array<TranscriptionDiarizedSegment>;\n\n  /**\n   * The type of task that was run. Always `transcribe`.\n   */\n  task: 'transcribe';\n\n  /**\n   * The concatenated transcript text for the entire audio input.\n   */\n  text: string;\n\n  /**\n   * Token or duration usage statistics for the request.\n   */\n  usage?: TranscriptionDiarized.Tokens | TranscriptionDiarized.Duration;\n}\n\nexport namespace TranscriptionDiarized {\n  /**\n   * Usage statistics for models billed by token usage.\n   */\n  export interface Tokens {\n    /**\n     * Number of input tokens billed for this request.\n     */\n    input_tokens: number;\n\n    /**\n     * Number of output tokens generated.\n     */\n    output_tokens: number;\n\n    /**\n     * Total number of tokens used (input + output).\n     */\n    total_tokens: number;\n\n    /**\n     * The type of the usage object. Always `tokens` for this variant.\n     */\n    type: 'tokens';\n\n    /**\n     * Details about the input tokens billed for this request.\n     */\n    input_token_details?: Tokens.InputTokenDetails;\n  }\n\n  export namespace Tokens {\n    /**\n     * Details about the input tokens billed for this request.\n     */\n    export interface InputTokenDetails {\n      /**\n       * Number of audio tokens billed for this request.\n       */\n      audio_tokens?: number;\n\n      /**\n       * Number of text tokens billed for this request.\n       */\n      text_tokens?: number;\n    }\n  }\n\n  /**\n   * Usage statistics for models billed by audio input duration.\n   */\n  export interface Duration {\n    /**\n     * Duration of the input audio in seconds.\n     */\n    seconds: number;\n\n    /**\n     * The type of the usage object. Always `duration` for this variant.\n     */\n    type: 'duration';\n  }\n}\n\n/**\n * A segment of diarized transcript text with speaker metadata.\n */\nexport interface TranscriptionDiarizedSegment {\n  /**\n   * Unique identifier for the segment.\n   */\n  id: string;\n\n  /**\n   * End timestamp of the segment in seconds.\n   */\n  end: number;\n\n  /**\n   * Speaker label for this segment. When known speakers are provided, the label\n   * matches `known_speaker_names[]`. Otherwise speakers are labeled sequentially\n   * using capital letters (`A`, `B`, ...).\n   */\n  speaker: string;\n\n  /**\n   * Start timestamp of the segment in seconds.\n   */\n  start: number;\n\n  /**\n   * Transcript text for this segment.\n   */\n  text: string;\n\n  /**\n   * The type of the segment. Always `transcript.text.segment`.\n   */\n  type: 'transcript.text.segment';\n}\n\nexport type TranscriptionInclude = 'logprobs';\n\nexport interface TranscriptionSegment {\n  /**\n   * Unique identifier of the segment.\n   */\n  id: number;\n\n  /**\n   * Average logprob of the segment. If the value is lower than -1, consider the\n   * logprobs failed.\n   */\n  avg_logprob: number;\n\n  /**\n   * Compression ratio of the segment. If the value is greater than 2.4, consider the\n   * compression failed.\n   */\n  compression_ratio: number;\n\n  /**\n   * End time of the segment in seconds.\n   */\n  end: number;\n\n  /**\n   * Probability of no speech in the segment. If the value is higher than 1.0 and the\n   * `avg_logprob` is below -1, consider this segment silent.\n   */\n  no_speech_prob: number;\n\n  /**\n   * Seek offset of the segment.\n   */\n  seek: number;\n\n  /**\n   * Start time of the segment in seconds.\n   */\n  start: number;\n\n  /**\n   * Temperature parameter used for generating the segment.\n   */\n  temperature: number;\n\n  /**\n   * Text content of the segment.\n   */\n  text: string;\n\n  /**\n   * Array of token IDs for the text content.\n   */\n  tokens: Array<number>;\n}\n\n/**\n * Emitted when a diarized transcription returns a completed segment with speaker\n * information. Only emitted when you\n * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n * with `stream` set to `true` and `response_format` set to `diarized_json`.\n */\nexport type TranscriptionStreamEvent =\n  | TranscriptionTextSegmentEvent\n  | TranscriptionTextDeltaEvent\n  | TranscriptionTextDoneEvent;\n\n/**\n * Emitted when there is an additional text delta. This is also the first event\n * emitted when the transcription starts. Only emitted when you\n * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n * with the `Stream` parameter set to `true`.\n */\nexport interface TranscriptionTextDeltaEvent {\n  /**\n   * The text delta that was additionally transcribed.\n   */\n  delta: string;\n\n  /**\n   * The type of the event. Always `transcript.text.delta`.\n   */\n  type: 'transcript.text.delta';\n\n  /**\n   * The log probabilities of the delta. Only included if you\n   * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n   * with the `include[]` parameter set to `logprobs`.\n   */\n  logprobs?: Array<TranscriptionTextDeltaEvent.Logprob>;\n\n  /**\n   * Identifier of the diarized segment that this delta belongs to. Only present when\n   * using `gpt-4o-transcribe-diarize`.\n   */\n  segment_id?: string;\n}\n\nexport namespace TranscriptionTextDeltaEvent {\n  export interface Logprob {\n    /**\n     * The token that was used to generate the log probability.\n     */\n    token?: string;\n\n    /**\n     * The bytes that were used to generate the log probability.\n     */\n    bytes?: Array<number>;\n\n    /**\n     * The log probability of the token.\n     */\n    logprob?: number;\n  }\n}\n\n/**\n * Emitted when the transcription is complete. Contains the complete transcription\n * text. Only emitted when you\n * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n * with the `Stream` parameter set to `true`.\n */\nexport interface TranscriptionTextDoneEvent {\n  /**\n   * The text that was transcribed.\n   */\n  text: string;\n\n  /**\n   * The type of the event. Always `transcript.text.done`.\n   */\n  type: 'transcript.text.done';\n\n  /**\n   * The log probabilities of the individual tokens in the transcription. Only\n   * included if you\n   * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n   * with the `include[]` parameter set to `logprobs`.\n   */\n  logprobs?: Array<TranscriptionTextDoneEvent.Logprob>;\n\n  /**\n   * Usage statistics for models billed by token usage.\n   */\n  usage?: TranscriptionTextDoneEvent.Usage;\n}\n\nexport namespace TranscriptionTextDoneEvent {\n  export interface Logprob {\n    /**\n     * The token that was used to generate the log probability.\n     */\n    token?: string;\n\n    /**\n     * The bytes that were used to generate the log probability.\n     */\n    bytes?: Array<number>;\n\n    /**\n     * The log probability of the token.\n     */\n    logprob?: number;\n  }\n\n  /**\n   * Usage statistics for models billed by token usage.\n   */\n  export interface Usage {\n    /**\n     * Number of input tokens billed for this request.\n     */\n    input_tokens: number;\n\n    /**\n     * Number of output tokens generated.\n     */\n    output_tokens: number;\n\n    /**\n     * Total number of tokens used (input + output).\n     */\n    total_tokens: number;\n\n    /**\n     * The type of the usage object. Always `tokens` for this variant.\n     */\n    type: 'tokens';\n\n    /**\n     * Details about the input tokens billed for this request.\n     */\n    input_token_details?: Usage.InputTokenDetails;\n  }\n\n  export namespace Usage {\n    /**\n     * Details about the input tokens billed for this request.\n     */\n    export interface InputTokenDetails {\n      /**\n       * Number of audio tokens billed for this request.\n       */\n      audio_tokens?: number;\n\n      /**\n       * Number of text tokens billed for this request.\n       */\n      text_tokens?: number;\n    }\n  }\n}\n\n/**\n * Emitted when a diarized transcription returns a completed segment with speaker\n * information. Only emitted when you\n * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n * with `stream` set to `true` and `response_format` set to `diarized_json`.\n */\nexport interface TranscriptionTextSegmentEvent {\n  /**\n   * Unique identifier for the segment.\n   */\n  id: string;\n\n  /**\n   * End timestamp of the segment in seconds.\n   */\n  end: number;\n\n  /**\n   * Speaker label for this segment.\n   */\n  speaker: string;\n\n  /**\n   * Start timestamp of the segment in seconds.\n   */\n  start: number;\n\n  /**\n   * Transcript text for this segment.\n   */\n  text: string;\n\n  /**\n   * The type of the event. Always `transcript.text.segment`.\n   */\n  type: 'transcript.text.segment';\n}\n\n/**\n * Represents a verbose json transcription response returned by model, based on the\n * provided input.\n */\nexport interface TranscriptionVerbose {\n  /**\n   * The duration of the input audio.\n   */\n  duration: number;\n\n  /**\n   * The language of the input audio.\n   */\n  language: string;\n\n  /**\n   * The transcribed text.\n   */\n  text: string;\n\n  /**\n   * Segments of the transcribed text and their corresponding details.\n   */\n  segments?: Array<TranscriptionSegment>;\n\n  /**\n   * Usage statistics for models billed by audio input duration.\n   */\n  usage?: TranscriptionVerbose.Usage;\n\n  /**\n   * Extracted words and their corresponding timestamps.\n   */\n  words?: Array<TranscriptionWord>;\n}\n\nexport namespace TranscriptionVerbose {\n  /**\n   * Usage statistics for models billed by audio input duration.\n   */\n  export interface Usage {\n    /**\n     * Duration of the input audio in seconds.\n     */\n    seconds: number;\n\n    /**\n     * The type of the usage object. Always `duration` for this variant.\n     */\n    type: 'duration';\n  }\n}\n\nexport interface TranscriptionWord {\n  /**\n   * End time of the word in seconds.\n   */\n  end: number;\n\n  /**\n   * Start time of the word in seconds.\n   */\n  start: number;\n\n  /**\n   * The text content of the word.\n   */\n  word: string;\n}\n\n/**\n * Represents a transcription response returned by model, based on the provided\n * input.\n */\nexport type TranscriptionCreateResponse = Transcription | TranscriptionDiarized | TranscriptionVerbose;\n\nexport type TranscriptionCreateParams<\n  ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined,\n> = TranscriptionCreateParamsNonStreaming<ResponseFormat> | TranscriptionCreateParamsStreaming;\n\nexport interface TranscriptionCreateParamsBase<\n  ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined,\n> {\n  /**\n   * The audio file object (not file name) to transcribe, in one of these formats:\n   * flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.\n   */\n  file: Uploadable;\n\n  /**\n   * ID of the model to use. The options are `gpt-4o-transcribe`,\n   * `gpt-4o-mini-transcribe`, `gpt-4o-mini-transcribe-2025-12-15`, `whisper-1`\n   * (which is powered by our open source Whisper V2 model), and\n   * `gpt-4o-transcribe-diarize`.\n   */\n  model: (string & {}) | AudioAPI.AudioModel;\n\n  /**\n   * Controls how the audio is cut into chunks. When set to `\"auto\"`, the server\n   * first normalizes loudness and then uses voice activity detection (VAD) to choose\n   * boundaries. `server_vad` object can be provided to tweak VAD detection\n   * parameters manually. If unset, the audio is transcribed as a single block.\n   * Required when using `gpt-4o-transcribe-diarize` for inputs longer than 30\n   * seconds.\n   */\n  chunking_strategy?: 'auto' | TranscriptionCreateParams.VadConfig | null;\n\n  /**\n   * Additional information to include in the transcription response. `logprobs` will\n   * return the log probabilities of the tokens in the response to understand the\n   * model's confidence in the transcription. `logprobs` only works with\n   * response_format set to `json` and only with the models `gpt-4o-transcribe`,\n   * `gpt-4o-mini-transcribe`, and `gpt-4o-mini-transcribe-2025-12-15`. This field is\n   * not supported when using `gpt-4o-transcribe-diarize`.\n   */\n  include?: Array<TranscriptionInclude>;\n\n  /**\n   * Optional list of speaker names that correspond to the audio samples provided in\n   * `known_speaker_references[]`. Each entry should be a short identifier (for\n   * example `customer` or `agent`). Up to 4 speakers are supported.\n   */\n  known_speaker_names?: Array<string>;\n\n  /**\n   * Optional list of audio samples (as\n   * [data URLs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs))\n   * that contain known speaker references matching `known_speaker_names[]`. Each\n   * sample must be between 2 and 10 seconds, and can use any of the same input audio\n   * formats supported by `file`.\n   */\n  known_speaker_references?: Array<string>;\n\n  /**\n   * The language of the input audio. Supplying the input language in\n   * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n   * format will improve accuracy and latency.\n   */\n  language?: string;\n\n  /**\n   * An optional text to guide the model's style or continue a previous audio\n   * segment. The\n   * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)\n   * should match the audio language. This field is not supported when using\n   * `gpt-4o-transcribe-diarize`.\n   */\n  prompt?: string;\n\n  /**\n   * The format of the output, in one of these options: `json`, `text`, `srt`,\n   * `verbose_json`, `vtt`, or `diarized_json`. For `gpt-4o-transcribe` and\n   * `gpt-4o-mini-transcribe`, the only supported format is `json`. For\n   * `gpt-4o-transcribe-diarize`, the supported formats are `json`, `text`, and\n   * `diarized_json`, with `diarized_json` required to receive speaker annotations.\n   */\n  response_format?: ResponseFormat;\n\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section of the Speech-to-Text guide](https://platform.openai.com/docs/guides/speech-to-text?lang=curl#streaming-transcriptions)\n   * for more information.\n   *\n   * Note: Streaming is not supported for the `whisper-1` model and will be ignored.\n   */\n  stream?: boolean | null;\n\n  /**\n   * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the\n   * output more random, while lower values like 0.2 will make it more focused and\n   * deterministic. If set to 0, the model will use\n   * [log probability](https://en.wikipedia.org/wiki/Log_probability) to\n   * automatically increase the temperature until certain thresholds are hit.\n   */\n  temperature?: number;\n\n  /**\n   * The timestamp granularities to populate for this transcription.\n   * `response_format` must be set `verbose_json` to use timestamp granularities.\n   * Either or both of these options are supported: `word`, or `segment`. Note: There\n   * is no additional latency for segment timestamps, but generating word timestamps\n   * incurs additional latency. This option is not available for\n   * `gpt-4o-transcribe-diarize`.\n   */\n  timestamp_granularities?: Array<'word' | 'segment'>;\n}\n\nexport namespace TranscriptionCreateParams {\n  export interface VadConfig {\n    /**\n     * Must be set to `server_vad` to enable manual chunking using server side VAD.\n     */\n    type: 'server_vad';\n\n    /**\n     * Amount of audio to include before the VAD detected speech (in milliseconds).\n     */\n    prefix_padding_ms?: number;\n\n    /**\n     * Duration of silence to detect speech stop (in milliseconds). With shorter values\n     * the model will respond more quickly, but may jump in on short pauses from the\n     * user.\n     */\n    silence_duration_ms?: number;\n\n    /**\n     * Sensitivity threshold (0.0 to 1.0) for voice activity detection. A higher\n     * threshold will require louder audio to activate the model, and thus might\n     * perform better in noisy environments.\n     */\n    threshold?: number;\n  }\n\n  export type TranscriptionCreateParamsNonStreaming = TranscriptionsAPI.TranscriptionCreateParamsNonStreaming;\n  export type TranscriptionCreateParamsStreaming = TranscriptionsAPI.TranscriptionCreateParamsStreaming;\n}\n\nexport interface TranscriptionCreateParamsNonStreaming<\n  ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined,\n> extends TranscriptionCreateParamsBase<ResponseFormat> {\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section of the Speech-to-Text guide](https://platform.openai.com/docs/guides/speech-to-text?lang=curl#streaming-transcriptions)\n   * for more information.\n   *\n   * Note: Streaming is not supported for the `whisper-1` model and will be ignored.\n   */\n  stream?: false | null;\n}\n\nexport interface TranscriptionCreateParamsStreaming extends TranscriptionCreateParamsBase {\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section of the Speech-to-Text guide](https://platform.openai.com/docs/guides/speech-to-text?lang=curl#streaming-transcriptions)\n   * for more information.\n   *\n   * Note: Streaming is not supported for the `whisper-1` model and will be ignored.\n   */\n  stream: true;\n}\n\nexport declare namespace Transcriptions {\n  export {\n    type Transcription as Transcription,\n    type TranscriptionDiarized as TranscriptionDiarized,\n    type TranscriptionDiarizedSegment as TranscriptionDiarizedSegment,\n    type TranscriptionInclude as TranscriptionInclude,\n    type TranscriptionSegment as TranscriptionSegment,\n    type TranscriptionStreamEvent as TranscriptionStreamEvent,\n    type TranscriptionTextDeltaEvent as TranscriptionTextDeltaEvent,\n    type TranscriptionTextDoneEvent as TranscriptionTextDoneEvent,\n    type TranscriptionTextSegmentEvent as TranscriptionTextSegmentEvent,\n    type TranscriptionVerbose as TranscriptionVerbose,\n    type TranscriptionWord as TranscriptionWord,\n    type TranscriptionCreateResponse as TranscriptionCreateResponse,\n    type TranscriptionCreateParams as TranscriptionCreateParams,\n    type TranscriptionCreateParamsNonStreaming as TranscriptionCreateParamsNonStreaming,\n    type TranscriptionCreateParamsStreaming as TranscriptionCreateParamsStreaming,\n  };\n}\n"
  },
  {
    "path": "src/resources/audio/translations.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as AudioAPI from './audio';\nimport * as TranscriptionsAPI from './transcriptions';\nimport { APIPromise } from '../../core/api-promise';\nimport { type Uploadable } from '../../core/uploads';\nimport { RequestOptions } from '../../internal/request-options';\nimport { multipartFormRequestOptions } from '../../internal/uploads';\n\n/**\n * Turn audio into text or text into audio.\n */\nexport class Translations extends APIResource {\n  /**\n   * Translates audio into English.\n   *\n   * @example\n   * ```ts\n   * const translation = await client.audio.translations.create({\n   *   file: fs.createReadStream('speech.mp3'),\n   *   model: 'whisper-1',\n   * });\n   * ```\n   */\n  create(\n    body: TranslationCreateParams<'json' | undefined>,\n    options?: RequestOptions,\n  ): APIPromise<Translation>;\n  create(\n    body: TranslationCreateParams<'verbose_json'>,\n    options?: RequestOptions,\n  ): APIPromise<TranslationVerbose>;\n  create(body: TranslationCreateParams<'text' | 'srt' | 'vtt'>, options?: RequestOptions): APIPromise<string>;\n  create(body: TranslationCreateParams, options?: RequestOptions): APIPromise<Translation>;\n  create(\n    body: TranslationCreateParams,\n    options?: RequestOptions,\n  ): APIPromise<TranslationCreateResponse | string> {\n    return this._client.post(\n      '/audio/translations',\n      multipartFormRequestOptions({ body, ...options, __metadata: { model: body.model } }, this._client),\n    );\n  }\n}\n\nexport interface Translation {\n  text: string;\n}\n\nexport interface TranslationVerbose {\n  /**\n   * The duration of the input audio.\n   */\n  duration: number;\n\n  /**\n   * The language of the output translation (always `english`).\n   */\n  language: string;\n\n  /**\n   * The translated text.\n   */\n  text: string;\n\n  /**\n   * Segments of the translated text and their corresponding details.\n   */\n  segments?: Array<TranscriptionsAPI.TranscriptionSegment>;\n}\n\nexport type TranslationCreateResponse = Translation | TranslationVerbose;\n\nexport interface TranslationCreateParams<\n  ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined,\n> {\n  /**\n   * The audio file object (not file name) translate, in one of these formats: flac,\n   * mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.\n   */\n  file: Uploadable;\n\n  /**\n   * ID of the model to use. Only `whisper-1` (which is powered by our open source\n   * Whisper V2 model) is currently available.\n   */\n  model: (string & {}) | AudioAPI.AudioModel;\n\n  /**\n   * An optional text to guide the model's style or continue a previous audio\n   * segment. The\n   * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)\n   * should be in English.\n   */\n  prompt?: string;\n\n  /**\n   * The format of the output, in one of these options: `json`, `text`, `srt`,\n   * `verbose_json`, or `vtt`.\n   */\n  response_format?: 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt';\n\n  /**\n   * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the\n   * output more random, while lower values like 0.2 will make it more focused and\n   * deterministic. If set to 0, the model will use\n   * [log probability](https://en.wikipedia.org/wiki/Log_probability) to\n   * automatically increase the temperature until certain thresholds are hit.\n   */\n  temperature?: number;\n}\n\nexport declare namespace Translations {\n  export {\n    type Translation as Translation,\n    type TranslationVerbose as TranslationVerbose,\n    type TranslationCreateResponse as TranslationCreateResponse,\n    type TranslationCreateParams as TranslationCreateParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/audio.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './audio/index';\n"
  },
  {
    "path": "src/resources/batches.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport * as BatchesAPI from './batches';\nimport * as Shared from './shared';\nimport { APIPromise } from '../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../core/pagination';\nimport { RequestOptions } from '../internal/request-options';\nimport { path } from '../internal/utils/path';\n\n/**\n * Create large batches of API requests to run asynchronously.\n */\nexport class Batches extends APIResource {\n  /**\n   * Creates and executes a batch from an uploaded file of requests\n   */\n  create(body: BatchCreateParams, options?: RequestOptions): APIPromise<Batch> {\n    return this._client.post('/batches', { body, ...options });\n  }\n\n  /**\n   * Retrieves a batch.\n   */\n  retrieve(batchID: string, options?: RequestOptions): APIPromise<Batch> {\n    return this._client.get(path`/batches/${batchID}`, options);\n  }\n\n  /**\n   * List your organization's batches.\n   */\n  list(\n    query: BatchListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<BatchesPage, Batch> {\n    return this._client.getAPIList('/batches', CursorPage<Batch>, { query, ...options });\n  }\n\n  /**\n   * Cancels an in-progress batch. The batch will be in status `cancelling` for up to\n   * 10 minutes, before changing to `cancelled`, where it will have partial results\n   * (if any) available in the output file.\n   */\n  cancel(batchID: string, options?: RequestOptions): APIPromise<Batch> {\n    return this._client.post(path`/batches/${batchID}/cancel`, options);\n  }\n}\n\nexport type BatchesPage = CursorPage<Batch>;\n\nexport interface Batch {\n  id: string;\n\n  /**\n   * The time frame within which the batch should be processed.\n   */\n  completion_window: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the batch was created.\n   */\n  created_at: number;\n\n  /**\n   * The OpenAI API endpoint used by the batch.\n   */\n  endpoint: string;\n\n  /**\n   * The ID of the input file for the batch.\n   */\n  input_file_id: string;\n\n  /**\n   * The object type, which is always `batch`.\n   */\n  object: 'batch';\n\n  /**\n   * The current status of the batch.\n   */\n  status:\n    | 'validating'\n    | 'failed'\n    | 'in_progress'\n    | 'finalizing'\n    | 'completed'\n    | 'expired'\n    | 'cancelling'\n    | 'cancelled';\n\n  /**\n   * The Unix timestamp (in seconds) for when the batch was cancelled.\n   */\n  cancelled_at?: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the batch started cancelling.\n   */\n  cancelling_at?: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the batch was completed.\n   */\n  completed_at?: number;\n\n  /**\n   * The ID of the file containing the outputs of requests with errors.\n   */\n  error_file_id?: string;\n\n  errors?: Batch.Errors;\n\n  /**\n   * The Unix timestamp (in seconds) for when the batch expired.\n   */\n  expired_at?: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the batch will expire.\n   */\n  expires_at?: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the batch failed.\n   */\n  failed_at?: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the batch started finalizing.\n   */\n  finalizing_at?: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the batch started processing.\n   */\n  in_progress_at?: number;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * Model ID used to process the batch, like `gpt-5-2025-08-07`. OpenAI offers a\n   * wide range of models with different capabilities, performance characteristics,\n   * and price points. Refer to the\n   * [model guide](https://platform.openai.com/docs/models) to browse and compare\n   * available models.\n   */\n  model?: string;\n\n  /**\n   * The ID of the file containing the outputs of successfully executed requests.\n   */\n  output_file_id?: string;\n\n  /**\n   * The request counts for different statuses within the batch.\n   */\n  request_counts?: BatchRequestCounts;\n\n  /**\n   * Represents token usage details including input tokens, output tokens, a\n   * breakdown of output tokens, and the total tokens used. Only populated on batches\n   * created after September 7, 2025.\n   */\n  usage?: BatchUsage;\n}\n\nexport namespace Batch {\n  export interface Errors {\n    data?: Array<BatchesAPI.BatchError>;\n\n    /**\n     * The object type, which is always `list`.\n     */\n    object?: string;\n  }\n}\n\nexport interface BatchError {\n  /**\n   * An error code identifying the error type.\n   */\n  code?: string;\n\n  /**\n   * The line number of the input file where the error occurred, if applicable.\n   */\n  line?: number | null;\n\n  /**\n   * A human-readable message providing more details about the error.\n   */\n  message?: string;\n\n  /**\n   * The name of the parameter that caused the error, if applicable.\n   */\n  param?: string | null;\n}\n\n/**\n * The request counts for different statuses within the batch.\n */\nexport interface BatchRequestCounts {\n  /**\n   * Number of requests that have been completed successfully.\n   */\n  completed: number;\n\n  /**\n   * Number of requests that have failed.\n   */\n  failed: number;\n\n  /**\n   * Total number of requests in the batch.\n   */\n  total: number;\n}\n\n/**\n * Represents token usage details including input tokens, output tokens, a\n * breakdown of output tokens, and the total tokens used. Only populated on batches\n * created after September 7, 2025.\n */\nexport interface BatchUsage {\n  /**\n   * The number of input tokens.\n   */\n  input_tokens: number;\n\n  /**\n   * A detailed breakdown of the input tokens.\n   */\n  input_tokens_details: BatchUsage.InputTokensDetails;\n\n  /**\n   * The number of output tokens.\n   */\n  output_tokens: number;\n\n  /**\n   * A detailed breakdown of the output tokens.\n   */\n  output_tokens_details: BatchUsage.OutputTokensDetails;\n\n  /**\n   * The total number of tokens used.\n   */\n  total_tokens: number;\n}\n\nexport namespace BatchUsage {\n  /**\n   * A detailed breakdown of the input tokens.\n   */\n  export interface InputTokensDetails {\n    /**\n     * The number of tokens that were retrieved from the cache.\n     * [More on prompt caching](https://platform.openai.com/docs/guides/prompt-caching).\n     */\n    cached_tokens: number;\n  }\n\n  /**\n   * A detailed breakdown of the output tokens.\n   */\n  export interface OutputTokensDetails {\n    /**\n     * The number of reasoning tokens.\n     */\n    reasoning_tokens: number;\n  }\n}\n\nexport interface BatchCreateParams {\n  /**\n   * The time frame within which the batch should be processed. Currently only `24h`\n   * is supported.\n   */\n  completion_window: '24h';\n\n  /**\n   * The endpoint to be used for all requests in the batch. Currently\n   * `/v1/responses`, `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`,\n   * `/v1/moderations`, `/v1/images/generations`, `/v1/images/edits`, and\n   * `/v1/videos` are supported. Note that `/v1/embeddings` batches are also\n   * restricted to a maximum of 50,000 embedding inputs across all requests in the\n   * batch.\n   */\n  endpoint:\n    | '/v1/responses'\n    | '/v1/chat/completions'\n    | '/v1/embeddings'\n    | '/v1/completions'\n    | '/v1/moderations'\n    | '/v1/images/generations'\n    | '/v1/images/edits'\n    | '/v1/videos';\n\n  /**\n   * The ID of an uploaded file that contains requests for the new batch.\n   *\n   * See [upload file](https://platform.openai.com/docs/api-reference/files/create)\n   * for how to upload a file.\n   *\n   * Your input file must be formatted as a\n   * [JSONL file](https://platform.openai.com/docs/api-reference/batch/request-input),\n   * and must be uploaded with the purpose `batch`. The file can contain up to 50,000\n   * requests, and can be up to 200 MB in size.\n   */\n  input_file_id: string;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The expiration policy for the output and/or error file that are generated for a\n   * batch.\n   */\n  output_expires_after?: BatchCreateParams.OutputExpiresAfter;\n}\n\nexport namespace BatchCreateParams {\n  /**\n   * The expiration policy for the output and/or error file that are generated for a\n   * batch.\n   */\n  export interface OutputExpiresAfter {\n    /**\n     * Anchor timestamp after which the expiration policy applies. Supported anchors:\n     * `created_at`. Note that the anchor is the file creation time, not the time the\n     * batch is created.\n     */\n    anchor: 'created_at';\n\n    /**\n     * The number of seconds after the anchor time that the file will expire. Must be\n     * between 3600 (1 hour) and 2592000 (30 days).\n     */\n    seconds: number;\n  }\n}\n\nexport interface BatchListParams extends CursorPageParams {}\n\nexport declare namespace Batches {\n  export {\n    type Batch as Batch,\n    type BatchError as BatchError,\n    type BatchRequestCounts as BatchRequestCounts,\n    type BatchUsage as BatchUsage,\n    type BatchesPage as BatchesPage,\n    type BatchCreateParams as BatchCreateParams,\n    type BatchListParams as BatchListParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/beta/assistants.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as MessagesAPI from './threads/messages';\nimport * as ThreadsAPI from './threads/threads';\nimport * as RunsAPI from './threads/runs/runs';\nimport * as StepsAPI from './threads/runs/steps';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\nimport { AssistantStream } from '../../lib/AssistantStream';\n\n/**\n * Build Assistants that can call models and use tools.\n */\nexport class Assistants extends APIResource {\n  /**\n   * Create an assistant with a model and instructions.\n   *\n   * @deprecated\n   */\n  create(body: AssistantCreateParams, options?: RequestOptions): APIPromise<Assistant> {\n    return this._client.post('/assistants', {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Retrieves an assistant.\n   *\n   * @deprecated\n   */\n  retrieve(assistantID: string, options?: RequestOptions): APIPromise<Assistant> {\n    return this._client.get(path`/assistants/${assistantID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Modifies an assistant.\n   *\n   * @deprecated\n   */\n  update(assistantID: string, body: AssistantUpdateParams, options?: RequestOptions): APIPromise<Assistant> {\n    return this._client.post(path`/assistants/${assistantID}`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Returns a list of assistants.\n   *\n   * @deprecated\n   */\n  list(\n    query: AssistantListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<AssistantsPage, Assistant> {\n    return this._client.getAPIList('/assistants', CursorPage<Assistant>, {\n      query,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Delete an assistant.\n   *\n   * @deprecated\n   */\n  delete(assistantID: string, options?: RequestOptions): APIPromise<AssistantDeleted> {\n    return this._client.delete(path`/assistants/${assistantID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n}\n\nexport type AssistantsPage = CursorPage<Assistant>;\n\n/**\n * @deprecated Represents an `assistant` that can call the model and use tools.\n */\nexport interface Assistant {\n  /**\n   * The identifier, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the assistant was created.\n   */\n  created_at: number;\n\n  /**\n   * The description of the assistant. The maximum length is 512 characters.\n   */\n  description: string | null;\n\n  /**\n   * The system instructions that the assistant uses. The maximum length is 256,000\n   * characters.\n   */\n  instructions: string | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * ID of the model to use. You can use the\n   * [List models](https://platform.openai.com/docs/api-reference/models/list) API to\n   * see all of your available models, or see our\n   * [Model overview](https://platform.openai.com/docs/models) for descriptions of\n   * them.\n   */\n  model: string;\n\n  /**\n   * The name of the assistant. The maximum length is 256 characters.\n   */\n  name: string | null;\n\n  /**\n   * The object type, which is always `assistant`.\n   */\n  object: 'assistant';\n\n  /**\n   * A list of tool enabled on the assistant. There can be a maximum of 128 tools per\n   * assistant. Tools can be of types `code_interpreter`, `file_search`, or\n   * `function`.\n   */\n  tools: Array<AssistantTool>;\n\n  /**\n   * Specifies the format that the model must output. Compatible with\n   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n   * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n   * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n   *\n   * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n   * Outputs which ensures the model will match your supplied JSON schema. Learn more\n   * in the\n   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n   *\n   * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n   * message the model generates is valid JSON.\n   *\n   * **Important:** when using JSON mode, you **must** also instruct the model to\n   * produce JSON yourself via a system or user message. Without this, the model may\n   * generate an unending stream of whitespace until the generation reaches the token\n   * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n   * the message content may be partially cut off if `finish_reason=\"length\"`, which\n   * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n   * max context length.\n   */\n  response_format?: ThreadsAPI.AssistantResponseFormatOption | null;\n\n  /**\n   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n   * make the output more random, while lower values like 0.2 will make it more\n   * focused and deterministic.\n   */\n  temperature?: number | null;\n\n  /**\n   * A set of resources that are used by the assistant's tools. The resources are\n   * specific to the type of tool. For example, the `code_interpreter` tool requires\n   * a list of file IDs, while the `file_search` tool requires a list of vector store\n   * IDs.\n   */\n  tool_resources?: Assistant.ToolResources | null;\n\n  /**\n   * An alternative to sampling with temperature, called nucleus sampling, where the\n   * model considers the results of the tokens with top_p probability mass. So 0.1\n   * means only the tokens comprising the top 10% probability mass are considered.\n   *\n   * We generally recommend altering this or temperature but not both.\n   */\n  top_p?: number | null;\n}\n\nexport namespace Assistant {\n  /**\n   * A set of resources that are used by the assistant's tools. The resources are\n   * specific to the type of tool. For example, the `code_interpreter` tool requires\n   * a list of file IDs, while the `file_search` tool requires a list of vector store\n   * IDs.\n   */\n  export interface ToolResources {\n    code_interpreter?: ToolResources.CodeInterpreter;\n\n    file_search?: ToolResources.FileSearch;\n  }\n\n  export namespace ToolResources {\n    export interface CodeInterpreter {\n      /**\n       * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n       * available to the `code_interpreter`` tool. There can be a maximum of 20 files\n       * associated with the tool.\n       */\n      file_ids?: Array<string>;\n    }\n\n    export interface FileSearch {\n      /**\n       * The ID of the\n       * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n       * attached to this assistant. There can be a maximum of 1 vector store attached to\n       * the assistant.\n       */\n      vector_store_ids?: Array<string>;\n    }\n  }\n}\n\nexport interface AssistantDeleted {\n  id: string;\n\n  deleted: boolean;\n\n  object: 'assistant.deleted';\n}\n\n/**\n * Represents an event emitted when streaming a Run.\n *\n * Each event in a server-sent events stream has an `event` and `data` property:\n *\n * ```\n * event: thread.created\n * data: {\"id\": \"thread_123\", \"object\": \"thread\", ...}\n * ```\n *\n * We emit events whenever a new object is created, transitions to a new state, or\n * is being streamed in parts (deltas). For example, we emit `thread.run.created`\n * when a new run is created, `thread.run.completed` when a run completes, and so\n * on. When an Assistant chooses to create a message during a run, we emit a\n * `thread.message.created event`, a `thread.message.in_progress` event, many\n * `thread.message.delta` events, and finally a `thread.message.completed` event.\n *\n * We may add additional events over time, so we recommend handling unknown events\n * gracefully in your code. See the\n * [Assistants API quickstart](https://platform.openai.com/docs/assistants/overview)\n * to learn how to integrate the Assistants API with streaming.\n */\nexport type AssistantStreamEvent =\n  | AssistantStreamEvent.ThreadCreated\n  | AssistantStreamEvent.ThreadRunCreated\n  | AssistantStreamEvent.ThreadRunQueued\n  | AssistantStreamEvent.ThreadRunInProgress\n  | AssistantStreamEvent.ThreadRunRequiresAction\n  | AssistantStreamEvent.ThreadRunCompleted\n  | AssistantStreamEvent.ThreadRunIncomplete\n  | AssistantStreamEvent.ThreadRunFailed\n  | AssistantStreamEvent.ThreadRunCancelling\n  | AssistantStreamEvent.ThreadRunCancelled\n  | AssistantStreamEvent.ThreadRunExpired\n  | AssistantStreamEvent.ThreadRunStepCreated\n  | AssistantStreamEvent.ThreadRunStepInProgress\n  | AssistantStreamEvent.ThreadRunStepDelta\n  | AssistantStreamEvent.ThreadRunStepCompleted\n  | AssistantStreamEvent.ThreadRunStepFailed\n  | AssistantStreamEvent.ThreadRunStepCancelled\n  | AssistantStreamEvent.ThreadRunStepExpired\n  | AssistantStreamEvent.ThreadMessageCreated\n  | AssistantStreamEvent.ThreadMessageInProgress\n  | AssistantStreamEvent.ThreadMessageDelta\n  | AssistantStreamEvent.ThreadMessageCompleted\n  | AssistantStreamEvent.ThreadMessageIncomplete\n  | AssistantStreamEvent.ErrorEvent;\n\nexport namespace AssistantStreamEvent {\n  /**\n   * Occurs when a new\n   * [thread](https://platform.openai.com/docs/api-reference/threads/object) is\n   * created.\n   */\n  export interface ThreadCreated {\n    /**\n     * Represents a thread that contains\n     * [messages](https://platform.openai.com/docs/api-reference/messages).\n     */\n    data: ThreadsAPI.Thread;\n\n    event: 'thread.created';\n\n    /**\n     * Whether to enable input audio transcription.\n     */\n    enabled?: boolean;\n  }\n\n  /**\n   * Occurs when a new\n   * [run](https://platform.openai.com/docs/api-reference/runs/object) is created.\n   */\n  export interface ThreadRunCreated {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.created';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * moves to a `queued` status.\n   */\n  export interface ThreadRunQueued {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.queued';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * moves to an `in_progress` status.\n   */\n  export interface ThreadRunInProgress {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.in_progress';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * moves to a `requires_action` status.\n   */\n  export interface ThreadRunRequiresAction {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.requires_action';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * is completed.\n   */\n  export interface ThreadRunCompleted {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.completed';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * ends with status `incomplete`.\n   */\n  export interface ThreadRunIncomplete {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.incomplete';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * fails.\n   */\n  export interface ThreadRunFailed {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.failed';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * moves to a `cancelling` status.\n   */\n  export interface ThreadRunCancelling {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.cancelling';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * is cancelled.\n   */\n  export interface ThreadRunCancelled {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.cancelled';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * expires.\n   */\n  export interface ThreadRunExpired {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.expired';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * is created.\n   */\n  export interface ThreadRunStepCreated {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.created';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * moves to an `in_progress` state.\n   */\n  export interface ThreadRunStepInProgress {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.in_progress';\n  }\n\n  /**\n   * Occurs when parts of a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * are being streamed.\n   */\n  export interface ThreadRunStepDelta {\n    /**\n     * Represents a run step delta i.e. any changed fields on a run step during\n     * streaming.\n     */\n    data: StepsAPI.RunStepDeltaEvent;\n\n    event: 'thread.run.step.delta';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * is completed.\n   */\n  export interface ThreadRunStepCompleted {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.completed';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * fails.\n   */\n  export interface ThreadRunStepFailed {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.failed';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * is cancelled.\n   */\n  export interface ThreadRunStepCancelled {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.cancelled';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * expires.\n   */\n  export interface ThreadRunStepExpired {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.expired';\n  }\n\n  /**\n   * Occurs when a\n   * [message](https://platform.openai.com/docs/api-reference/messages/object) is\n   * created.\n   */\n  export interface ThreadMessageCreated {\n    /**\n     * Represents a message within a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: MessagesAPI.Message;\n\n    event: 'thread.message.created';\n  }\n\n  /**\n   * Occurs when a\n   * [message](https://platform.openai.com/docs/api-reference/messages/object) moves\n   * to an `in_progress` state.\n   */\n  export interface ThreadMessageInProgress {\n    /**\n     * Represents a message within a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: MessagesAPI.Message;\n\n    event: 'thread.message.in_progress';\n  }\n\n  /**\n   * Occurs when parts of a\n   * [Message](https://platform.openai.com/docs/api-reference/messages/object) are\n   * being streamed.\n   */\n  export interface ThreadMessageDelta {\n    /**\n     * Represents a message delta i.e. any changed fields on a message during\n     * streaming.\n     */\n    data: MessagesAPI.MessageDeltaEvent;\n\n    event: 'thread.message.delta';\n  }\n\n  /**\n   * Occurs when a\n   * [message](https://platform.openai.com/docs/api-reference/messages/object) is\n   * completed.\n   */\n  export interface ThreadMessageCompleted {\n    /**\n     * Represents a message within a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: MessagesAPI.Message;\n\n    event: 'thread.message.completed';\n  }\n\n  /**\n   * Occurs when a\n   * [message](https://platform.openai.com/docs/api-reference/messages/object) ends\n   * before it is completed.\n   */\n  export interface ThreadMessageIncomplete {\n    /**\n     * Represents a message within a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: MessagesAPI.Message;\n\n    event: 'thread.message.incomplete';\n  }\n\n  /**\n   * Occurs when an\n   * [error](https://platform.openai.com/docs/guides/error-codes#api-errors) occurs.\n   * This can happen due to an internal server error or a timeout.\n   */\n  export interface ErrorEvent {\n    data: Shared.ErrorObject;\n\n    event: 'error';\n  }\n}\n\nexport type AssistantTool = CodeInterpreterTool | FileSearchTool | FunctionTool;\n\nexport interface CodeInterpreterTool {\n  /**\n   * The type of tool being defined: `code_interpreter`\n   */\n  type: 'code_interpreter';\n}\n\nexport interface FileSearchTool {\n  /**\n   * The type of tool being defined: `file_search`\n   */\n  type: 'file_search';\n\n  /**\n   * Overrides for the file search tool.\n   */\n  file_search?: FileSearchTool.FileSearch;\n}\n\nexport namespace FileSearchTool {\n  /**\n   * Overrides for the file search tool.\n   */\n  export interface FileSearch {\n    /**\n     * The maximum number of results the file search tool should output. The default is\n     * 20 for `gpt-4*` models and 5 for `gpt-3.5-turbo`. This number should be between\n     * 1 and 50 inclusive.\n     *\n     * Note that the file search tool may output fewer than `max_num_results` results.\n     * See the\n     * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n     * for more information.\n     */\n    max_num_results?: number;\n\n    /**\n     * The ranking options for the file search. If not specified, the file search tool\n     * will use the `auto` ranker and a score_threshold of 0.\n     *\n     * See the\n     * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n     * for more information.\n     */\n    ranking_options?: FileSearch.RankingOptions;\n  }\n\n  export namespace FileSearch {\n    /**\n     * The ranking options for the file search. If not specified, the file search tool\n     * will use the `auto` ranker and a score_threshold of 0.\n     *\n     * See the\n     * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n     * for more information.\n     */\n    export interface RankingOptions {\n      /**\n       * The score threshold for the file search. All values must be a floating point\n       * number between 0 and 1.\n       */\n      score_threshold: number;\n\n      /**\n       * The ranker to use for the file search. If not specified will use the `auto`\n       * ranker.\n       */\n      ranker?: 'auto' | 'default_2024_08_21';\n    }\n  }\n}\n\nexport interface FunctionTool {\n  function: Shared.FunctionDefinition;\n\n  /**\n   * The type of tool being defined: `function`\n   */\n  type: 'function';\n}\n\n/**\n * Occurs when a\n * [message](https://platform.openai.com/docs/api-reference/messages/object) is\n * created.\n */\nexport type MessageStreamEvent =\n  | MessageStreamEvent.ThreadMessageCreated\n  | MessageStreamEvent.ThreadMessageInProgress\n  | MessageStreamEvent.ThreadMessageDelta\n  | MessageStreamEvent.ThreadMessageCompleted\n  | MessageStreamEvent.ThreadMessageIncomplete;\n\nexport namespace MessageStreamEvent {\n  /**\n   * Occurs when a\n   * [message](https://platform.openai.com/docs/api-reference/messages/object) is\n   * created.\n   */\n  export interface ThreadMessageCreated {\n    /**\n     * Represents a message within a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: MessagesAPI.Message;\n\n    event: 'thread.message.created';\n  }\n\n  /**\n   * Occurs when a\n   * [message](https://platform.openai.com/docs/api-reference/messages/object) moves\n   * to an `in_progress` state.\n   */\n  export interface ThreadMessageInProgress {\n    /**\n     * Represents a message within a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: MessagesAPI.Message;\n\n    event: 'thread.message.in_progress';\n  }\n\n  /**\n   * Occurs when parts of a\n   * [Message](https://platform.openai.com/docs/api-reference/messages/object) are\n   * being streamed.\n   */\n  export interface ThreadMessageDelta {\n    /**\n     * Represents a message delta i.e. any changed fields on a message during\n     * streaming.\n     */\n    data: MessagesAPI.MessageDeltaEvent;\n\n    event: 'thread.message.delta';\n  }\n\n  /**\n   * Occurs when a\n   * [message](https://platform.openai.com/docs/api-reference/messages/object) is\n   * completed.\n   */\n  export interface ThreadMessageCompleted {\n    /**\n     * Represents a message within a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: MessagesAPI.Message;\n\n    event: 'thread.message.completed';\n  }\n\n  /**\n   * Occurs when a\n   * [message](https://platform.openai.com/docs/api-reference/messages/object) ends\n   * before it is completed.\n   */\n  export interface ThreadMessageIncomplete {\n    /**\n     * Represents a message within a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: MessagesAPI.Message;\n\n    event: 'thread.message.incomplete';\n  }\n}\n\n/**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * is created.\n */\nexport type RunStepStreamEvent =\n  | RunStepStreamEvent.ThreadRunStepCreated\n  | RunStepStreamEvent.ThreadRunStepInProgress\n  | RunStepStreamEvent.ThreadRunStepDelta\n  | RunStepStreamEvent.ThreadRunStepCompleted\n  | RunStepStreamEvent.ThreadRunStepFailed\n  | RunStepStreamEvent.ThreadRunStepCancelled\n  | RunStepStreamEvent.ThreadRunStepExpired;\n\nexport namespace RunStepStreamEvent {\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * is created.\n   */\n  export interface ThreadRunStepCreated {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.created';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * moves to an `in_progress` state.\n   */\n  export interface ThreadRunStepInProgress {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.in_progress';\n  }\n\n  /**\n   * Occurs when parts of a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * are being streamed.\n   */\n  export interface ThreadRunStepDelta {\n    /**\n     * Represents a run step delta i.e. any changed fields on a run step during\n     * streaming.\n     */\n    data: StepsAPI.RunStepDeltaEvent;\n\n    event: 'thread.run.step.delta';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * is completed.\n   */\n  export interface ThreadRunStepCompleted {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.completed';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * fails.\n   */\n  export interface ThreadRunStepFailed {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.failed';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * is cancelled.\n   */\n  export interface ThreadRunStepCancelled {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.cancelled';\n  }\n\n  /**\n   * Occurs when a\n   * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n   * expires.\n   */\n  export interface ThreadRunStepExpired {\n    /**\n     * Represents a step in execution of a run.\n     */\n    data: StepsAPI.RunStep;\n\n    event: 'thread.run.step.expired';\n  }\n}\n\n/**\n * Occurs when a new\n * [run](https://platform.openai.com/docs/api-reference/runs/object) is created.\n */\nexport type RunStreamEvent =\n  | RunStreamEvent.ThreadRunCreated\n  | RunStreamEvent.ThreadRunQueued\n  | RunStreamEvent.ThreadRunInProgress\n  | RunStreamEvent.ThreadRunRequiresAction\n  | RunStreamEvent.ThreadRunCompleted\n  | RunStreamEvent.ThreadRunIncomplete\n  | RunStreamEvent.ThreadRunFailed\n  | RunStreamEvent.ThreadRunCancelling\n  | RunStreamEvent.ThreadRunCancelled\n  | RunStreamEvent.ThreadRunExpired;\n\nexport namespace RunStreamEvent {\n  /**\n   * Occurs when a new\n   * [run](https://platform.openai.com/docs/api-reference/runs/object) is created.\n   */\n  export interface ThreadRunCreated {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.created';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * moves to a `queued` status.\n   */\n  export interface ThreadRunQueued {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.queued';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * moves to an `in_progress` status.\n   */\n  export interface ThreadRunInProgress {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.in_progress';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * moves to a `requires_action` status.\n   */\n  export interface ThreadRunRequiresAction {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.requires_action';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * is completed.\n   */\n  export interface ThreadRunCompleted {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.completed';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * ends with status `incomplete`.\n   */\n  export interface ThreadRunIncomplete {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.incomplete';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * fails.\n   */\n  export interface ThreadRunFailed {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.failed';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * moves to a `cancelling` status.\n   */\n  export interface ThreadRunCancelling {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.cancelling';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * is cancelled.\n   */\n  export interface ThreadRunCancelled {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.cancelled';\n  }\n\n  /**\n   * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n   * expires.\n   */\n  export interface ThreadRunExpired {\n    /**\n     * Represents an execution run on a\n     * [thread](https://platform.openai.com/docs/api-reference/threads).\n     */\n    data: RunsAPI.Run;\n\n    event: 'thread.run.expired';\n  }\n}\n\n/**\n * Occurs when a new\n * [thread](https://platform.openai.com/docs/api-reference/threads/object) is\n * created.\n */\nexport interface ThreadStreamEvent {\n  /**\n   * Represents a thread that contains\n   * [messages](https://platform.openai.com/docs/api-reference/messages).\n   */\n  data: ThreadsAPI.Thread;\n\n  event: 'thread.created';\n\n  /**\n   * Whether to enable input audio transcription.\n   */\n  enabled?: boolean;\n}\n\nexport interface AssistantCreateParams {\n  /**\n   * ID of the model to use. You can use the\n   * [List models](https://platform.openai.com/docs/api-reference/models/list) API to\n   * see all of your available models, or see our\n   * [Model overview](https://platform.openai.com/docs/models) for descriptions of\n   * them.\n   */\n  model: (string & {}) | Shared.ChatModel;\n\n  /**\n   * The description of the assistant. The maximum length is 512 characters.\n   */\n  description?: string | null;\n\n  /**\n   * The system instructions that the assistant uses. The maximum length is 256,000\n   * characters.\n   */\n  instructions?: string | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The name of the assistant. The maximum length is 256 characters.\n   */\n  name?: string | null;\n\n  /**\n   * Constrains effort on reasoning for\n   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n   * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n   * Reducing reasoning effort can result in faster responses and fewer tokens used\n   * on reasoning in a response.\n   *\n   * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n   *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n   *   calls are supported for all reasoning values in gpt-5.1.\n   * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n   *   support `none`.\n   * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n   * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n   */\n  reasoning_effort?: Shared.ReasoningEffort | null;\n\n  /**\n   * Specifies the format that the model must output. Compatible with\n   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n   * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n   * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n   *\n   * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n   * Outputs which ensures the model will match your supplied JSON schema. Learn more\n   * in the\n   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n   *\n   * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n   * message the model generates is valid JSON.\n   *\n   * **Important:** when using JSON mode, you **must** also instruct the model to\n   * produce JSON yourself via a system or user message. Without this, the model may\n   * generate an unending stream of whitespace until the generation reaches the token\n   * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n   * the message content may be partially cut off if `finish_reason=\"length\"`, which\n   * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n   * max context length.\n   */\n  response_format?: ThreadsAPI.AssistantResponseFormatOption | null;\n\n  /**\n   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n   * make the output more random, while lower values like 0.2 will make it more\n   * focused and deterministic.\n   */\n  temperature?: number | null;\n\n  /**\n   * A set of resources that are used by the assistant's tools. The resources are\n   * specific to the type of tool. For example, the `code_interpreter` tool requires\n   * a list of file IDs, while the `file_search` tool requires a list of vector store\n   * IDs.\n   */\n  tool_resources?: AssistantCreateParams.ToolResources | null;\n\n  /**\n   * A list of tool enabled on the assistant. There can be a maximum of 128 tools per\n   * assistant. Tools can be of types `code_interpreter`, `file_search`, or\n   * `function`.\n   */\n  tools?: Array<AssistantTool>;\n\n  /**\n   * An alternative to sampling with temperature, called nucleus sampling, where the\n   * model considers the results of the tokens with top_p probability mass. So 0.1\n   * means only the tokens comprising the top 10% probability mass are considered.\n   *\n   * We generally recommend altering this or temperature but not both.\n   */\n  top_p?: number | null;\n}\n\nexport namespace AssistantCreateParams {\n  /**\n   * A set of resources that are used by the assistant's tools. The resources are\n   * specific to the type of tool. For example, the `code_interpreter` tool requires\n   * a list of file IDs, while the `file_search` tool requires a list of vector store\n   * IDs.\n   */\n  export interface ToolResources {\n    code_interpreter?: ToolResources.CodeInterpreter;\n\n    file_search?: ToolResources.FileSearch;\n  }\n\n  export namespace ToolResources {\n    export interface CodeInterpreter {\n      /**\n       * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n       * available to the `code_interpreter` tool. There can be a maximum of 20 files\n       * associated with the tool.\n       */\n      file_ids?: Array<string>;\n    }\n\n    export interface FileSearch {\n      /**\n       * The\n       * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n       * attached to this assistant. There can be a maximum of 1 vector store attached to\n       * the assistant.\n       */\n      vector_store_ids?: Array<string>;\n\n      /**\n       * A helper to create a\n       * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n       * with file_ids and attach it to this assistant. There can be a maximum of 1\n       * vector store attached to the assistant.\n       */\n      vector_stores?: Array<FileSearch.VectorStore>;\n    }\n\n    export namespace FileSearch {\n      export interface VectorStore {\n        /**\n         * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n         * strategy.\n         */\n        chunking_strategy?: VectorStore.Auto | VectorStore.Static;\n\n        /**\n         * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to\n         * add to the vector store. For vector stores created before Nov 2025, there can be\n         * a maximum of 10,000 files in a vector store. For vector stores created starting\n         * in Nov 2025, the limit is 100,000,000 files.\n         */\n        file_ids?: Array<string>;\n\n        /**\n         * Set of 16 key-value pairs that can be attached to an object. This can be useful\n         * for storing additional information about the object in a structured format, and\n         * querying for objects via API or the dashboard.\n         *\n         * Keys are strings with a maximum length of 64 characters. Values are strings with\n         * a maximum length of 512 characters.\n         */\n        metadata?: Shared.Metadata | null;\n      }\n\n      export namespace VectorStore {\n        /**\n         * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of\n         * `800` and `chunk_overlap_tokens` of `400`.\n         */\n        export interface Auto {\n          /**\n           * Always `auto`.\n           */\n          type: 'auto';\n        }\n\n        export interface Static {\n          static: Static.Static;\n\n          /**\n           * Always `static`.\n           */\n          type: 'static';\n        }\n\n        export namespace Static {\n          export interface Static {\n            /**\n             * The number of tokens that overlap between chunks. The default value is `400`.\n             *\n             * Note that the overlap must not exceed half of `max_chunk_size_tokens`.\n             */\n            chunk_overlap_tokens: number;\n\n            /**\n             * The maximum number of tokens in each chunk. The default value is `800`. The\n             * minimum value is `100` and the maximum value is `4096`.\n             */\n            max_chunk_size_tokens: number;\n          }\n        }\n      }\n    }\n  }\n}\n\nexport interface AssistantUpdateParams {\n  /**\n   * The description of the assistant. The maximum length is 512 characters.\n   */\n  description?: string | null;\n\n  /**\n   * The system instructions that the assistant uses. The maximum length is 256,000\n   * characters.\n   */\n  instructions?: string | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * ID of the model to use. You can use the\n   * [List models](https://platform.openai.com/docs/api-reference/models/list) API to\n   * see all of your available models, or see our\n   * [Model overview](https://platform.openai.com/docs/models) for descriptions of\n   * them.\n   */\n  model?:\n    | (string & {})\n    | 'gpt-5'\n    | 'gpt-5-mini'\n    | 'gpt-5-nano'\n    | 'gpt-5-2025-08-07'\n    | 'gpt-5-mini-2025-08-07'\n    | 'gpt-5-nano-2025-08-07'\n    | 'gpt-4.1'\n    | 'gpt-4.1-mini'\n    | 'gpt-4.1-nano'\n    | 'gpt-4.1-2025-04-14'\n    | 'gpt-4.1-mini-2025-04-14'\n    | 'gpt-4.1-nano-2025-04-14'\n    | 'o3-mini'\n    | 'o3-mini-2025-01-31'\n    | 'o1'\n    | 'o1-2024-12-17'\n    | 'gpt-4o'\n    | 'gpt-4o-2024-11-20'\n    | 'gpt-4o-2024-08-06'\n    | 'gpt-4o-2024-05-13'\n    | 'gpt-4o-mini'\n    | 'gpt-4o-mini-2024-07-18'\n    | 'gpt-4.5-preview'\n    | 'gpt-4.5-preview-2025-02-27'\n    | 'gpt-4-turbo'\n    | 'gpt-4-turbo-2024-04-09'\n    | 'gpt-4-0125-preview'\n    | 'gpt-4-turbo-preview'\n    | 'gpt-4-1106-preview'\n    | 'gpt-4-vision-preview'\n    | 'gpt-4'\n    | 'gpt-4-0314'\n    | 'gpt-4-0613'\n    | 'gpt-4-32k'\n    | 'gpt-4-32k-0314'\n    | 'gpt-4-32k-0613'\n    | 'gpt-3.5-turbo'\n    | 'gpt-3.5-turbo-16k'\n    | 'gpt-3.5-turbo-0613'\n    | 'gpt-3.5-turbo-1106'\n    | 'gpt-3.5-turbo-0125'\n    | 'gpt-3.5-turbo-16k-0613';\n\n  /**\n   * The name of the assistant. The maximum length is 256 characters.\n   */\n  name?: string | null;\n\n  /**\n   * Constrains effort on reasoning for\n   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n   * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n   * Reducing reasoning effort can result in faster responses and fewer tokens used\n   * on reasoning in a response.\n   *\n   * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n   *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n   *   calls are supported for all reasoning values in gpt-5.1.\n   * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n   *   support `none`.\n   * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n   * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n   */\n  reasoning_effort?: Shared.ReasoningEffort | null;\n\n  /**\n   * Specifies the format that the model must output. Compatible with\n   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n   * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n   * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n   *\n   * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n   * Outputs which ensures the model will match your supplied JSON schema. Learn more\n   * in the\n   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n   *\n   * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n   * message the model generates is valid JSON.\n   *\n   * **Important:** when using JSON mode, you **must** also instruct the model to\n   * produce JSON yourself via a system or user message. Without this, the model may\n   * generate an unending stream of whitespace until the generation reaches the token\n   * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n   * the message content may be partially cut off if `finish_reason=\"length\"`, which\n   * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n   * max context length.\n   */\n  response_format?: ThreadsAPI.AssistantResponseFormatOption | null;\n\n  /**\n   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n   * make the output more random, while lower values like 0.2 will make it more\n   * focused and deterministic.\n   */\n  temperature?: number | null;\n\n  /**\n   * A set of resources that are used by the assistant's tools. The resources are\n   * specific to the type of tool. For example, the `code_interpreter` tool requires\n   * a list of file IDs, while the `file_search` tool requires a list of vector store\n   * IDs.\n   */\n  tool_resources?: AssistantUpdateParams.ToolResources | null;\n\n  /**\n   * A list of tool enabled on the assistant. There can be a maximum of 128 tools per\n   * assistant. Tools can be of types `code_interpreter`, `file_search`, or\n   * `function`.\n   */\n  tools?: Array<AssistantTool>;\n\n  /**\n   * An alternative to sampling with temperature, called nucleus sampling, where the\n   * model considers the results of the tokens with top_p probability mass. So 0.1\n   * means only the tokens comprising the top 10% probability mass are considered.\n   *\n   * We generally recommend altering this or temperature but not both.\n   */\n  top_p?: number | null;\n}\n\nexport namespace AssistantUpdateParams {\n  /**\n   * A set of resources that are used by the assistant's tools. The resources are\n   * specific to the type of tool. For example, the `code_interpreter` tool requires\n   * a list of file IDs, while the `file_search` tool requires a list of vector store\n   * IDs.\n   */\n  export interface ToolResources {\n    code_interpreter?: ToolResources.CodeInterpreter;\n\n    file_search?: ToolResources.FileSearch;\n  }\n\n  export namespace ToolResources {\n    export interface CodeInterpreter {\n      /**\n       * Overrides the list of\n       * [file](https://platform.openai.com/docs/api-reference/files) IDs made available\n       * to the `code_interpreter` tool. There can be a maximum of 20 files associated\n       * with the tool.\n       */\n      file_ids?: Array<string>;\n    }\n\n    export interface FileSearch {\n      /**\n       * Overrides the\n       * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n       * attached to this assistant. There can be a maximum of 1 vector store attached to\n       * the assistant.\n       */\n      vector_store_ids?: Array<string>;\n    }\n  }\n}\n\nexport interface AssistantListParams extends CursorPageParams {\n  /**\n   * A cursor for use in pagination. `before` is an object ID that defines your place\n   * in the list. For instance, if you make a list request and receive 100 objects,\n   * starting with obj_foo, your subsequent call can include before=obj_foo in order\n   * to fetch the previous page of the list.\n   */\n  before?: string;\n\n  /**\n   * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n   * order and `desc` for descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport declare namespace Assistants {\n  export {\n    type Assistant as Assistant,\n    type AssistantDeleted as AssistantDeleted,\n    type AssistantStreamEvent as AssistantStreamEvent,\n    type AssistantTool as AssistantTool,\n    type CodeInterpreterTool as CodeInterpreterTool,\n    type FileSearchTool as FileSearchTool,\n    type FunctionTool as FunctionTool,\n    type MessageStreamEvent as MessageStreamEvent,\n    type RunStepStreamEvent as RunStepStreamEvent,\n    type RunStreamEvent as RunStreamEvent,\n    type ThreadStreamEvent as ThreadStreamEvent,\n    type AssistantsPage as AssistantsPage,\n    type AssistantCreateParams as AssistantCreateParams,\n    type AssistantUpdateParams as AssistantUpdateParams,\n    type AssistantListParams as AssistantListParams,\n  };\n\n  export { AssistantStream };\n}\n"
  },
  {
    "path": "src/resources/beta/beta.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as AssistantsAPI from './assistants';\nimport {\n  Assistant,\n  AssistantCreateParams,\n  AssistantDeleted,\n  AssistantListParams,\n  AssistantStreamEvent,\n  AssistantTool,\n  AssistantUpdateParams,\n  Assistants,\n  AssistantsPage,\n  CodeInterpreterTool,\n  FileSearchTool,\n  FunctionTool,\n  MessageStreamEvent,\n  RunStepStreamEvent,\n  RunStreamEvent,\n  ThreadStreamEvent,\n} from './assistants';\nimport * as RealtimeAPI from './realtime/realtime';\nimport {\n  ConversationCreatedEvent,\n  ConversationItem,\n  ConversationItemContent,\n  ConversationItemCreateEvent,\n  ConversationItemCreatedEvent,\n  ConversationItemDeleteEvent,\n  ConversationItemDeletedEvent,\n  ConversationItemInputAudioTranscriptionCompletedEvent,\n  ConversationItemInputAudioTranscriptionDeltaEvent,\n  ConversationItemInputAudioTranscriptionFailedEvent,\n  ConversationItemRetrieveEvent,\n  ConversationItemTruncateEvent,\n  ConversationItemTruncatedEvent,\n  ConversationItemWithReference,\n  ErrorEvent,\n  InputAudioBufferAppendEvent,\n  InputAudioBufferClearEvent,\n  InputAudioBufferClearedEvent,\n  InputAudioBufferCommitEvent,\n  InputAudioBufferCommittedEvent,\n  InputAudioBufferSpeechStartedEvent,\n  InputAudioBufferSpeechStoppedEvent,\n  RateLimitsUpdatedEvent,\n  Realtime,\n  RealtimeClientEvent,\n  RealtimeResponse,\n  RealtimeResponseStatus,\n  RealtimeResponseUsage,\n  RealtimeServerEvent,\n  ResponseAudioDeltaEvent,\n  ResponseAudioDoneEvent,\n  ResponseAudioTranscriptDeltaEvent,\n  ResponseAudioTranscriptDoneEvent,\n  ResponseCancelEvent,\n  ResponseContentPartAddedEvent,\n  ResponseContentPartDoneEvent,\n  ResponseCreateEvent,\n  ResponseCreatedEvent,\n  ResponseDoneEvent,\n  ResponseFunctionCallArgumentsDeltaEvent,\n  ResponseFunctionCallArgumentsDoneEvent,\n  ResponseOutputItemAddedEvent,\n  ResponseOutputItemDoneEvent,\n  ResponseTextDeltaEvent,\n  ResponseTextDoneEvent,\n  SessionCreatedEvent,\n  SessionUpdateEvent,\n  SessionUpdatedEvent,\n  TranscriptionSessionUpdate,\n  TranscriptionSessionUpdatedEvent,\n} from './realtime/realtime';\nimport * as ChatKitAPI from './chatkit/chatkit';\nimport { ChatKit, ChatKitWorkflow } from './chatkit/chatkit';\nimport * as ThreadsAPI from './threads/threads';\nimport {\n  AssistantResponseFormatOption,\n  AssistantToolChoice,\n  AssistantToolChoiceFunction,\n  AssistantToolChoiceOption,\n  Thread,\n  ThreadCreateAndRunParams,\n  ThreadCreateAndRunParamsNonStreaming,\n  ThreadCreateAndRunParamsStreaming,\n  ThreadCreateAndRunPollParams,\n  ThreadCreateAndRunStreamParams,\n  ThreadCreateParams,\n  ThreadDeleted,\n  ThreadUpdateParams,\n  Threads,\n} from './threads/threads';\n\nexport class Beta extends APIResource {\n  realtime: RealtimeAPI.Realtime = new RealtimeAPI.Realtime(this._client);\n  chatkit: ChatKitAPI.ChatKit = new ChatKitAPI.ChatKit(this._client);\n  assistants: AssistantsAPI.Assistants = new AssistantsAPI.Assistants(this._client);\n  threads: ThreadsAPI.Threads = new ThreadsAPI.Threads(this._client);\n}\n\nBeta.Realtime = Realtime;\nBeta.ChatKit = ChatKit;\nBeta.Assistants = Assistants;\nBeta.Threads = Threads;\n\nexport declare namespace Beta {\n  export {\n    Realtime as Realtime,\n    type ConversationCreatedEvent as ConversationCreatedEvent,\n    type ConversationItem as ConversationItem,\n    type ConversationItemContent as ConversationItemContent,\n    type ConversationItemCreateEvent as ConversationItemCreateEvent,\n    type ConversationItemCreatedEvent as ConversationItemCreatedEvent,\n    type ConversationItemDeleteEvent as ConversationItemDeleteEvent,\n    type ConversationItemDeletedEvent as ConversationItemDeletedEvent,\n    type ConversationItemInputAudioTranscriptionCompletedEvent as ConversationItemInputAudioTranscriptionCompletedEvent,\n    type ConversationItemInputAudioTranscriptionDeltaEvent as ConversationItemInputAudioTranscriptionDeltaEvent,\n    type ConversationItemInputAudioTranscriptionFailedEvent as ConversationItemInputAudioTranscriptionFailedEvent,\n    type ConversationItemRetrieveEvent as ConversationItemRetrieveEvent,\n    type ConversationItemTruncateEvent as ConversationItemTruncateEvent,\n    type ConversationItemTruncatedEvent as ConversationItemTruncatedEvent,\n    type ConversationItemWithReference as ConversationItemWithReference,\n    type ErrorEvent as ErrorEvent,\n    type InputAudioBufferAppendEvent as InputAudioBufferAppendEvent,\n    type InputAudioBufferClearEvent as InputAudioBufferClearEvent,\n    type InputAudioBufferClearedEvent as InputAudioBufferClearedEvent,\n    type InputAudioBufferCommitEvent as InputAudioBufferCommitEvent,\n    type InputAudioBufferCommittedEvent as InputAudioBufferCommittedEvent,\n    type InputAudioBufferSpeechStartedEvent as InputAudioBufferSpeechStartedEvent,\n    type InputAudioBufferSpeechStoppedEvent as InputAudioBufferSpeechStoppedEvent,\n    type RateLimitsUpdatedEvent as RateLimitsUpdatedEvent,\n    type RealtimeClientEvent as RealtimeClientEvent,\n    type RealtimeResponse as RealtimeResponse,\n    type RealtimeResponseStatus as RealtimeResponseStatus,\n    type RealtimeResponseUsage as RealtimeResponseUsage,\n    type RealtimeServerEvent as RealtimeServerEvent,\n    type ResponseAudioDeltaEvent as ResponseAudioDeltaEvent,\n    type ResponseAudioDoneEvent as ResponseAudioDoneEvent,\n    type ResponseAudioTranscriptDeltaEvent as ResponseAudioTranscriptDeltaEvent,\n    type ResponseAudioTranscriptDoneEvent as ResponseAudioTranscriptDoneEvent,\n    type ResponseCancelEvent as ResponseCancelEvent,\n    type ResponseContentPartAddedEvent as ResponseContentPartAddedEvent,\n    type ResponseContentPartDoneEvent as ResponseContentPartDoneEvent,\n    type ResponseCreateEvent as ResponseCreateEvent,\n    type ResponseCreatedEvent as ResponseCreatedEvent,\n    type ResponseDoneEvent as ResponseDoneEvent,\n    type ResponseFunctionCallArgumentsDeltaEvent as ResponseFunctionCallArgumentsDeltaEvent,\n    type ResponseFunctionCallArgumentsDoneEvent as ResponseFunctionCallArgumentsDoneEvent,\n    type ResponseOutputItemAddedEvent as ResponseOutputItemAddedEvent,\n    type ResponseOutputItemDoneEvent as ResponseOutputItemDoneEvent,\n    type ResponseTextDeltaEvent as ResponseTextDeltaEvent,\n    type ResponseTextDoneEvent as ResponseTextDoneEvent,\n    type SessionCreatedEvent as SessionCreatedEvent,\n    type SessionUpdateEvent as SessionUpdateEvent,\n    type SessionUpdatedEvent as SessionUpdatedEvent,\n    type TranscriptionSessionUpdate as TranscriptionSessionUpdate,\n    type TranscriptionSessionUpdatedEvent as TranscriptionSessionUpdatedEvent,\n    ChatKit as ChatKit,\n    type ChatKitWorkflow as ChatKitWorkflow,\n  };\n\n  export {\n    Assistants as Assistants,\n    type Assistant as Assistant,\n    type AssistantDeleted as AssistantDeleted,\n    type AssistantStreamEvent as AssistantStreamEvent,\n    type AssistantTool as AssistantTool,\n    type CodeInterpreterTool as CodeInterpreterTool,\n    type FileSearchTool as FileSearchTool,\n    type FunctionTool as FunctionTool,\n    type MessageStreamEvent as MessageStreamEvent,\n    type RunStepStreamEvent as RunStepStreamEvent,\n    type RunStreamEvent as RunStreamEvent,\n    type ThreadStreamEvent as ThreadStreamEvent,\n    type AssistantsPage as AssistantsPage,\n    type AssistantCreateParams as AssistantCreateParams,\n    type AssistantUpdateParams as AssistantUpdateParams,\n    type AssistantListParams as AssistantListParams,\n  };\n\n  export {\n    Threads as Threads,\n    type AssistantResponseFormatOption as AssistantResponseFormatOption,\n    type AssistantToolChoice as AssistantToolChoice,\n    type AssistantToolChoiceFunction as AssistantToolChoiceFunction,\n    type AssistantToolChoiceOption as AssistantToolChoiceOption,\n    type Thread as Thread,\n    type ThreadDeleted as ThreadDeleted,\n    type ThreadCreateParams as ThreadCreateParams,\n    type ThreadUpdateParams as ThreadUpdateParams,\n    type ThreadCreateAndRunParams as ThreadCreateAndRunParams,\n    type ThreadCreateAndRunParamsNonStreaming as ThreadCreateAndRunParamsNonStreaming,\n    type ThreadCreateAndRunParamsStreaming as ThreadCreateAndRunParamsStreaming,\n    type ThreadCreateAndRunPollParams,\n    type ThreadCreateAndRunStreamParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/beta/chatkit/chatkit.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as SessionsAPI from './sessions';\nimport { SessionCreateParams, Sessions } from './sessions';\nimport * as ThreadsAPI from './threads';\nimport {\n  ChatKitAttachment,\n  ChatKitResponseOutputText,\n  ChatKitThread,\n  ChatKitThreadAssistantMessageItem,\n  ChatKitThreadItemList,\n  ChatKitThreadItemListDataPage,\n  ChatKitThreadUserMessageItem,\n  ChatKitThreadsPage,\n  ChatKitWidgetItem,\n  ChatSession,\n  ChatSessionAutomaticThreadTitling,\n  ChatSessionChatKitConfiguration,\n  ChatSessionChatKitConfigurationParam,\n  ChatSessionExpiresAfterParam,\n  ChatSessionFileUpload,\n  ChatSessionHistory,\n  ChatSessionRateLimits,\n  ChatSessionRateLimitsParam,\n  ChatSessionStatus,\n  ChatSessionWorkflowParam,\n  ThreadDeleteResponse,\n  ThreadListItemsParams,\n  ThreadListParams,\n  Threads,\n} from './threads';\n\nexport class ChatKit extends APIResource {\n  sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client);\n  threads: ThreadsAPI.Threads = new ThreadsAPI.Threads(this._client);\n}\n\n/**\n * Workflow metadata and state returned for the session.\n */\nexport interface ChatKitWorkflow {\n  /**\n   * Identifier of the workflow backing the session.\n   */\n  id: string;\n\n  /**\n   * State variable key-value pairs applied when invoking the workflow. Defaults to\n   * null when no overrides were provided.\n   */\n  state_variables: { [key: string]: string | boolean | number } | null;\n\n  /**\n   * Tracing settings applied to the workflow.\n   */\n  tracing: ChatKitWorkflow.Tracing;\n\n  /**\n   * Specific workflow version used for the session. Defaults to null when using the\n   * latest deployment.\n   */\n  version: string | null;\n}\n\nexport namespace ChatKitWorkflow {\n  /**\n   * Tracing settings applied to the workflow.\n   */\n  export interface Tracing {\n    /**\n     * Indicates whether tracing is enabled.\n     */\n    enabled: boolean;\n  }\n}\n\nChatKit.Sessions = Sessions;\nChatKit.Threads = Threads;\n\nexport declare namespace ChatKit {\n  export { type ChatKitWorkflow as ChatKitWorkflow };\n\n  export { Sessions as Sessions, type SessionCreateParams as SessionCreateParams };\n\n  export {\n    Threads as Threads,\n    type ChatSession as ChatSession,\n    type ChatSessionAutomaticThreadTitling as ChatSessionAutomaticThreadTitling,\n    type ChatSessionChatKitConfiguration as ChatSessionChatKitConfiguration,\n    type ChatSessionChatKitConfigurationParam as ChatSessionChatKitConfigurationParam,\n    type ChatSessionExpiresAfterParam as ChatSessionExpiresAfterParam,\n    type ChatSessionFileUpload as ChatSessionFileUpload,\n    type ChatSessionHistory as ChatSessionHistory,\n    type ChatSessionRateLimits as ChatSessionRateLimits,\n    type ChatSessionRateLimitsParam as ChatSessionRateLimitsParam,\n    type ChatSessionStatus as ChatSessionStatus,\n    type ChatSessionWorkflowParam as ChatSessionWorkflowParam,\n    type ChatKitAttachment as ChatKitAttachment,\n    type ChatKitResponseOutputText as ChatKitResponseOutputText,\n    type ChatKitThread as ChatKitThread,\n    type ChatKitThreadAssistantMessageItem as ChatKitThreadAssistantMessageItem,\n    type ChatKitThreadItemList as ChatKitThreadItemList,\n    type ChatKitThreadUserMessageItem as ChatKitThreadUserMessageItem,\n    type ChatKitWidgetItem as ChatKitWidgetItem,\n    type ThreadDeleteResponse as ThreadDeleteResponse,\n    type ChatKitThreadsPage as ChatKitThreadsPage,\n    type ChatKitThreadItemListDataPage as ChatKitThreadItemListDataPage,\n    type ThreadListParams as ThreadListParams,\n    type ThreadListItemsParams as ThreadListItemsParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/beta/chatkit/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { ChatKit, type ChatKitWorkflow } from './chatkit';\nexport { Sessions, type SessionCreateParams } from './sessions';\nexport {\n  Threads,\n  type ChatSession,\n  type ChatSessionAutomaticThreadTitling,\n  type ChatSessionChatKitConfiguration,\n  type ChatSessionChatKitConfigurationParam,\n  type ChatSessionExpiresAfterParam,\n  type ChatSessionFileUpload,\n  type ChatSessionHistory,\n  type ChatSessionRateLimits,\n  type ChatSessionRateLimitsParam,\n  type ChatSessionStatus,\n  type ChatSessionWorkflowParam,\n  type ChatKitAttachment,\n  type ChatKitResponseOutputText,\n  type ChatKitThread,\n  type ChatKitThreadAssistantMessageItem,\n  type ChatKitThreadItemList,\n  type ChatKitThreadUserMessageItem,\n  type ChatKitWidgetItem,\n  type ThreadDeleteResponse,\n  type ThreadListParams,\n  type ThreadListItemsParams,\n  type ChatKitThreadsPage,\n  type ChatKitThreadItemListDataPage,\n} from './threads';\n"
  },
  {
    "path": "src/resources/beta/chatkit/sessions.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ThreadsAPI from './threads';\nimport { APIPromise } from '../../../core/api-promise';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\nexport class Sessions extends APIResource {\n  /**\n   * Create a ChatKit session.\n   *\n   * @example\n   * ```ts\n   * const chatSession =\n   *   await client.beta.chatkit.sessions.create({\n   *     user: 'x',\n   *     workflow: { id: 'id' },\n   *   });\n   * ```\n   */\n  create(body: SessionCreateParams, options?: RequestOptions): APIPromise<ThreadsAPI.ChatSession> {\n    return this._client.post('/chatkit/sessions', {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Cancel an active ChatKit session and return its most recent metadata.\n   *\n   * Cancelling prevents new requests from using the issued client secret.\n   *\n   * @example\n   * ```ts\n   * const chatSession =\n   *   await client.beta.chatkit.sessions.cancel('cksess_123');\n   * ```\n   */\n  cancel(sessionID: string, options?: RequestOptions): APIPromise<ThreadsAPI.ChatSession> {\n    return this._client.post(path`/chatkit/sessions/${sessionID}/cancel`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),\n    });\n  }\n}\n\nexport interface SessionCreateParams {\n  /**\n   * A free-form string that identifies your end user; ensures this Session can\n   * access other objects that have the same `user` scope.\n   */\n  user: string;\n\n  /**\n   * Workflow that powers the session.\n   */\n  workflow: ThreadsAPI.ChatSessionWorkflowParam;\n\n  /**\n   * Optional overrides for ChatKit runtime configuration features\n   */\n  chatkit_configuration?: ThreadsAPI.ChatSessionChatKitConfigurationParam;\n\n  /**\n   * Optional override for session expiration timing in seconds from creation.\n   * Defaults to 10 minutes.\n   */\n  expires_after?: ThreadsAPI.ChatSessionExpiresAfterParam;\n\n  /**\n   * Optional override for per-minute request limits. When omitted, defaults to 10.\n   */\n  rate_limits?: ThreadsAPI.ChatSessionRateLimitsParam;\n}\n\nexport declare namespace Sessions {\n  export { type SessionCreateParams as SessionCreateParams };\n}\n"
  },
  {
    "path": "src/resources/beta/chatkit/threads.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ChatKitAPI from './chatkit';\nimport { APIPromise } from '../../../core/api-promise';\nimport {\n  ConversationCursorPage,\n  type ConversationCursorPageParams,\n  PagePromise,\n} from '../../../core/pagination';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\nexport class Threads extends APIResource {\n  /**\n   * Retrieve a ChatKit thread by its identifier.\n   *\n   * @example\n   * ```ts\n   * const chatkitThread =\n   *   await client.beta.chatkit.threads.retrieve('cthr_123');\n   * ```\n   */\n  retrieve(threadID: string, options?: RequestOptions): APIPromise<ChatKitThread> {\n    return this._client.get(path`/chatkit/threads/${threadID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),\n    });\n  }\n\n  /**\n   * List ChatKit threads with optional pagination and user filters.\n   *\n   * @example\n   * ```ts\n   * // Automatically fetches more pages as needed.\n   * for await (const chatkitThread of client.beta.chatkit.threads.list()) {\n   *   // ...\n   * }\n   * ```\n   */\n  list(\n    query: ThreadListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<ChatKitThreadsPage, ChatKitThread> {\n    return this._client.getAPIList('/chatkit/threads', ConversationCursorPage<ChatKitThread>, {\n      query,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Delete a ChatKit thread along with its items and stored attachments.\n   *\n   * @example\n   * ```ts\n   * const thread = await client.beta.chatkit.threads.delete(\n   *   'cthr_123',\n   * );\n   * ```\n   */\n  delete(threadID: string, options?: RequestOptions): APIPromise<ThreadDeleteResponse> {\n    return this._client.delete(path`/chatkit/threads/${threadID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),\n    });\n  }\n\n  /**\n   * List items that belong to a ChatKit thread.\n   *\n   * @example\n   * ```ts\n   * // Automatically fetches more pages as needed.\n   * for await (const thread of client.beta.chatkit.threads.listItems(\n   *   'cthr_123',\n   * )) {\n   *   // ...\n   * }\n   * ```\n   */\n  listItems(\n    threadID: string,\n    query: ThreadListItemsParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<\n    ChatKitThreadItemListDataPage,\n    | ChatKitThreadUserMessageItem\n    | ChatKitThreadAssistantMessageItem\n    | ChatKitWidgetItem\n    | ChatKitThreadItemList.ChatKitClientToolCall\n    | ChatKitThreadItemList.ChatKitTask\n    | ChatKitThreadItemList.ChatKitTaskGroup\n  > {\n    return this._client.getAPIList(\n      path`/chatkit/threads/${threadID}/items`,\n      ConversationCursorPage<\n        | ChatKitThreadUserMessageItem\n        | ChatKitThreadAssistantMessageItem\n        | ChatKitWidgetItem\n        | ChatKitThreadItemList.ChatKitClientToolCall\n        | ChatKitThreadItemList.ChatKitTask\n        | ChatKitThreadItemList.ChatKitTaskGroup\n      >,\n      { query, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]) },\n    );\n  }\n}\n\nexport type ChatKitThreadsPage = ConversationCursorPage<ChatKitThread>;\n\nexport type ChatKitThreadItemListDataPage = ConversationCursorPage<\n  | ChatKitThreadUserMessageItem\n  | ChatKitThreadAssistantMessageItem\n  | ChatKitWidgetItem\n  | ChatKitThreadItemList.ChatKitClientToolCall\n  | ChatKitThreadItemList.ChatKitTask\n  | ChatKitThreadItemList.ChatKitTaskGroup\n>;\n\n/**\n * Represents a ChatKit session and its resolved configuration.\n */\nexport interface ChatSession {\n  /**\n   * Identifier for the ChatKit session.\n   */\n  id: string;\n\n  /**\n   * Resolved ChatKit feature configuration for the session.\n   */\n  chatkit_configuration: ChatSessionChatKitConfiguration;\n\n  /**\n   * Ephemeral client secret that authenticates session requests.\n   */\n  client_secret: string;\n\n  /**\n   * Unix timestamp (in seconds) for when the session expires.\n   */\n  expires_at: number;\n\n  /**\n   * Convenience copy of the per-minute request limit.\n   */\n  max_requests_per_1_minute: number;\n\n  /**\n   * Type discriminator that is always `chatkit.session`.\n   */\n  object: 'chatkit.session';\n\n  /**\n   * Resolved rate limit values.\n   */\n  rate_limits: ChatSessionRateLimits;\n\n  /**\n   * Current lifecycle state of the session.\n   */\n  status: ChatSessionStatus;\n\n  /**\n   * User identifier associated with the session.\n   */\n  user: string;\n\n  /**\n   * Workflow metadata for the session.\n   */\n  workflow: ChatKitAPI.ChatKitWorkflow;\n}\n\n/**\n * Automatic thread title preferences for the session.\n */\nexport interface ChatSessionAutomaticThreadTitling {\n  /**\n   * Whether automatic thread titling is enabled.\n   */\n  enabled: boolean;\n}\n\n/**\n * ChatKit configuration for the session.\n */\nexport interface ChatSessionChatKitConfiguration {\n  /**\n   * Automatic thread titling preferences.\n   */\n  automatic_thread_titling: ChatSessionAutomaticThreadTitling;\n\n  /**\n   * Upload settings for the session.\n   */\n  file_upload: ChatSessionFileUpload;\n\n  /**\n   * History retention configuration.\n   */\n  history: ChatSessionHistory;\n}\n\n/**\n * Optional per-session configuration settings for ChatKit behavior.\n */\nexport interface ChatSessionChatKitConfigurationParam {\n  /**\n   * Configuration for automatic thread titling. When omitted, automatic thread\n   * titling is enabled by default.\n   */\n  automatic_thread_titling?: ChatSessionChatKitConfigurationParam.AutomaticThreadTitling;\n\n  /**\n   * Configuration for upload enablement and limits. When omitted, uploads are\n   * disabled by default (max_files 10, max_file_size 512 MB).\n   */\n  file_upload?: ChatSessionChatKitConfigurationParam.FileUpload;\n\n  /**\n   * Configuration for chat history retention. When omitted, history is enabled by\n   * default with no limit on recent_threads (null).\n   */\n  history?: ChatSessionChatKitConfigurationParam.History;\n}\n\nexport namespace ChatSessionChatKitConfigurationParam {\n  /**\n   * Configuration for automatic thread titling. When omitted, automatic thread\n   * titling is enabled by default.\n   */\n  export interface AutomaticThreadTitling {\n    /**\n     * Enable automatic thread title generation. Defaults to true.\n     */\n    enabled?: boolean;\n  }\n\n  /**\n   * Configuration for upload enablement and limits. When omitted, uploads are\n   * disabled by default (max_files 10, max_file_size 512 MB).\n   */\n  export interface FileUpload {\n    /**\n     * Enable uploads for this session. Defaults to false.\n     */\n    enabled?: boolean;\n\n    /**\n     * Maximum size in megabytes for each uploaded file. Defaults to 512 MB, which is\n     * the maximum allowable size.\n     */\n    max_file_size?: number;\n\n    /**\n     * Maximum number of files that can be uploaded to the session. Defaults to 10.\n     */\n    max_files?: number;\n  }\n\n  /**\n   * Configuration for chat history retention. When omitted, history is enabled by\n   * default with no limit on recent_threads (null).\n   */\n  export interface History {\n    /**\n     * Enables chat users to access previous ChatKit threads. Defaults to true.\n     */\n    enabled?: boolean;\n\n    /**\n     * Number of recent ChatKit threads users have access to. Defaults to unlimited\n     * when unset.\n     */\n    recent_threads?: number;\n  }\n}\n\n/**\n * Controls when the session expires relative to an anchor timestamp.\n */\nexport interface ChatSessionExpiresAfterParam {\n  /**\n   * Base timestamp used to calculate expiration. Currently fixed to `created_at`.\n   */\n  anchor: 'created_at';\n\n  /**\n   * Number of seconds after the anchor when the session expires.\n   */\n  seconds: number;\n}\n\n/**\n * Upload permissions and limits applied to the session.\n */\nexport interface ChatSessionFileUpload {\n  /**\n   * Indicates if uploads are enabled for the session.\n   */\n  enabled: boolean;\n\n  /**\n   * Maximum upload size in megabytes.\n   */\n  max_file_size: number | null;\n\n  /**\n   * Maximum number of uploads allowed during the session.\n   */\n  max_files: number | null;\n}\n\n/**\n * History retention preferences returned for the session.\n */\nexport interface ChatSessionHistory {\n  /**\n   * Indicates if chat history is persisted for the session.\n   */\n  enabled: boolean;\n\n  /**\n   * Number of prior threads surfaced in history views. Defaults to null when all\n   * history is retained.\n   */\n  recent_threads: number | null;\n}\n\n/**\n * Active per-minute request limit for the session.\n */\nexport interface ChatSessionRateLimits {\n  /**\n   * Maximum allowed requests per one-minute window.\n   */\n  max_requests_per_1_minute: number;\n}\n\n/**\n * Controls request rate limits for the session.\n */\nexport interface ChatSessionRateLimitsParam {\n  /**\n   * Maximum number of requests allowed per minute for the session. Defaults to 10.\n   */\n  max_requests_per_1_minute?: number;\n}\n\nexport type ChatSessionStatus = 'active' | 'expired' | 'cancelled';\n\n/**\n * Workflow reference and overrides applied to the chat session.\n */\nexport interface ChatSessionWorkflowParam {\n  /**\n   * Identifier for the workflow invoked by the session.\n   */\n  id: string;\n\n  /**\n   * State variables forwarded to the workflow. Keys may be up to 64 characters,\n   * values must be primitive types, and the map defaults to an empty object.\n   */\n  state_variables?: { [key: string]: string | boolean | number };\n\n  /**\n   * Optional tracing overrides for the workflow invocation. When omitted, tracing is\n   * enabled by default.\n   */\n  tracing?: ChatSessionWorkflowParam.Tracing;\n\n  /**\n   * Specific workflow version to run. Defaults to the latest deployed version.\n   */\n  version?: string;\n}\n\nexport namespace ChatSessionWorkflowParam {\n  /**\n   * Optional tracing overrides for the workflow invocation. When omitted, tracing is\n   * enabled by default.\n   */\n  export interface Tracing {\n    /**\n     * Whether tracing is enabled during the session. Defaults to true.\n     */\n    enabled?: boolean;\n  }\n}\n\n/**\n * Attachment metadata included on thread items.\n */\nexport interface ChatKitAttachment {\n  /**\n   * Identifier for the attachment.\n   */\n  id: string;\n\n  /**\n   * MIME type of the attachment.\n   */\n  mime_type: string;\n\n  /**\n   * Original display name for the attachment.\n   */\n  name: string;\n\n  /**\n   * Preview URL for rendering the attachment inline.\n   */\n  preview_url: string | null;\n\n  /**\n   * Attachment discriminator.\n   */\n  type: 'image' | 'file';\n}\n\n/**\n * Assistant response text accompanied by optional annotations.\n */\nexport interface ChatKitResponseOutputText {\n  /**\n   * Ordered list of annotations attached to the response text.\n   */\n  annotations: Array<ChatKitResponseOutputText.File | ChatKitResponseOutputText.URL>;\n\n  /**\n   * Assistant generated text.\n   */\n  text: string;\n\n  /**\n   * Type discriminator that is always `output_text`.\n   */\n  type: 'output_text';\n}\n\nexport namespace ChatKitResponseOutputText {\n  /**\n   * Annotation that references an uploaded file.\n   */\n  export interface File {\n    /**\n     * File attachment referenced by the annotation.\n     */\n    source: File.Source;\n\n    /**\n     * Type discriminator that is always `file` for this annotation.\n     */\n    type: 'file';\n  }\n\n  export namespace File {\n    /**\n     * File attachment referenced by the annotation.\n     */\n    export interface Source {\n      /**\n       * Filename referenced by the annotation.\n       */\n      filename: string;\n\n      /**\n       * Type discriminator that is always `file`.\n       */\n      type: 'file';\n    }\n  }\n\n  /**\n   * Annotation that references a URL.\n   */\n  export interface URL {\n    /**\n     * URL referenced by the annotation.\n     */\n    source: URL.Source;\n\n    /**\n     * Type discriminator that is always `url` for this annotation.\n     */\n    type: 'url';\n  }\n\n  export namespace URL {\n    /**\n     * URL referenced by the annotation.\n     */\n    export interface Source {\n      /**\n       * Type discriminator that is always `url`.\n       */\n      type: 'url';\n\n      /**\n       * URL referenced by the annotation.\n       */\n      url: string;\n    }\n  }\n}\n\n/**\n * Represents a ChatKit thread and its current status.\n */\nexport interface ChatKitThread {\n  /**\n   * Identifier of the thread.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) for when the thread was created.\n   */\n  created_at: number;\n\n  /**\n   * Type discriminator that is always `chatkit.thread`.\n   */\n  object: 'chatkit.thread';\n\n  /**\n   * Current status for the thread. Defaults to `active` for newly created threads.\n   */\n  status: ChatKitThread.Active | ChatKitThread.Locked | ChatKitThread.Closed;\n\n  /**\n   * Optional human-readable title for the thread. Defaults to null when no title has\n   * been generated.\n   */\n  title: string | null;\n\n  /**\n   * Free-form string that identifies your end user who owns the thread.\n   */\n  user: string;\n}\n\nexport namespace ChatKitThread {\n  /**\n   * Indicates that a thread is active.\n   */\n  export interface Active {\n    /**\n     * Status discriminator that is always `active`.\n     */\n    type: 'active';\n  }\n\n  /**\n   * Indicates that a thread is locked and cannot accept new input.\n   */\n  export interface Locked {\n    /**\n     * Reason that the thread was locked. Defaults to null when no reason is recorded.\n     */\n    reason: string | null;\n\n    /**\n     * Status discriminator that is always `locked`.\n     */\n    type: 'locked';\n  }\n\n  /**\n   * Indicates that a thread has been closed.\n   */\n  export interface Closed {\n    /**\n     * Reason that the thread was closed. Defaults to null when no reason is recorded.\n     */\n    reason: string | null;\n\n    /**\n     * Status discriminator that is always `closed`.\n     */\n    type: 'closed';\n  }\n}\n\n/**\n * Assistant-authored message within a thread.\n */\nexport interface ChatKitThreadAssistantMessageItem {\n  /**\n   * Identifier of the thread item.\n   */\n  id: string;\n\n  /**\n   * Ordered assistant response segments.\n   */\n  content: Array<ChatKitResponseOutputText>;\n\n  /**\n   * Unix timestamp (in seconds) for when the item was created.\n   */\n  created_at: number;\n\n  /**\n   * Type discriminator that is always `chatkit.thread_item`.\n   */\n  object: 'chatkit.thread_item';\n\n  /**\n   * Identifier of the parent thread.\n   */\n  thread_id: string;\n\n  /**\n   * Type discriminator that is always `chatkit.assistant_message`.\n   */\n  type: 'chatkit.assistant_message';\n}\n\n/**\n * A paginated list of thread items rendered for the ChatKit API.\n */\nexport interface ChatKitThreadItemList {\n  /**\n   * A list of items\n   */\n  data: Array<\n    | ChatKitThreadUserMessageItem\n    | ChatKitThreadAssistantMessageItem\n    | ChatKitWidgetItem\n    | ChatKitThreadItemList.ChatKitClientToolCall\n    | ChatKitThreadItemList.ChatKitTask\n    | ChatKitThreadItemList.ChatKitTaskGroup\n  >;\n\n  /**\n   * The ID of the first item in the list.\n   */\n  first_id: string | null;\n\n  /**\n   * Whether there are more items available.\n   */\n  has_more: boolean;\n\n  /**\n   * The ID of the last item in the list.\n   */\n  last_id: string | null;\n\n  /**\n   * The type of object returned, must be `list`.\n   */\n  object: 'list';\n}\n\nexport namespace ChatKitThreadItemList {\n  /**\n   * Record of a client side tool invocation initiated by the assistant.\n   */\n  export interface ChatKitClientToolCall {\n    /**\n     * Identifier of the thread item.\n     */\n    id: string;\n\n    /**\n     * JSON-encoded arguments that were sent to the tool.\n     */\n    arguments: string;\n\n    /**\n     * Identifier for the client tool call.\n     */\n    call_id: string;\n\n    /**\n     * Unix timestamp (in seconds) for when the item was created.\n     */\n    created_at: number;\n\n    /**\n     * Tool name that was invoked.\n     */\n    name: string;\n\n    /**\n     * Type discriminator that is always `chatkit.thread_item`.\n     */\n    object: 'chatkit.thread_item';\n\n    /**\n     * JSON-encoded output captured from the tool. Defaults to null while execution is\n     * in progress.\n     */\n    output: string | null;\n\n    /**\n     * Execution status for the tool call.\n     */\n    status: 'in_progress' | 'completed';\n\n    /**\n     * Identifier of the parent thread.\n     */\n    thread_id: string;\n\n    /**\n     * Type discriminator that is always `chatkit.client_tool_call`.\n     */\n    type: 'chatkit.client_tool_call';\n  }\n\n  /**\n   * Task emitted by the workflow to show progress and status updates.\n   */\n  export interface ChatKitTask {\n    /**\n     * Identifier of the thread item.\n     */\n    id: string;\n\n    /**\n     * Unix timestamp (in seconds) for when the item was created.\n     */\n    created_at: number;\n\n    /**\n     * Optional heading for the task. Defaults to null when not provided.\n     */\n    heading: string | null;\n\n    /**\n     * Type discriminator that is always `chatkit.thread_item`.\n     */\n    object: 'chatkit.thread_item';\n\n    /**\n     * Optional summary that describes the task. Defaults to null when omitted.\n     */\n    summary: string | null;\n\n    /**\n     * Subtype for the task.\n     */\n    task_type: 'custom' | 'thought';\n\n    /**\n     * Identifier of the parent thread.\n     */\n    thread_id: string;\n\n    /**\n     * Type discriminator that is always `chatkit.task`.\n     */\n    type: 'chatkit.task';\n  }\n\n  /**\n   * Collection of workflow tasks grouped together in the thread.\n   */\n  export interface ChatKitTaskGroup {\n    /**\n     * Identifier of the thread item.\n     */\n    id: string;\n\n    /**\n     * Unix timestamp (in seconds) for when the item was created.\n     */\n    created_at: number;\n\n    /**\n     * Type discriminator that is always `chatkit.thread_item`.\n     */\n    object: 'chatkit.thread_item';\n\n    /**\n     * Tasks included in the group.\n     */\n    tasks: Array<ChatKitTaskGroup.Task>;\n\n    /**\n     * Identifier of the parent thread.\n     */\n    thread_id: string;\n\n    /**\n     * Type discriminator that is always `chatkit.task_group`.\n     */\n    type: 'chatkit.task_group';\n  }\n\n  export namespace ChatKitTaskGroup {\n    /**\n     * Task entry that appears within a TaskGroup.\n     */\n    export interface Task {\n      /**\n       * Optional heading for the grouped task. Defaults to null when not provided.\n       */\n      heading: string | null;\n\n      /**\n       * Optional summary that describes the grouped task. Defaults to null when omitted.\n       */\n      summary: string | null;\n\n      /**\n       * Subtype for the grouped task.\n       */\n      type: 'custom' | 'thought';\n    }\n  }\n}\n\n/**\n * User-authored messages within a thread.\n */\nexport interface ChatKitThreadUserMessageItem {\n  /**\n   * Identifier of the thread item.\n   */\n  id: string;\n\n  /**\n   * Attachments associated with the user message. Defaults to an empty list.\n   */\n  attachments: Array<ChatKitAttachment>;\n\n  /**\n   * Ordered content elements supplied by the user.\n   */\n  content: Array<ChatKitThreadUserMessageItem.InputText | ChatKitThreadUserMessageItem.QuotedText>;\n\n  /**\n   * Unix timestamp (in seconds) for when the item was created.\n   */\n  created_at: number;\n\n  /**\n   * Inference overrides applied to the message. Defaults to null when unset.\n   */\n  inference_options: ChatKitThreadUserMessageItem.InferenceOptions | null;\n\n  /**\n   * Type discriminator that is always `chatkit.thread_item`.\n   */\n  object: 'chatkit.thread_item';\n\n  /**\n   * Identifier of the parent thread.\n   */\n  thread_id: string;\n\n  type: 'chatkit.user_message';\n}\n\nexport namespace ChatKitThreadUserMessageItem {\n  /**\n   * Text block that a user contributed to the thread.\n   */\n  export interface InputText {\n    /**\n     * Plain-text content supplied by the user.\n     */\n    text: string;\n\n    /**\n     * Type discriminator that is always `input_text`.\n     */\n    type: 'input_text';\n  }\n\n  /**\n   * Quoted snippet that the user referenced in their message.\n   */\n  export interface QuotedText {\n    /**\n     * Quoted text content.\n     */\n    text: string;\n\n    /**\n     * Type discriminator that is always `quoted_text`.\n     */\n    type: 'quoted_text';\n  }\n\n  /**\n   * Inference overrides applied to the message. Defaults to null when unset.\n   */\n  export interface InferenceOptions {\n    /**\n     * Model name that generated the response. Defaults to null when using the session\n     * default.\n     */\n    model: string | null;\n\n    /**\n     * Preferred tool to invoke. Defaults to null when ChatKit should auto-select.\n     */\n    tool_choice: InferenceOptions.ToolChoice | null;\n  }\n\n  export namespace InferenceOptions {\n    /**\n     * Preferred tool to invoke. Defaults to null when ChatKit should auto-select.\n     */\n    export interface ToolChoice {\n      /**\n       * Identifier of the requested tool.\n       */\n      id: string;\n    }\n  }\n}\n\n/**\n * Thread item that renders a widget payload.\n */\nexport interface ChatKitWidgetItem {\n  /**\n   * Identifier of the thread item.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) for when the item was created.\n   */\n  created_at: number;\n\n  /**\n   * Type discriminator that is always `chatkit.thread_item`.\n   */\n  object: 'chatkit.thread_item';\n\n  /**\n   * Identifier of the parent thread.\n   */\n  thread_id: string;\n\n  /**\n   * Type discriminator that is always `chatkit.widget`.\n   */\n  type: 'chatkit.widget';\n\n  /**\n   * Serialized widget payload rendered in the UI.\n   */\n  widget: string;\n}\n\n/**\n * Confirmation payload returned after deleting a thread.\n */\nexport interface ThreadDeleteResponse {\n  /**\n   * Identifier of the deleted thread.\n   */\n  id: string;\n\n  /**\n   * Indicates that the thread has been deleted.\n   */\n  deleted: boolean;\n\n  /**\n   * Type discriminator that is always `chatkit.thread.deleted`.\n   */\n  object: 'chatkit.thread.deleted';\n}\n\nexport interface ThreadListParams extends ConversationCursorPageParams {\n  /**\n   * List items created before this thread item ID. Defaults to null for the newest\n   * results.\n   */\n  before?: string;\n\n  /**\n   * Sort order for results by creation time. Defaults to `desc`.\n   */\n  order?: 'asc' | 'desc';\n\n  /**\n   * Filter threads that belong to this user identifier. Defaults to null to return\n   * all users.\n   */\n  user?: string;\n}\n\nexport interface ThreadListItemsParams extends ConversationCursorPageParams {\n  /**\n   * List items created before this thread item ID. Defaults to null for the newest\n   * results.\n   */\n  before?: string;\n\n  /**\n   * Sort order for results by creation time. Defaults to `desc`.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport declare namespace Threads {\n  export {\n    type ChatSession as ChatSession,\n    type ChatSessionAutomaticThreadTitling as ChatSessionAutomaticThreadTitling,\n    type ChatSessionChatKitConfiguration as ChatSessionChatKitConfiguration,\n    type ChatSessionChatKitConfigurationParam as ChatSessionChatKitConfigurationParam,\n    type ChatSessionExpiresAfterParam as ChatSessionExpiresAfterParam,\n    type ChatSessionFileUpload as ChatSessionFileUpload,\n    type ChatSessionHistory as ChatSessionHistory,\n    type ChatSessionRateLimits as ChatSessionRateLimits,\n    type ChatSessionRateLimitsParam as ChatSessionRateLimitsParam,\n    type ChatSessionStatus as ChatSessionStatus,\n    type ChatSessionWorkflowParam as ChatSessionWorkflowParam,\n    type ChatKitAttachment as ChatKitAttachment,\n    type ChatKitResponseOutputText as ChatKitResponseOutputText,\n    type ChatKitThread as ChatKitThread,\n    type ChatKitThreadAssistantMessageItem as ChatKitThreadAssistantMessageItem,\n    type ChatKitThreadItemList as ChatKitThreadItemList,\n    type ChatKitThreadUserMessageItem as ChatKitThreadUserMessageItem,\n    type ChatKitWidgetItem as ChatKitWidgetItem,\n    type ThreadDeleteResponse as ThreadDeleteResponse,\n    type ChatKitThreadsPage as ChatKitThreadsPage,\n    type ChatKitThreadItemListDataPage as ChatKitThreadItemListDataPage,\n    type ThreadListParams as ThreadListParams,\n    type ThreadListItemsParams as ThreadListItemsParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/beta/chatkit.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './chatkit/index';\n"
  },
  {
    "path": "src/resources/beta/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport {\n  Assistants,\n  type Assistant,\n  type AssistantDeleted,\n  type AssistantStreamEvent,\n  type AssistantTool,\n  type CodeInterpreterTool,\n  type FileSearchTool,\n  type FunctionTool,\n  type MessageStreamEvent,\n  type RunStepStreamEvent,\n  type RunStreamEvent,\n  type ThreadStreamEvent,\n  type AssistantCreateParams,\n  type AssistantUpdateParams,\n  type AssistantListParams,\n  type AssistantsPage,\n} from './assistants';\nexport { Beta } from './beta';\nexport { Realtime } from './realtime/index';\nexport { ChatKit, type ChatKitWorkflow } from './chatkit/index';\nexport {\n  Threads,\n  type AssistantResponseFormatOption,\n  type AssistantToolChoice,\n  type AssistantToolChoiceFunction,\n  type AssistantToolChoiceOption,\n  type Thread,\n  type ThreadDeleted,\n  type ThreadCreateParams,\n  type ThreadUpdateParams,\n  type ThreadCreateAndRunParams,\n  type ThreadCreateAndRunParamsNonStreaming,\n  type ThreadCreateAndRunParamsStreaming,\n  type ThreadCreateAndRunPollParams,\n  type ThreadCreateAndRunStreamParams,\n} from './threads/index';\n"
  },
  {
    "path": "src/resources/beta/realtime/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Realtime } from './realtime';\nexport { Sessions, type Session, type SessionCreateResponse, type SessionCreateParams } from './sessions';\nexport {\n  TranscriptionSessions,\n  type TranscriptionSession,\n  type TranscriptionSessionCreateParams,\n} from './transcription-sessions';\n"
  },
  {
    "path": "src/resources/beta/realtime/realtime.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as RealtimeAPI from './realtime';\nimport * as Shared from '../../shared';\nimport * as SessionsAPI from './sessions';\nimport {\n  Session as SessionsAPISession,\n  SessionCreateParams,\n  SessionCreateResponse,\n  Sessions,\n} from './sessions';\nimport * as TranscriptionSessionsAPI from './transcription-sessions';\nimport {\n  TranscriptionSession,\n  TranscriptionSessionCreateParams,\n  TranscriptionSessions,\n} from './transcription-sessions';\n\n/**\n * @deprecated Realtime has now launched and is generally available. The old beta API is now deprecated.\n */\nexport class Realtime extends APIResource {\n  sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client);\n  transcriptionSessions: TranscriptionSessionsAPI.TranscriptionSessions =\n    new TranscriptionSessionsAPI.TranscriptionSessions(this._client);\n}\n\n/**\n * Returned when a conversation is created. Emitted right after session creation.\n */\nexport interface ConversationCreatedEvent {\n  /**\n   * The conversation resource.\n   */\n  conversation: ConversationCreatedEvent.Conversation;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The event type, must be `conversation.created`.\n   */\n  type: 'conversation.created';\n}\n\nexport namespace ConversationCreatedEvent {\n  /**\n   * The conversation resource.\n   */\n  export interface Conversation {\n    /**\n     * The unique ID of the conversation.\n     */\n    id?: string;\n\n    /**\n     * The object type, must be `realtime.conversation`.\n     */\n    object?: 'realtime.conversation';\n  }\n}\n\n/**\n * The item to add to the conversation.\n */\nexport interface ConversationItem {\n  /**\n   * The unique ID of the item, this can be generated by the client to help manage\n   * server-side context, but is not required because the server will generate one if\n   * not provided.\n   */\n  id?: string;\n\n  /**\n   * The arguments of the function call (for `function_call` items).\n   */\n  arguments?: string;\n\n  /**\n   * The ID of the function call (for `function_call` and `function_call_output`\n   * items). If passed on a `function_call_output` item, the server will check that a\n   * `function_call` item with the same ID exists in the conversation history.\n   */\n  call_id?: string;\n\n  /**\n   * The content of the message, applicable for `message` items.\n   *\n   * - Message items of role `system` support only `input_text` content\n   * - Message items of role `user` support `input_text` and `input_audio` content\n   * - Message items of role `assistant` support `text` content.\n   */\n  content?: Array<ConversationItemContent>;\n\n  /**\n   * The name of the function being called (for `function_call` items).\n   */\n  name?: string;\n\n  /**\n   * Identifier for the API object being returned - always `realtime.item`.\n   */\n  object?: 'realtime.item';\n\n  /**\n   * The output of the function call (for `function_call_output` items).\n   */\n  output?: string;\n\n  /**\n   * The role of the message sender (`user`, `assistant`, `system`), only applicable\n   * for `message` items.\n   */\n  role?: 'user' | 'assistant' | 'system';\n\n  /**\n   * The status of the item (`completed`, `incomplete`, `in_progress`). These have no\n   * effect on the conversation, but are accepted for consistency with the\n   * `conversation.item.created` event.\n   */\n  status?: 'completed' | 'incomplete' | 'in_progress';\n\n  /**\n   * The type of the item (`message`, `function_call`, `function_call_output`).\n   */\n  type?: 'message' | 'function_call' | 'function_call_output';\n}\n\nexport interface ConversationItemContent {\n  /**\n   * ID of a previous conversation item to reference (for `item_reference` content\n   * types in `response.create` events). These can reference both client and server\n   * created items.\n   */\n  id?: string;\n\n  /**\n   * Base64-encoded audio bytes, used for `input_audio` content type.\n   */\n  audio?: string;\n\n  /**\n   * The text content, used for `input_text` and `text` content types.\n   */\n  text?: string;\n\n  /**\n   * The transcript of the audio, used for `input_audio` and `audio` content types.\n   */\n  transcript?: string;\n\n  /**\n   * The content type (`input_text`, `input_audio`, `item_reference`, `text`,\n   * `audio`).\n   */\n  type?: 'input_text' | 'input_audio' | 'item_reference' | 'text' | 'audio';\n}\n\n/**\n * Add a new Item to the Conversation's context, including messages, function\n * calls, and function call responses. This event can be used both to populate a\n * \"history\" of the conversation and to add new items mid-stream, but has the\n * current limitation that it cannot populate assistant audio messages.\n *\n * If successful, the server will respond with a `conversation.item.created` event,\n * otherwise an `error` event will be sent.\n */\nexport interface ConversationItemCreateEvent {\n  /**\n   * The item to add to the conversation.\n   */\n  item: ConversationItem;\n\n  /**\n   * The event type, must be `conversation.item.create`.\n   */\n  type: 'conversation.item.create';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n\n  /**\n   * The ID of the preceding item after which the new item will be inserted. If not\n   * set, the new item will be appended to the end of the conversation. If set to\n   * `root`, the new item will be added to the beginning of the conversation. If set\n   * to an existing ID, it allows an item to be inserted mid-conversation. If the ID\n   * cannot be found, an error will be returned and the item will not be added.\n   */\n  previous_item_id?: string;\n}\n\n/**\n * Returned when a conversation item is created. There are several scenarios that\n * produce this event:\n *\n * - The server is generating a Response, which if successful will produce either\n *   one or two Items, which will be of type `message` (role `assistant`) or type\n *   `function_call`.\n * - The input audio buffer has been committed, either by the client or the server\n *   (in `server_vad` mode). The server will take the content of the input audio\n *   buffer and add it to a new user message Item.\n * - The client has sent a `conversation.item.create` event to add a new Item to\n *   the Conversation.\n */\nexport interface ConversationItemCreatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The item to add to the conversation.\n   */\n  item: ConversationItem;\n\n  /**\n   * The event type, must be `conversation.item.created`.\n   */\n  type: 'conversation.item.created';\n\n  /**\n   * The ID of the preceding item in the Conversation context, allows the client to\n   * understand the order of the conversation. Can be `null` if the item has no\n   * predecessor.\n   */\n  previous_item_id?: string | null;\n}\n\n/**\n * Send this event when you want to remove any item from the conversation history.\n * The server will respond with a `conversation.item.deleted` event, unless the\n * item does not exist in the conversation history, in which case the server will\n * respond with an error.\n */\nexport interface ConversationItemDeleteEvent {\n  /**\n   * The ID of the item to delete.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.delete`.\n   */\n  type: 'conversation.item.delete';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Returned when an item in the conversation is deleted by the client with a\n * `conversation.item.delete` event. This event is used to synchronize the server's\n * understanding of the conversation history with the client's view.\n */\nexport interface ConversationItemDeletedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item that was deleted.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.deleted`.\n   */\n  type: 'conversation.item.deleted';\n}\n\n/**\n * This event is the output of audio transcription for user audio written to the\n * user audio buffer. Transcription begins when the input audio buffer is committed\n * by the client or server (in `server_vad` mode). Transcription runs\n * asynchronously with Response creation, so this event may come before or after\n * the Response events.\n *\n * Realtime API models accept audio natively, and thus input transcription is a\n * separate process run on a separate ASR (Automatic Speech Recognition) model. The\n * transcript may diverge somewhat from the model's interpretation, and should be\n * treated as a rough guide.\n */\nexport interface ConversationItemInputAudioTranscriptionCompletedEvent {\n  /**\n   * The index of the content part containing the audio.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the user message item containing the audio.\n   */\n  item_id: string;\n\n  /**\n   * The transcribed text.\n   */\n  transcript: string;\n\n  /**\n   * The event type, must be `conversation.item.input_audio_transcription.completed`.\n   */\n  type: 'conversation.item.input_audio_transcription.completed';\n\n  /**\n   * Usage statistics for the transcription.\n   */\n  usage:\n    | ConversationItemInputAudioTranscriptionCompletedEvent.TranscriptTextUsageTokens\n    | ConversationItemInputAudioTranscriptionCompletedEvent.TranscriptTextUsageDuration;\n\n  /**\n   * The log probabilities of the transcription.\n   */\n  logprobs?: Array<ConversationItemInputAudioTranscriptionCompletedEvent.Logprob> | null;\n}\n\nexport namespace ConversationItemInputAudioTranscriptionCompletedEvent {\n  /**\n   * Usage statistics for models billed by token usage.\n   */\n  export interface TranscriptTextUsageTokens {\n    /**\n     * Number of input tokens billed for this request.\n     */\n    input_tokens: number;\n\n    /**\n     * Number of output tokens generated.\n     */\n    output_tokens: number;\n\n    /**\n     * Total number of tokens used (input + output).\n     */\n    total_tokens: number;\n\n    /**\n     * The type of the usage object. Always `tokens` for this variant.\n     */\n    type: 'tokens';\n\n    /**\n     * Details about the input tokens billed for this request.\n     */\n    input_token_details?: TranscriptTextUsageTokens.InputTokenDetails;\n  }\n\n  export namespace TranscriptTextUsageTokens {\n    /**\n     * Details about the input tokens billed for this request.\n     */\n    export interface InputTokenDetails {\n      /**\n       * Number of audio tokens billed for this request.\n       */\n      audio_tokens?: number;\n\n      /**\n       * Number of text tokens billed for this request.\n       */\n      text_tokens?: number;\n    }\n  }\n\n  /**\n   * Usage statistics for models billed by audio input duration.\n   */\n  export interface TranscriptTextUsageDuration {\n    /**\n     * Duration of the input audio in seconds.\n     */\n    seconds: number;\n\n    /**\n     * The type of the usage object. Always `duration` for this variant.\n     */\n    type: 'duration';\n  }\n\n  /**\n   * A log probability object.\n   */\n  export interface Logprob {\n    /**\n     * The token that was used to generate the log probability.\n     */\n    token: string;\n\n    /**\n     * The bytes that were used to generate the log probability.\n     */\n    bytes: Array<number>;\n\n    /**\n     * The log probability of the token.\n     */\n    logprob: number;\n  }\n}\n\n/**\n * Returned when the text value of an input audio transcription content part is\n * updated.\n */\nexport interface ConversationItemInputAudioTranscriptionDeltaEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.input_audio_transcription.delta`.\n   */\n  type: 'conversation.item.input_audio_transcription.delta';\n\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index?: number;\n\n  /**\n   * The text delta.\n   */\n  delta?: string;\n\n  /**\n   * The log probabilities of the transcription.\n   */\n  logprobs?: Array<ConversationItemInputAudioTranscriptionDeltaEvent.Logprob> | null;\n}\n\nexport namespace ConversationItemInputAudioTranscriptionDeltaEvent {\n  /**\n   * A log probability object.\n   */\n  export interface Logprob {\n    /**\n     * The token that was used to generate the log probability.\n     */\n    token: string;\n\n    /**\n     * The bytes that were used to generate the log probability.\n     */\n    bytes: Array<number>;\n\n    /**\n     * The log probability of the token.\n     */\n    logprob: number;\n  }\n}\n\n/**\n * Returned when input audio transcription is configured, and a transcription\n * request for a user message failed. These events are separate from other `error`\n * events so that the client can identify the related Item.\n */\nexport interface ConversationItemInputAudioTranscriptionFailedEvent {\n  /**\n   * The index of the content part containing the audio.\n   */\n  content_index: number;\n\n  /**\n   * Details of the transcription error.\n   */\n  error: ConversationItemInputAudioTranscriptionFailedEvent.Error;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the user message item.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.input_audio_transcription.failed`.\n   */\n  type: 'conversation.item.input_audio_transcription.failed';\n}\n\nexport namespace ConversationItemInputAudioTranscriptionFailedEvent {\n  /**\n   * Details of the transcription error.\n   */\n  export interface Error {\n    /**\n     * Error code, if any.\n     */\n    code?: string;\n\n    /**\n     * A human-readable error message.\n     */\n    message?: string;\n\n    /**\n     * Parameter related to the error, if any.\n     */\n    param?: string;\n\n    /**\n     * The type of error.\n     */\n    type?: string;\n  }\n}\n\n/**\n * Send this event when you want to retrieve the server's representation of a\n * specific item in the conversation history. This is useful, for example, to\n * inspect user audio after noise cancellation and VAD. The server will respond\n * with a `conversation.item.retrieved` event, unless the item does not exist in\n * the conversation history, in which case the server will respond with an error.\n */\nexport interface ConversationItemRetrieveEvent {\n  /**\n   * The ID of the item to retrieve.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.retrieve`.\n   */\n  type: 'conversation.item.retrieve';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Send this event to truncate a previous assistant message’s audio. The server\n * will produce audio faster than realtime, so this event is useful when the user\n * interrupts to truncate audio that has already been sent to the client but not\n * yet played. This will synchronize the server's understanding of the audio with\n * the client's playback.\n *\n * Truncating audio will delete the server-side text transcript to ensure there is\n * not text in the context that hasn't been heard by the user.\n *\n * If successful, the server will respond with a `conversation.item.truncated`\n * event.\n */\nexport interface ConversationItemTruncateEvent {\n  /**\n   * Inclusive duration up to which audio is truncated, in milliseconds. If the\n   * audio_end_ms is greater than the actual audio duration, the server will respond\n   * with an error.\n   */\n  audio_end_ms: number;\n\n  /**\n   * The index of the content part to truncate. Set this to 0.\n   */\n  content_index: number;\n\n  /**\n   * The ID of the assistant message item to truncate. Only assistant message items\n   * can be truncated.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.truncate`.\n   */\n  type: 'conversation.item.truncate';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Returned when an earlier assistant audio message item is truncated by the client\n * with a `conversation.item.truncate` event. This event is used to synchronize the\n * server's understanding of the audio with the client's playback.\n *\n * This action will truncate the audio and remove the server-side text transcript\n * to ensure there is no text in the context that hasn't been heard by the user.\n */\nexport interface ConversationItemTruncatedEvent {\n  /**\n   * The duration up to which the audio was truncated, in milliseconds.\n   */\n  audio_end_ms: number;\n\n  /**\n   * The index of the content part that was truncated.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the assistant message item that was truncated.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.truncated`.\n   */\n  type: 'conversation.item.truncated';\n}\n\n/**\n * The item to add to the conversation.\n */\nexport interface ConversationItemWithReference {\n  /**\n   * For an item of type (`message` | `function_call` | `function_call_output`) this\n   * field allows the client to assign the unique ID of the item. It is not required\n   * because the server will generate one if not provided.\n   *\n   * For an item of type `item_reference`, this field is required and is a reference\n   * to any item that has previously existed in the conversation.\n   */\n  id?: string;\n\n  /**\n   * The arguments of the function call (for `function_call` items).\n   */\n  arguments?: string;\n\n  /**\n   * The ID of the function call (for `function_call` and `function_call_output`\n   * items). If passed on a `function_call_output` item, the server will check that a\n   * `function_call` item with the same ID exists in the conversation history.\n   */\n  call_id?: string;\n\n  /**\n   * The content of the message, applicable for `message` items.\n   *\n   * - Message items of role `system` support only `input_text` content\n   * - Message items of role `user` support `input_text` and `input_audio` content\n   * - Message items of role `assistant` support `text` content.\n   */\n  content?: Array<ConversationItemWithReference.Content>;\n\n  /**\n   * The name of the function being called (for `function_call` items).\n   */\n  name?: string;\n\n  /**\n   * Identifier for the API object being returned - always `realtime.item`.\n   */\n  object?: 'realtime.item';\n\n  /**\n   * The output of the function call (for `function_call_output` items).\n   */\n  output?: string;\n\n  /**\n   * The role of the message sender (`user`, `assistant`, `system`), only applicable\n   * for `message` items.\n   */\n  role?: 'user' | 'assistant' | 'system';\n\n  /**\n   * The status of the item (`completed`, `incomplete`, `in_progress`). These have no\n   * effect on the conversation, but are accepted for consistency with the\n   * `conversation.item.created` event.\n   */\n  status?: 'completed' | 'incomplete' | 'in_progress';\n\n  /**\n   * The type of the item (`message`, `function_call`, `function_call_output`,\n   * `item_reference`).\n   */\n  type?: 'message' | 'function_call' | 'function_call_output' | 'item_reference';\n}\n\nexport namespace ConversationItemWithReference {\n  export interface Content {\n    /**\n     * ID of a previous conversation item to reference (for `item_reference` content\n     * types in `response.create` events). These can reference both client and server\n     * created items.\n     */\n    id?: string;\n\n    /**\n     * Base64-encoded audio bytes, used for `input_audio` content type.\n     */\n    audio?: string;\n\n    /**\n     * The text content, used for `input_text` and `text` content types.\n     */\n    text?: string;\n\n    /**\n     * The transcript of the audio, used for `input_audio` content type.\n     */\n    transcript?: string;\n\n    /**\n     * The content type (`input_text`, `input_audio`, `item_reference`, `text`).\n     */\n    type?: 'input_text' | 'input_audio' | 'item_reference' | 'text';\n  }\n}\n\n/**\n * Returned when an error occurs, which could be a client problem or a server\n * problem. Most errors are recoverable and the session will stay open, we\n * recommend to implementors to monitor and log error messages by default.\n */\nexport interface ErrorEvent {\n  /**\n   * Details of the error.\n   */\n  error: ErrorEvent.Error;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The event type, must be `error`.\n   */\n  type: 'error';\n}\n\nexport namespace ErrorEvent {\n  /**\n   * Details of the error.\n   */\n  export interface Error {\n    /**\n     * A human-readable error message.\n     */\n    message: string;\n\n    /**\n     * The type of error (e.g., \"invalid_request_error\", \"server_error\").\n     */\n    type: string;\n\n    /**\n     * Error code, if any.\n     */\n    code?: string | null;\n\n    /**\n     * The event_id of the client event that caused the error, if applicable.\n     */\n    event_id?: string | null;\n\n    /**\n     * Parameter related to the error, if any.\n     */\n    param?: string | null;\n  }\n}\n\n/**\n * Send this event to append audio bytes to the input audio buffer. The audio\n * buffer is temporary storage you can write to and later commit. In Server VAD\n * mode, the audio buffer is used to detect speech and the server will decide when\n * to commit. When Server VAD is disabled, you must commit the audio buffer\n * manually.\n *\n * The client may choose how much audio to place in each event up to a maximum of\n * 15 MiB, for example streaming smaller chunks from the client may allow the VAD\n * to be more responsive. Unlike made other client events, the server will not send\n * a confirmation response to this event.\n */\nexport interface InputAudioBufferAppendEvent {\n  /**\n   * Base64-encoded audio bytes. This must be in the format specified by the\n   * `input_audio_format` field in the session configuration.\n   */\n  audio: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.append`.\n   */\n  type: 'input_audio_buffer.append';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Send this event to clear the audio bytes in the buffer. The server will respond\n * with an `input_audio_buffer.cleared` event.\n */\nexport interface InputAudioBufferClearEvent {\n  /**\n   * The event type, must be `input_audio_buffer.clear`.\n   */\n  type: 'input_audio_buffer.clear';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Returned when the input audio buffer is cleared by the client with a\n * `input_audio_buffer.clear` event.\n */\nexport interface InputAudioBufferClearedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.cleared`.\n   */\n  type: 'input_audio_buffer.cleared';\n}\n\n/**\n * Send this event to commit the user input audio buffer, which will create a new\n * user message item in the conversation. This event will produce an error if the\n * input audio buffer is empty. When in Server VAD mode, the client does not need\n * to send this event, the server will commit the audio buffer automatically.\n *\n * Committing the input audio buffer will trigger input audio transcription (if\n * enabled in session configuration), but it will not create a response from the\n * model. The server will respond with an `input_audio_buffer.committed` event.\n */\nexport interface InputAudioBufferCommitEvent {\n  /**\n   * The event type, must be `input_audio_buffer.commit`.\n   */\n  type: 'input_audio_buffer.commit';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Returned when an input audio buffer is committed, either by the client or\n * automatically in server VAD mode. The `item_id` property is the ID of the user\n * message item that will be created, thus a `conversation.item.created` event will\n * also be sent to the client.\n */\nexport interface InputAudioBufferCommittedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the user message item that will be created.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.committed`.\n   */\n  type: 'input_audio_buffer.committed';\n\n  /**\n   * The ID of the preceding item after which the new item will be inserted. Can be\n   * `null` if the item has no predecessor.\n   */\n  previous_item_id?: string | null;\n}\n\n/**\n * Sent by the server when in `server_vad` mode to indicate that speech has been\n * detected in the audio buffer. This can happen any time audio is added to the\n * buffer (unless speech is already detected). The client may want to use this\n * event to interrupt audio playback or provide visual feedback to the user.\n *\n * The client should expect to receive a `input_audio_buffer.speech_stopped` event\n * when speech stops. The `item_id` property is the ID of the user message item\n * that will be created when speech stops and will also be included in the\n * `input_audio_buffer.speech_stopped` event (unless the client manually commits\n * the audio buffer during VAD activation).\n */\nexport interface InputAudioBufferSpeechStartedEvent {\n  /**\n   * Milliseconds from the start of all audio written to the buffer during the\n   * session when speech was first detected. This will correspond to the beginning of\n   * audio sent to the model, and thus includes the `prefix_padding_ms` configured in\n   * the Session.\n   */\n  audio_start_ms: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the user message item that will be created when speech stops.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.speech_started`.\n   */\n  type: 'input_audio_buffer.speech_started';\n}\n\n/**\n * Returned in `server_vad` mode when the server detects the end of speech in the\n * audio buffer. The server will also send an `conversation.item.created` event\n * with the user message item that is created from the audio buffer.\n */\nexport interface InputAudioBufferSpeechStoppedEvent {\n  /**\n   * Milliseconds since the session started when speech stopped. This will correspond\n   * to the end of audio sent to the model, and thus includes the\n   * `min_silence_duration_ms` configured in the Session.\n   */\n  audio_end_ms: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the user message item that will be created.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.speech_stopped`.\n   */\n  type: 'input_audio_buffer.speech_stopped';\n}\n\n/**\n * Emitted at the beginning of a Response to indicate the updated rate limits. When\n * a Response is created some tokens will be \"reserved\" for the output tokens, the\n * rate limits shown here reflect that reservation, which is then adjusted\n * accordingly once the Response is completed.\n */\nexport interface RateLimitsUpdatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * List of rate limit information.\n   */\n  rate_limits: Array<RateLimitsUpdatedEvent.RateLimit>;\n\n  /**\n   * The event type, must be `rate_limits.updated`.\n   */\n  type: 'rate_limits.updated';\n}\n\nexport namespace RateLimitsUpdatedEvent {\n  export interface RateLimit {\n    /**\n     * The maximum allowed value for the rate limit.\n     */\n    limit?: number;\n\n    /**\n     * The name of the rate limit (`requests`, `tokens`).\n     */\n    name?: 'requests' | 'tokens';\n\n    /**\n     * The remaining value before the limit is reached.\n     */\n    remaining?: number;\n\n    /**\n     * Seconds until the rate limit resets.\n     */\n    reset_seconds?: number;\n  }\n}\n\n/**\n * A realtime client event.\n */\nexport type RealtimeClientEvent =\n  | ConversationItemCreateEvent\n  | ConversationItemDeleteEvent\n  | ConversationItemRetrieveEvent\n  | ConversationItemTruncateEvent\n  | InputAudioBufferAppendEvent\n  | InputAudioBufferClearEvent\n  | RealtimeClientEvent.OutputAudioBufferClear\n  | InputAudioBufferCommitEvent\n  | ResponseCancelEvent\n  | ResponseCreateEvent\n  | SessionUpdateEvent\n  | TranscriptionSessionUpdate;\n\nexport namespace RealtimeClientEvent {\n  /**\n   * **WebRTC Only:** Emit to cut off the current audio response. This will trigger\n   * the server to stop generating audio and emit a `output_audio_buffer.cleared`\n   * event. This event should be preceded by a `response.cancel` client event to stop\n   * the generation of the current response.\n   * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n   */\n  export interface OutputAudioBufferClear {\n    /**\n     * The event type, must be `output_audio_buffer.clear`.\n     */\n    type: 'output_audio_buffer.clear';\n\n    /**\n     * The unique ID of the client event used for error handling.\n     */\n    event_id?: string;\n  }\n}\n\n/**\n * The response resource.\n */\nexport interface RealtimeResponse {\n  /**\n   * The unique ID of the response.\n   */\n  id?: string;\n\n  /**\n   * Which conversation the response is added to, determined by the `conversation`\n   * field in the `response.create` event. If `auto`, the response will be added to\n   * the default conversation and the value of `conversation_id` will be an id like\n   * `conv_1234`. If `none`, the response will not be added to any conversation and\n   * the value of `conversation_id` will be `null`. If responses are being triggered\n   * by server VAD, the response will be added to the default conversation, thus the\n   * `conversation_id` will be an id like `conv_1234`.\n   */\n  conversation_id?: string;\n\n  /**\n   * Maximum number of output tokens for a single assistant response, inclusive of\n   * tool calls, that was used in this response.\n   */\n  max_output_tokens?: number | 'inf';\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The set of modalities the model used to respond. If there are multiple\n   * modalities, the model will pick one, for example if `modalities` is\n   * `[\"text\", \"audio\"]`, the model could be responding in either text or audio.\n   */\n  modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * The object type, must be `realtime.response`.\n   */\n  object?: 'realtime.response';\n\n  /**\n   * The list of output items generated by the response.\n   */\n  output?: Array<ConversationItem>;\n\n  /**\n   * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n   */\n  output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n  /**\n   * The final status of the response (`completed`, `cancelled`, `failed`, or\n   * `incomplete`, `in_progress`).\n   */\n  status?: 'completed' | 'cancelled' | 'failed' | 'incomplete' | 'in_progress';\n\n  /**\n   * Additional details about the status.\n   */\n  status_details?: RealtimeResponseStatus;\n\n  /**\n   * Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.\n   */\n  temperature?: number;\n\n  /**\n   * Usage statistics for the Response, this will correspond to billing. A Realtime\n   * API session will maintain a conversation context and append new Items to the\n   * Conversation, thus output from previous turns (text and audio tokens) will\n   * become the input for later turns.\n   */\n  usage?: RealtimeResponseUsage;\n\n  /**\n   * The voice the model used to respond. Current voice options are `alloy`, `ash`,\n   * `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n   */\n  voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n}\n\n/**\n * Additional details about the status.\n */\nexport interface RealtimeResponseStatus {\n  /**\n   * A description of the error that caused the response to fail, populated when the\n   * `status` is `failed`.\n   */\n  error?: RealtimeResponseStatus.Error;\n\n  /**\n   * The reason the Response did not complete. For a `cancelled` Response, one of\n   * `turn_detected` (the server VAD detected a new start of speech) or\n   * `client_cancelled` (the client sent a cancel event). For an `incomplete`\n   * Response, one of `max_output_tokens` or `content_filter` (the server-side safety\n   * filter activated and cut off the response).\n   */\n  reason?: 'turn_detected' | 'client_cancelled' | 'max_output_tokens' | 'content_filter';\n\n  /**\n   * The type of error that caused the response to fail, corresponding with the\n   * `status` field (`completed`, `cancelled`, `incomplete`, `failed`).\n   */\n  type?: 'completed' | 'cancelled' | 'incomplete' | 'failed';\n}\n\nexport namespace RealtimeResponseStatus {\n  /**\n   * A description of the error that caused the response to fail, populated when the\n   * `status` is `failed`.\n   */\n  export interface Error {\n    /**\n     * Error code, if any.\n     */\n    code?: string;\n\n    /**\n     * The type of error.\n     */\n    type?: string;\n  }\n}\n\n/**\n * Usage statistics for the Response, this will correspond to billing. A Realtime\n * API session will maintain a conversation context and append new Items to the\n * Conversation, thus output from previous turns (text and audio tokens) will\n * become the input for later turns.\n */\nexport interface RealtimeResponseUsage {\n  /**\n   * Details about the input tokens used in the Response.\n   */\n  input_token_details?: RealtimeResponseUsage.InputTokenDetails;\n\n  /**\n   * The number of input tokens used in the Response, including text and audio\n   * tokens.\n   */\n  input_tokens?: number;\n\n  /**\n   * Details about the output tokens used in the Response.\n   */\n  output_token_details?: RealtimeResponseUsage.OutputTokenDetails;\n\n  /**\n   * The number of output tokens sent in the Response, including text and audio\n   * tokens.\n   */\n  output_tokens?: number;\n\n  /**\n   * The total number of tokens in the Response including input and output text and\n   * audio tokens.\n   */\n  total_tokens?: number;\n}\n\nexport namespace RealtimeResponseUsage {\n  /**\n   * Details about the input tokens used in the Response.\n   */\n  export interface InputTokenDetails {\n    /**\n     * The number of audio tokens used in the Response.\n     */\n    audio_tokens?: number;\n\n    /**\n     * The number of cached tokens used in the Response.\n     */\n    cached_tokens?: number;\n\n    /**\n     * The number of text tokens used in the Response.\n     */\n    text_tokens?: number;\n  }\n\n  /**\n   * Details about the output tokens used in the Response.\n   */\n  export interface OutputTokenDetails {\n    /**\n     * The number of audio tokens used in the Response.\n     */\n    audio_tokens?: number;\n\n    /**\n     * The number of text tokens used in the Response.\n     */\n    text_tokens?: number;\n  }\n}\n\n/**\n * A realtime server event.\n */\nexport type RealtimeServerEvent =\n  | ConversationCreatedEvent\n  | ConversationItemCreatedEvent\n  | ConversationItemDeletedEvent\n  | ConversationItemInputAudioTranscriptionCompletedEvent\n  | ConversationItemInputAudioTranscriptionDeltaEvent\n  | ConversationItemInputAudioTranscriptionFailedEvent\n  | RealtimeServerEvent.ConversationItemRetrieved\n  | ConversationItemTruncatedEvent\n  | ErrorEvent\n  | InputAudioBufferClearedEvent\n  | InputAudioBufferCommittedEvent\n  | InputAudioBufferSpeechStartedEvent\n  | InputAudioBufferSpeechStoppedEvent\n  | RateLimitsUpdatedEvent\n  | ResponseAudioDeltaEvent\n  | ResponseAudioDoneEvent\n  | ResponseAudioTranscriptDeltaEvent\n  | ResponseAudioTranscriptDoneEvent\n  | ResponseContentPartAddedEvent\n  | ResponseContentPartDoneEvent\n  | ResponseCreatedEvent\n  | ResponseDoneEvent\n  | ResponseFunctionCallArgumentsDeltaEvent\n  | ResponseFunctionCallArgumentsDoneEvent\n  | ResponseOutputItemAddedEvent\n  | ResponseOutputItemDoneEvent\n  | ResponseTextDeltaEvent\n  | ResponseTextDoneEvent\n  | SessionCreatedEvent\n  | SessionUpdatedEvent\n  | TranscriptionSessionUpdatedEvent\n  | RealtimeServerEvent.OutputAudioBufferStarted\n  | RealtimeServerEvent.OutputAudioBufferStopped\n  | RealtimeServerEvent.OutputAudioBufferCleared;\n\nexport namespace RealtimeServerEvent {\n  /**\n   * Returned when a conversation item is retrieved with\n   * `conversation.item.retrieve`.\n   */\n  export interface ConversationItemRetrieved {\n    /**\n     * The unique ID of the server event.\n     */\n    event_id: string;\n\n    /**\n     * The item to add to the conversation.\n     */\n    item: RealtimeAPI.ConversationItem;\n\n    /**\n     * The event type, must be `conversation.item.retrieved`.\n     */\n    type: 'conversation.item.retrieved';\n  }\n\n  /**\n   * **WebRTC Only:** Emitted when the server begins streaming audio to the client.\n   * This event is emitted after an audio content part has been added\n   * (`response.content_part.added`) to the response.\n   * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n   */\n  export interface OutputAudioBufferStarted {\n    /**\n     * The unique ID of the server event.\n     */\n    event_id: string;\n\n    /**\n     * The unique ID of the response that produced the audio.\n     */\n    response_id: string;\n\n    /**\n     * The event type, must be `output_audio_buffer.started`.\n     */\n    type: 'output_audio_buffer.started';\n  }\n\n  /**\n   * **WebRTC Only:** Emitted when the output audio buffer has been completely\n   * drained on the server, and no more audio is forthcoming. This event is emitted\n   * after the full response data has been sent to the client (`response.done`).\n   * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n   */\n  export interface OutputAudioBufferStopped {\n    /**\n     * The unique ID of the server event.\n     */\n    event_id: string;\n\n    /**\n     * The unique ID of the response that produced the audio.\n     */\n    response_id: string;\n\n    /**\n     * The event type, must be `output_audio_buffer.stopped`.\n     */\n    type: 'output_audio_buffer.stopped';\n  }\n\n  /**\n   * **WebRTC Only:** Emitted when the output audio buffer is cleared. This happens\n   * either in VAD mode when the user has interrupted\n   * (`input_audio_buffer.speech_started`), or when the client has emitted the\n   * `output_audio_buffer.clear` event to manually cut off the current audio\n   * response.\n   * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n   */\n  export interface OutputAudioBufferCleared {\n    /**\n     * The unique ID of the server event.\n     */\n    event_id: string;\n\n    /**\n     * The unique ID of the response that produced the audio.\n     */\n    response_id: string;\n\n    /**\n     * The event type, must be `output_audio_buffer.cleared`.\n     */\n    type: 'output_audio_buffer.cleared';\n  }\n}\n\n/**\n * Returned when the model-generated audio is updated.\n */\nexport interface ResponseAudioDeltaEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * Base64-encoded audio data delta.\n   */\n  delta: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.audio.delta`.\n   */\n  type: 'response.audio.delta';\n}\n\n/**\n * Returned when the model-generated audio is done. Also emitted when a Response is\n * interrupted, incomplete, or cancelled.\n */\nexport interface ResponseAudioDoneEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.audio.done`.\n   */\n  type: 'response.audio.done';\n}\n\n/**\n * Returned when the model-generated transcription of audio output is updated.\n */\nexport interface ResponseAudioTranscriptDeltaEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The transcript delta.\n   */\n  delta: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.audio_transcript.delta`.\n   */\n  type: 'response.audio_transcript.delta';\n}\n\n/**\n * Returned when the model-generated transcription of audio output is done\n * streaming. Also emitted when a Response is interrupted, incomplete, or\n * cancelled.\n */\nexport interface ResponseAudioTranscriptDoneEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The final transcript of the audio.\n   */\n  transcript: string;\n\n  /**\n   * The event type, must be `response.audio_transcript.done`.\n   */\n  type: 'response.audio_transcript.done';\n}\n\n/**\n * Send this event to cancel an in-progress response. The server will respond with\n * a `response.done` event with a status of `response.status=cancelled`. If there\n * is no response to cancel, the server will respond with an error.\n */\nexport interface ResponseCancelEvent {\n  /**\n   * The event type, must be `response.cancel`.\n   */\n  type: 'response.cancel';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n\n  /**\n   * A specific response ID to cancel - if not provided, will cancel an in-progress\n   * response in the default conversation.\n   */\n  response_id?: string;\n}\n\n/**\n * Returned when a new content part is added to an assistant message item during\n * response generation.\n */\nexport interface ResponseContentPartAddedEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item to which the content part was added.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The content part that was added.\n   */\n  part: ResponseContentPartAddedEvent.Part;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.content_part.added`.\n   */\n  type: 'response.content_part.added';\n}\n\nexport namespace ResponseContentPartAddedEvent {\n  /**\n   * The content part that was added.\n   */\n  export interface Part {\n    /**\n     * Base64-encoded audio data (if type is \"audio\").\n     */\n    audio?: string;\n\n    /**\n     * The text content (if type is \"text\").\n     */\n    text?: string;\n\n    /**\n     * The transcript of the audio (if type is \"audio\").\n     */\n    transcript?: string;\n\n    /**\n     * The content type (\"text\", \"audio\").\n     */\n    type?: 'text' | 'audio';\n  }\n}\n\n/**\n * Returned when a content part is done streaming in an assistant message item.\n * Also emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseContentPartDoneEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The content part that is done.\n   */\n  part: ResponseContentPartDoneEvent.Part;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.content_part.done`.\n   */\n  type: 'response.content_part.done';\n}\n\nexport namespace ResponseContentPartDoneEvent {\n  /**\n   * The content part that is done.\n   */\n  export interface Part {\n    /**\n     * Base64-encoded audio data (if type is \"audio\").\n     */\n    audio?: string;\n\n    /**\n     * The text content (if type is \"text\").\n     */\n    text?: string;\n\n    /**\n     * The transcript of the audio (if type is \"audio\").\n     */\n    transcript?: string;\n\n    /**\n     * The content type (\"text\", \"audio\").\n     */\n    type?: 'text' | 'audio';\n  }\n}\n\n/**\n * This event instructs the server to create a Response, which means triggering\n * model inference. When in Server VAD mode, the server will create Responses\n * automatically.\n *\n * A Response will include at least one Item, and may have two, in which case the\n * second will be a function call. These Items will be appended to the conversation\n * history.\n *\n * The server will respond with a `response.created` event, events for Items and\n * content created, and finally a `response.done` event to indicate the Response is\n * complete.\n *\n * The `response.create` event includes inference configuration like\n * `instructions`, and `temperature`. These fields will override the Session's\n * configuration for this Response only.\n */\nexport interface ResponseCreateEvent {\n  /**\n   * The event type, must be `response.create`.\n   */\n  type: 'response.create';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n\n  /**\n   * Create a new Realtime response with these parameters\n   */\n  response?: ResponseCreateEvent.Response;\n}\n\nexport namespace ResponseCreateEvent {\n  /**\n   * Create a new Realtime response with these parameters\n   */\n  export interface Response {\n    /**\n     * Controls which conversation the response is added to. Currently supports `auto`\n     * and `none`, with `auto` as the default value. The `auto` value means that the\n     * contents of the response will be added to the default conversation. Set this to\n     * `none` to create an out-of-band response which will not add items to default\n     * conversation.\n     */\n    conversation?: (string & {}) | 'auto' | 'none';\n\n    /**\n     * Input items to include in the prompt for the model. Using this field creates a\n     * new context for this Response instead of using the default conversation. An\n     * empty array `[]` will clear the context for this Response. Note that this can\n     * include references to items from the default conversation.\n     */\n    input?: Array<RealtimeAPI.ConversationItemWithReference>;\n\n    /**\n     * The default system instructions (i.e. system message) prepended to model calls.\n     * This field allows the client to guide the model on desired responses. The model\n     * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n     * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n     * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n     * instructions are not guaranteed to be followed by the model, but they provide\n     * guidance to the model on the desired behavior.\n     *\n     * Note that the server sets default instructions which will be used if this field\n     * is not set and are visible in the `session.created` event at the start of the\n     * session.\n     */\n    instructions?: string;\n\n    /**\n     * Maximum number of output tokens for a single assistant response, inclusive of\n     * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n     * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n     */\n    max_response_output_tokens?: number | 'inf';\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard.\n     *\n     * Keys are strings with a maximum length of 64 characters. Values are strings with\n     * a maximum length of 512 characters.\n     */\n    metadata?: Shared.Metadata | null;\n\n    /**\n     * The set of modalities the model can respond with. To disable audio, set this to\n     * [\"text\"].\n     */\n    modalities?: Array<'text' | 'audio'>;\n\n    /**\n     * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n     */\n    output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n    /**\n     * Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.\n     */\n    temperature?: number;\n\n    /**\n     * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n     * a function, like `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}`.\n     */\n    tool_choice?: string;\n\n    /**\n     * Tools (functions) available to the model.\n     */\n    tools?: Array<Response.Tool>;\n\n    /**\n     * The voice the model uses to respond. Voice cannot be changed during the session\n     * once the model has responded with audio at least once. Current voice options are\n     * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n     */\n    voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n  }\n\n  export namespace Response {\n    export interface Tool {\n      /**\n       * The description of the function, including guidance on when and how to call it,\n       * and guidance about what to tell the user when calling (if anything).\n       */\n      description?: string;\n\n      /**\n       * The name of the function.\n       */\n      name?: string;\n\n      /**\n       * Parameters of the function in JSON Schema.\n       */\n      parameters?: unknown;\n\n      /**\n       * The type of the tool, i.e. `function`.\n       */\n      type?: 'function';\n    }\n  }\n}\n\n/**\n * Returned when a new Response is created. The first event of response creation,\n * where the response is in an initial state of `in_progress`.\n */\nexport interface ResponseCreatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The response resource.\n   */\n  response: RealtimeResponse;\n\n  /**\n   * The event type, must be `response.created`.\n   */\n  type: 'response.created';\n}\n\n/**\n * Returned when a Response is done streaming. Always emitted, no matter the final\n * state. The Response object included in the `response.done` event will include\n * all output Items in the Response but will omit the raw audio data.\n */\nexport interface ResponseDoneEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The response resource.\n   */\n  response: RealtimeResponse;\n\n  /**\n   * The event type, must be `response.done`.\n   */\n  type: 'response.done';\n}\n\n/**\n * Returned when the model-generated function call arguments are updated.\n */\nexport interface ResponseFunctionCallArgumentsDeltaEvent {\n  /**\n   * The ID of the function call.\n   */\n  call_id: string;\n\n  /**\n   * The arguments delta as a JSON string.\n   */\n  delta: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the function call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.function_call_arguments.delta`.\n   */\n  type: 'response.function_call_arguments.delta';\n}\n\n/**\n * Returned when the model-generated function call arguments are done streaming.\n * Also emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseFunctionCallArgumentsDoneEvent {\n  /**\n   * The final arguments as a JSON string.\n   */\n  arguments: string;\n\n  /**\n   * The ID of the function call.\n   */\n  call_id: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the function call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.function_call_arguments.done`.\n   */\n  type: 'response.function_call_arguments.done';\n}\n\n/**\n * Returned when a new Item is created during Response generation.\n */\nexport interface ResponseOutputItemAddedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The item to add to the conversation.\n   */\n  item: ConversationItem;\n\n  /**\n   * The index of the output item in the Response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the Response to which the item belongs.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.output_item.added`.\n   */\n  type: 'response.output_item.added';\n}\n\n/**\n * Returned when an Item is done streaming. Also emitted when a Response is\n * interrupted, incomplete, or cancelled.\n */\nexport interface ResponseOutputItemDoneEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The item to add to the conversation.\n   */\n  item: ConversationItem;\n\n  /**\n   * The index of the output item in the Response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the Response to which the item belongs.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.output_item.done`.\n   */\n  type: 'response.output_item.done';\n}\n\n/**\n * Returned when the text value of a \"text\" content part is updated.\n */\nexport interface ResponseTextDeltaEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The text delta.\n   */\n  delta: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.text.delta`.\n   */\n  type: 'response.text.delta';\n}\n\n/**\n * Returned when the text value of a \"text\" content part is done streaming. Also\n * emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseTextDoneEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The final text content.\n   */\n  text: string;\n\n  /**\n   * The event type, must be `response.text.done`.\n   */\n  type: 'response.text.done';\n}\n\n/**\n * Returned when a Session is created. Emitted automatically when a new connection\n * is established as the first server event. This event will contain the default\n * Session configuration.\n */\nexport interface SessionCreatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * Realtime session object configuration.\n   */\n  session: SessionsAPI.Session;\n\n  /**\n   * The event type, must be `session.created`.\n   */\n  type: 'session.created';\n}\n\n/**\n * Send this event to update the session’s default configuration. The client may\n * send this event at any time to update any field, except for `voice`. However,\n * note that once a session has been initialized with a particular `model`, it\n * can’t be changed to another model using `session.update`.\n *\n * When the server receives a `session.update`, it will respond with a\n * `session.updated` event showing the full, effective configuration. Only the\n * fields that are present are updated. To clear a field like `instructions`, pass\n * an empty string.\n */\nexport interface SessionUpdateEvent {\n  /**\n   * Realtime session object configuration.\n   */\n  session: SessionUpdateEvent.Session;\n\n  /**\n   * The event type, must be `session.update`.\n   */\n  type: 'session.update';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\nexport namespace SessionUpdateEvent {\n  /**\n   * Realtime session object configuration.\n   */\n  export interface Session {\n    /**\n     * Configuration options for the generated client secret.\n     */\n    client_secret?: Session.ClientSecret;\n\n    /**\n     * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n     * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n     * (mono), and little-endian byte order.\n     */\n    input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n    /**\n     * Configuration for input audio noise reduction. This can be set to `null` to turn\n     * off. Noise reduction filters audio added to the input audio buffer before it is\n     * sent to VAD and the model. Filtering the audio can improve VAD and turn\n     * detection accuracy (reducing false positives) and model performance by improving\n     * perception of the input audio.\n     */\n    input_audio_noise_reduction?: Session.InputAudioNoiseReduction;\n\n    /**\n     * Configuration for input audio transcription, defaults to off and can be set to\n     * `null` to turn off once on. Input audio transcription is not native to the\n     * model, since the model consumes audio directly. Transcription runs\n     * asynchronously through\n     * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n     * and should be treated as guidance of input audio content rather than precisely\n     * what the model heard. The client can optionally set the language and prompt for\n     * transcription, these offer additional guidance to the transcription service.\n     */\n    input_audio_transcription?: Session.InputAudioTranscription;\n\n    /**\n     * The default system instructions (i.e. system message) prepended to model calls.\n     * This field allows the client to guide the model on desired responses. The model\n     * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n     * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n     * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n     * instructions are not guaranteed to be followed by the model, but they provide\n     * guidance to the model on the desired behavior.\n     *\n     * Note that the server sets default instructions which will be used if this field\n     * is not set and are visible in the `session.created` event at the start of the\n     * session.\n     */\n    instructions?: string;\n\n    /**\n     * Maximum number of output tokens for a single assistant response, inclusive of\n     * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n     * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n     */\n    max_response_output_tokens?: number | 'inf';\n\n    /**\n     * The set of modalities the model can respond with. To disable audio, set this to\n     * [\"text\"].\n     */\n    modalities?: Array<'text' | 'audio'>;\n\n    /**\n     * The Realtime model used for this session.\n     */\n    model?:\n      | 'gpt-4o-realtime-preview'\n      | 'gpt-4o-realtime-preview-2024-10-01'\n      | 'gpt-4o-realtime-preview-2024-12-17'\n      | 'gpt-4o-realtime-preview-2025-06-03'\n      | 'gpt-4o-mini-realtime-preview'\n      | 'gpt-4o-mini-realtime-preview-2024-12-17';\n\n    /**\n     * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n     * For `pcm16`, output audio is sampled at a rate of 24kHz.\n     */\n    output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n    /**\n     * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the\n     * minimum speed. 1.5 is the maximum speed. This value can only be changed in\n     * between model turns, not while a response is in progress.\n     */\n    speed?: number;\n\n    /**\n     * Sampling temperature for the model, limited to [0.6, 1.2]. For audio models a\n     * temperature of 0.8 is highly recommended for best performance.\n     */\n    temperature?: number;\n\n    /**\n     * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n     * a function.\n     */\n    tool_choice?: string;\n\n    /**\n     * Tools (functions) available to the model.\n     */\n    tools?: Array<Session.Tool>;\n\n    /**\n     * Configuration options for tracing. Set to null to disable tracing. Once tracing\n     * is enabled for a session, the configuration cannot be modified.\n     *\n     * `auto` will create a trace for the session with default values for the workflow\n     * name, group id, and metadata.\n     */\n    tracing?: 'auto' | Session.TracingConfiguration;\n\n    /**\n     * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n     * set to `null` to turn off, in which case the client must manually trigger model\n     * response. Server VAD means that the model will detect the start and end of\n     * speech based on audio volume and respond at the end of user speech. Semantic VAD\n     * is more advanced and uses a turn detection model (in conjunction with VAD) to\n     * semantically estimate whether the user has finished speaking, then dynamically\n     * sets a timeout based on this probability. For example, if user audio trails off\n     * with \"uhhm\", the model will score a low probability of turn end and wait longer\n     * for the user to continue speaking. This can be useful for more natural\n     * conversations, but may have a higher latency.\n     */\n    turn_detection?: Session.TurnDetection;\n\n    /**\n     * The voice the model uses to respond. Voice cannot be changed during the session\n     * once the model has responded with audio at least once. Current voice options are\n     * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n     */\n    voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n  }\n\n  export namespace Session {\n    /**\n     * Configuration options for the generated client secret.\n     */\n    export interface ClientSecret {\n      /**\n       * Configuration for the ephemeral token expiration.\n       */\n      expires_after?: ClientSecret.ExpiresAfter;\n    }\n\n    export namespace ClientSecret {\n      /**\n       * Configuration for the ephemeral token expiration.\n       */\n      export interface ExpiresAfter {\n        /**\n         * The anchor point for the ephemeral token expiration. Only `created_at` is\n         * currently supported.\n         */\n        anchor: 'created_at';\n\n        /**\n         * The number of seconds from the anchor point to the expiration. Select a value\n         * between `10` and `7200`.\n         */\n        seconds?: number;\n      }\n    }\n\n    /**\n     * Configuration for input audio noise reduction. This can be set to `null` to turn\n     * off. Noise reduction filters audio added to the input audio buffer before it is\n     * sent to VAD and the model. Filtering the audio can improve VAD and turn\n     * detection accuracy (reducing false positives) and model performance by improving\n     * perception of the input audio.\n     */\n    export interface InputAudioNoiseReduction {\n      /**\n       * Type of noise reduction. `near_field` is for close-talking microphones such as\n       * headphones, `far_field` is for far-field microphones such as laptop or\n       * conference room microphones.\n       */\n      type?: 'near_field' | 'far_field';\n    }\n\n    /**\n     * Configuration for input audio transcription, defaults to off and can be set to\n     * `null` to turn off once on. Input audio transcription is not native to the\n     * model, since the model consumes audio directly. Transcription runs\n     * asynchronously through\n     * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n     * and should be treated as guidance of input audio content rather than precisely\n     * what the model heard. The client can optionally set the language and prompt for\n     * transcription, these offer additional guidance to the transcription service.\n     */\n    export interface InputAudioTranscription {\n      /**\n       * The language of the input audio. Supplying the input language in\n       * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n       * format will improve accuracy and latency.\n       */\n      language?: string;\n\n      /**\n       * The model to use for transcription, current options are `gpt-4o-transcribe`,\n       * `gpt-4o-mini-transcribe`, and `whisper-1`.\n       */\n      model?: string;\n\n      /**\n       * An optional text to guide the model's style or continue a previous audio\n       * segment. For `whisper-1`, the\n       * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n       * For `gpt-4o-transcribe` models, the prompt is a free text string, for example\n       * \"expect words related to technology\".\n       */\n      prompt?: string;\n    }\n\n    export interface Tool {\n      /**\n       * The description of the function, including guidance on when and how to call it,\n       * and guidance about what to tell the user when calling (if anything).\n       */\n      description?: string;\n\n      /**\n       * The name of the function.\n       */\n      name?: string;\n\n      /**\n       * Parameters of the function in JSON Schema.\n       */\n      parameters?: unknown;\n\n      /**\n       * The type of the tool, i.e. `function`.\n       */\n      type?: 'function';\n    }\n\n    /**\n     * Granular configuration for tracing.\n     */\n    export interface TracingConfiguration {\n      /**\n       * The group id to attach to this trace to enable filtering and grouping in the\n       * traces dashboard.\n       */\n      group_id?: string;\n\n      /**\n       * The arbitrary metadata to attach to this trace to enable filtering in the traces\n       * dashboard.\n       */\n      metadata?: unknown;\n\n      /**\n       * The name of the workflow to attach to this trace. This is used to name the trace\n       * in the traces dashboard.\n       */\n      workflow_name?: string;\n    }\n\n    /**\n     * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n     * set to `null` to turn off, in which case the client must manually trigger model\n     * response. Server VAD means that the model will detect the start and end of\n     * speech based on audio volume and respond at the end of user speech. Semantic VAD\n     * is more advanced and uses a turn detection model (in conjunction with VAD) to\n     * semantically estimate whether the user has finished speaking, then dynamically\n     * sets a timeout based on this probability. For example, if user audio trails off\n     * with \"uhhm\", the model will score a low probability of turn end and wait longer\n     * for the user to continue speaking. This can be useful for more natural\n     * conversations, but may have a higher latency.\n     */\n    export interface TurnDetection {\n      /**\n       * Whether or not to automatically generate a response when a VAD stop event\n       * occurs.\n       */\n      create_response?: boolean;\n\n      /**\n       * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n       * will wait longer for the user to continue speaking, `high` will respond more\n       * quickly. `auto` is the default and is equivalent to `medium`.\n       */\n      eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n      /**\n       * Whether or not to automatically interrupt any ongoing response with output to\n       * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n       * occurs.\n       */\n      interrupt_response?: boolean;\n\n      /**\n       * Used only for `server_vad` mode. Amount of audio to include before the VAD\n       * detected speech (in milliseconds). Defaults to 300ms.\n       */\n      prefix_padding_ms?: number;\n\n      /**\n       * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n       * milliseconds). Defaults to 500ms. With shorter values the model will respond\n       * more quickly, but may jump in on short pauses from the user.\n       */\n      silence_duration_ms?: number;\n\n      /**\n       * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n       * defaults to 0.5. A higher threshold will require louder audio to activate the\n       * model, and thus might perform better in noisy environments.\n       */\n      threshold?: number;\n\n      /**\n       * Type of turn detection.\n       */\n      type?: 'server_vad' | 'semantic_vad';\n    }\n  }\n}\n\n/**\n * Returned when a session is updated with a `session.update` event, unless there\n * is an error.\n */\nexport interface SessionUpdatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * Realtime session object configuration.\n   */\n  session: SessionsAPI.Session;\n\n  /**\n   * The event type, must be `session.updated`.\n   */\n  type: 'session.updated';\n}\n\n/**\n * Send this event to update a transcription session.\n */\nexport interface TranscriptionSessionUpdate {\n  /**\n   * Realtime transcription session object configuration.\n   */\n  session: TranscriptionSessionUpdate.Session;\n\n  /**\n   * The event type, must be `transcription_session.update`.\n   */\n  type: 'transcription_session.update';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\nexport namespace TranscriptionSessionUpdate {\n  /**\n   * Realtime transcription session object configuration.\n   */\n  export interface Session {\n    /**\n     * Configuration options for the generated client secret.\n     */\n    client_secret?: Session.ClientSecret;\n\n    /**\n     * The set of items to include in the transcription. Current available items are:\n     *\n     * - `item.input_audio_transcription.logprobs`\n     */\n    include?: Array<string>;\n\n    /**\n     * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n     * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n     * (mono), and little-endian byte order.\n     */\n    input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n    /**\n     * Configuration for input audio noise reduction. This can be set to `null` to turn\n     * off. Noise reduction filters audio added to the input audio buffer before it is\n     * sent to VAD and the model. Filtering the audio can improve VAD and turn\n     * detection accuracy (reducing false positives) and model performance by improving\n     * perception of the input audio.\n     */\n    input_audio_noise_reduction?: Session.InputAudioNoiseReduction;\n\n    /**\n     * Configuration for input audio transcription. The client can optionally set the\n     * language and prompt for transcription, these offer additional guidance to the\n     * transcription service.\n     */\n    input_audio_transcription?: Session.InputAudioTranscription;\n\n    /**\n     * The set of modalities the model can respond with. To disable audio, set this to\n     * [\"text\"].\n     */\n    modalities?: Array<'text' | 'audio'>;\n\n    /**\n     * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n     * set to `null` to turn off, in which case the client must manually trigger model\n     * response. Server VAD means that the model will detect the start and end of\n     * speech based on audio volume and respond at the end of user speech. Semantic VAD\n     * is more advanced and uses a turn detection model (in conjunction with VAD) to\n     * semantically estimate whether the user has finished speaking, then dynamically\n     * sets a timeout based on this probability. For example, if user audio trails off\n     * with \"uhhm\", the model will score a low probability of turn end and wait longer\n     * for the user to continue speaking. This can be useful for more natural\n     * conversations, but may have a higher latency.\n     */\n    turn_detection?: Session.TurnDetection;\n  }\n\n  export namespace Session {\n    /**\n     * Configuration options for the generated client secret.\n     */\n    export interface ClientSecret {\n      /**\n       * Configuration for the ephemeral token expiration.\n       */\n      expires_at?: ClientSecret.ExpiresAt;\n    }\n\n    export namespace ClientSecret {\n      /**\n       * Configuration for the ephemeral token expiration.\n       */\n      export interface ExpiresAt {\n        /**\n         * The anchor point for the ephemeral token expiration. Only `created_at` is\n         * currently supported.\n         */\n        anchor?: 'created_at';\n\n        /**\n         * The number of seconds from the anchor point to the expiration. Select a value\n         * between `10` and `7200`.\n         */\n        seconds?: number;\n      }\n    }\n\n    /**\n     * Configuration for input audio noise reduction. This can be set to `null` to turn\n     * off. Noise reduction filters audio added to the input audio buffer before it is\n     * sent to VAD and the model. Filtering the audio can improve VAD and turn\n     * detection accuracy (reducing false positives) and model performance by improving\n     * perception of the input audio.\n     */\n    export interface InputAudioNoiseReduction {\n      /**\n       * Type of noise reduction. `near_field` is for close-talking microphones such as\n       * headphones, `far_field` is for far-field microphones such as laptop or\n       * conference room microphones.\n       */\n      type?: 'near_field' | 'far_field';\n    }\n\n    /**\n     * Configuration for input audio transcription. The client can optionally set the\n     * language and prompt for transcription, these offer additional guidance to the\n     * transcription service.\n     */\n    export interface InputAudioTranscription {\n      /**\n       * The language of the input audio. Supplying the input language in\n       * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n       * format will improve accuracy and latency.\n       */\n      language?: string;\n\n      /**\n       * The model to use for transcription, current options are `gpt-4o-transcribe`,\n       * `gpt-4o-mini-transcribe`, and `whisper-1`.\n       */\n      model?: 'gpt-4o-transcribe' | 'gpt-4o-mini-transcribe' | 'whisper-1';\n\n      /**\n       * An optional text to guide the model's style or continue a previous audio\n       * segment. For `whisper-1`, the\n       * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n       * For `gpt-4o-transcribe` models, the prompt is a free text string, for example\n       * \"expect words related to technology\".\n       */\n      prompt?: string;\n    }\n\n    /**\n     * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n     * set to `null` to turn off, in which case the client must manually trigger model\n     * response. Server VAD means that the model will detect the start and end of\n     * speech based on audio volume and respond at the end of user speech. Semantic VAD\n     * is more advanced and uses a turn detection model (in conjunction with VAD) to\n     * semantically estimate whether the user has finished speaking, then dynamically\n     * sets a timeout based on this probability. For example, if user audio trails off\n     * with \"uhhm\", the model will score a low probability of turn end and wait longer\n     * for the user to continue speaking. This can be useful for more natural\n     * conversations, but may have a higher latency.\n     */\n    export interface TurnDetection {\n      /**\n       * Whether or not to automatically generate a response when a VAD stop event\n       * occurs. Not available for transcription sessions.\n       */\n      create_response?: boolean;\n\n      /**\n       * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n       * will wait longer for the user to continue speaking, `high` will respond more\n       * quickly. `auto` is the default and is equivalent to `medium`.\n       */\n      eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n      /**\n       * Whether or not to automatically interrupt any ongoing response with output to\n       * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n       * occurs. Not available for transcription sessions.\n       */\n      interrupt_response?: boolean;\n\n      /**\n       * Used only for `server_vad` mode. Amount of audio to include before the VAD\n       * detected speech (in milliseconds). Defaults to 300ms.\n       */\n      prefix_padding_ms?: number;\n\n      /**\n       * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n       * milliseconds). Defaults to 500ms. With shorter values the model will respond\n       * more quickly, but may jump in on short pauses from the user.\n       */\n      silence_duration_ms?: number;\n\n      /**\n       * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n       * defaults to 0.5. A higher threshold will require louder audio to activate the\n       * model, and thus might perform better in noisy environments.\n       */\n      threshold?: number;\n\n      /**\n       * Type of turn detection.\n       */\n      type?: 'server_vad' | 'semantic_vad';\n    }\n  }\n}\n\n/**\n * Returned when a transcription session is updated with a\n * `transcription_session.update` event, unless there is an error.\n */\nexport interface TranscriptionSessionUpdatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * A new Realtime transcription session configuration.\n   *\n   * When a session is created on the server via REST API, the session object also\n   * contains an ephemeral key. Default TTL for keys is 10 minutes. This property is\n   * not present when a session is updated via the WebSocket API.\n   */\n  session: TranscriptionSessionsAPI.TranscriptionSession;\n\n  /**\n   * The event type, must be `transcription_session.updated`.\n   */\n  type: 'transcription_session.updated';\n}\n\nRealtime.Sessions = Sessions;\nRealtime.TranscriptionSessions = TranscriptionSessions;\n\nexport declare namespace Realtime {\n  export {\n    type ConversationCreatedEvent as ConversationCreatedEvent,\n    type ConversationItem as ConversationItem,\n    type ConversationItemContent as ConversationItemContent,\n    type ConversationItemCreateEvent as ConversationItemCreateEvent,\n    type ConversationItemCreatedEvent as ConversationItemCreatedEvent,\n    type ConversationItemDeleteEvent as ConversationItemDeleteEvent,\n    type ConversationItemDeletedEvent as ConversationItemDeletedEvent,\n    type ConversationItemInputAudioTranscriptionCompletedEvent as ConversationItemInputAudioTranscriptionCompletedEvent,\n    type ConversationItemInputAudioTranscriptionDeltaEvent as ConversationItemInputAudioTranscriptionDeltaEvent,\n    type ConversationItemInputAudioTranscriptionFailedEvent as ConversationItemInputAudioTranscriptionFailedEvent,\n    type ConversationItemRetrieveEvent as ConversationItemRetrieveEvent,\n    type ConversationItemTruncateEvent as ConversationItemTruncateEvent,\n    type ConversationItemTruncatedEvent as ConversationItemTruncatedEvent,\n    type ConversationItemWithReference as ConversationItemWithReference,\n    type ErrorEvent as ErrorEvent,\n    type InputAudioBufferAppendEvent as InputAudioBufferAppendEvent,\n    type InputAudioBufferClearEvent as InputAudioBufferClearEvent,\n    type InputAudioBufferClearedEvent as InputAudioBufferClearedEvent,\n    type InputAudioBufferCommitEvent as InputAudioBufferCommitEvent,\n    type InputAudioBufferCommittedEvent as InputAudioBufferCommittedEvent,\n    type InputAudioBufferSpeechStartedEvent as InputAudioBufferSpeechStartedEvent,\n    type InputAudioBufferSpeechStoppedEvent as InputAudioBufferSpeechStoppedEvent,\n    type RateLimitsUpdatedEvent as RateLimitsUpdatedEvent,\n    type RealtimeClientEvent as RealtimeClientEvent,\n    type RealtimeResponse as RealtimeResponse,\n    type RealtimeResponseStatus as RealtimeResponseStatus,\n    type RealtimeResponseUsage as RealtimeResponseUsage,\n    type RealtimeServerEvent as RealtimeServerEvent,\n    type ResponseAudioDeltaEvent as ResponseAudioDeltaEvent,\n    type ResponseAudioDoneEvent as ResponseAudioDoneEvent,\n    type ResponseAudioTranscriptDeltaEvent as ResponseAudioTranscriptDeltaEvent,\n    type ResponseAudioTranscriptDoneEvent as ResponseAudioTranscriptDoneEvent,\n    type ResponseCancelEvent as ResponseCancelEvent,\n    type ResponseContentPartAddedEvent as ResponseContentPartAddedEvent,\n    type ResponseContentPartDoneEvent as ResponseContentPartDoneEvent,\n    type ResponseCreateEvent as ResponseCreateEvent,\n    type ResponseCreatedEvent as ResponseCreatedEvent,\n    type ResponseDoneEvent as ResponseDoneEvent,\n    type ResponseFunctionCallArgumentsDeltaEvent as ResponseFunctionCallArgumentsDeltaEvent,\n    type ResponseFunctionCallArgumentsDoneEvent as ResponseFunctionCallArgumentsDoneEvent,\n    type ResponseOutputItemAddedEvent as ResponseOutputItemAddedEvent,\n    type ResponseOutputItemDoneEvent as ResponseOutputItemDoneEvent,\n    type ResponseTextDeltaEvent as ResponseTextDeltaEvent,\n    type ResponseTextDoneEvent as ResponseTextDoneEvent,\n    type SessionCreatedEvent as SessionCreatedEvent,\n    type SessionUpdateEvent as SessionUpdateEvent,\n    type SessionUpdatedEvent as SessionUpdatedEvent,\n    type TranscriptionSessionUpdate as TranscriptionSessionUpdate,\n    type TranscriptionSessionUpdatedEvent as TranscriptionSessionUpdatedEvent,\n  };\n\n  export {\n    Sessions as Sessions,\n    type SessionsAPISession as Session,\n    type SessionCreateResponse as SessionCreateResponse,\n    type SessionCreateParams as SessionCreateParams,\n  };\n\n  export {\n    TranscriptionSessions as TranscriptionSessions,\n    type TranscriptionSession as TranscriptionSession,\n    type TranscriptionSessionCreateParams as TranscriptionSessionCreateParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/beta/realtime/sessions.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { APIPromise } from '../../../core/api-promise';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\n\nexport class Sessions extends APIResource {\n  /**\n   * Create an ephemeral API token for use in client-side applications with the\n   * Realtime API. Can be configured with the same session parameters as the\n   * `session.update` client event.\n   *\n   * It responds with a session object, plus a `client_secret` key which contains a\n   * usable ephemeral API token that can be used to authenticate browser clients for\n   * the Realtime API.\n   *\n   * @example\n   * ```ts\n   * const session =\n   *   await client.beta.realtime.sessions.create();\n   * ```\n   */\n  create(body: SessionCreateParams, options?: RequestOptions): APIPromise<SessionCreateResponse> {\n    return this._client.post('/realtime/sessions', {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n}\n\n/**\n * Realtime session object configuration.\n */\nexport interface Session {\n  /**\n   * Unique identifier for the session that looks like `sess_1234567890abcdef`.\n   */\n  id?: string;\n\n  /**\n   * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n   * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n   * (mono), and little-endian byte order.\n   */\n  input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  input_audio_noise_reduction?: Session.InputAudioNoiseReduction;\n\n  /**\n   * Configuration for input audio transcription, defaults to off and can be set to\n   * `null` to turn off once on. Input audio transcription is not native to the\n   * model, since the model consumes audio directly. Transcription runs\n   * asynchronously through\n   * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n   * and should be treated as guidance of input audio content rather than precisely\n   * what the model heard. The client can optionally set the language and prompt for\n   * transcription, these offer additional guidance to the transcription service.\n   */\n  input_audio_transcription?: Session.InputAudioTranscription;\n\n  /**\n   * The default system instructions (i.e. system message) prepended to model calls.\n   * This field allows the client to guide the model on desired responses. The model\n   * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n   * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n   * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n   * instructions are not guaranteed to be followed by the model, but they provide\n   * guidance to the model on the desired behavior.\n   *\n   * Note that the server sets default instructions which will be used if this field\n   * is not set and are visible in the `session.created` event at the start of the\n   * session.\n   */\n  instructions?: string;\n\n  /**\n   * Maximum number of output tokens for a single assistant response, inclusive of\n   * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n   * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n   */\n  max_response_output_tokens?: number | 'inf';\n\n  /**\n   * The set of modalities the model can respond with. To disable audio, set this to\n   * [\"text\"].\n   */\n  modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * The Realtime model used for this session.\n   */\n  model?:\n    | 'gpt-4o-realtime-preview'\n    | 'gpt-4o-realtime-preview-2024-10-01'\n    | 'gpt-4o-realtime-preview-2024-12-17'\n    | 'gpt-4o-realtime-preview-2025-06-03'\n    | 'gpt-4o-mini-realtime-preview'\n    | 'gpt-4o-mini-realtime-preview-2024-12-17';\n\n  /**\n   * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n   * For `pcm16`, output audio is sampled at a rate of 24kHz.\n   */\n  output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n  /**\n   * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the\n   * minimum speed. 1.5 is the maximum speed. This value can only be changed in\n   * between model turns, not while a response is in progress.\n   */\n  speed?: number;\n\n  /**\n   * Sampling temperature for the model, limited to [0.6, 1.2]. For audio models a\n   * temperature of 0.8 is highly recommended for best performance.\n   */\n  temperature?: number;\n\n  /**\n   * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n   * a function.\n   */\n  tool_choice?: string;\n\n  /**\n   * Tools (functions) available to the model.\n   */\n  tools?: Array<Session.Tool>;\n\n  /**\n   * Configuration options for tracing. Set to null to disable tracing. Once tracing\n   * is enabled for a session, the configuration cannot be modified.\n   *\n   * `auto` will create a trace for the session with default values for the workflow\n   * name, group id, and metadata.\n   */\n  tracing?: 'auto' | Session.TracingConfiguration;\n\n  /**\n   * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n   * set to `null` to turn off, in which case the client must manually trigger model\n   * response. Server VAD means that the model will detect the start and end of\n   * speech based on audio volume and respond at the end of user speech. Semantic VAD\n   * is more advanced and uses a turn detection model (in conjunction with VAD) to\n   * semantically estimate whether the user has finished speaking, then dynamically\n   * sets a timeout based on this probability. For example, if user audio trails off\n   * with \"uhhm\", the model will score a low probability of turn end and wait longer\n   * for the user to continue speaking. This can be useful for more natural\n   * conversations, but may have a higher latency.\n   */\n  turn_detection?: Session.TurnDetection;\n\n  /**\n   * The voice the model uses to respond. Voice cannot be changed during the session\n   * once the model has responded with audio at least once. Current voice options are\n   * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n   */\n  voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n}\n\nexport namespace Session {\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  export interface InputAudioNoiseReduction {\n    /**\n     * Type of noise reduction. `near_field` is for close-talking microphones such as\n     * headphones, `far_field` is for far-field microphones such as laptop or\n     * conference room microphones.\n     */\n    type?: 'near_field' | 'far_field';\n  }\n\n  /**\n   * Configuration for input audio transcription, defaults to off and can be set to\n   * `null` to turn off once on. Input audio transcription is not native to the\n   * model, since the model consumes audio directly. Transcription runs\n   * asynchronously through\n   * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n   * and should be treated as guidance of input audio content rather than precisely\n   * what the model heard. The client can optionally set the language and prompt for\n   * transcription, these offer additional guidance to the transcription service.\n   */\n  export interface InputAudioTranscription {\n    /**\n     * The language of the input audio. Supplying the input language in\n     * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n     * format will improve accuracy and latency.\n     */\n    language?: string;\n\n    /**\n     * The model to use for transcription, current options are `gpt-4o-transcribe`,\n     * `gpt-4o-mini-transcribe`, and `whisper-1`.\n     */\n    model?: string;\n\n    /**\n     * An optional text to guide the model's style or continue a previous audio\n     * segment. For `whisper-1`, the\n     * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n     * For `gpt-4o-transcribe` models, the prompt is a free text string, for example\n     * \"expect words related to technology\".\n     */\n    prompt?: string;\n  }\n\n  export interface Tool {\n    /**\n     * The description of the function, including guidance on when and how to call it,\n     * and guidance about what to tell the user when calling (if anything).\n     */\n    description?: string;\n\n    /**\n     * The name of the function.\n     */\n    name?: string;\n\n    /**\n     * Parameters of the function in JSON Schema.\n     */\n    parameters?: unknown;\n\n    /**\n     * The type of the tool, i.e. `function`.\n     */\n    type?: 'function';\n  }\n\n  /**\n   * Granular configuration for tracing.\n   */\n  export interface TracingConfiguration {\n    /**\n     * The group id to attach to this trace to enable filtering and grouping in the\n     * traces dashboard.\n     */\n    group_id?: string;\n\n    /**\n     * The arbitrary metadata to attach to this trace to enable filtering in the traces\n     * dashboard.\n     */\n    metadata?: unknown;\n\n    /**\n     * The name of the workflow to attach to this trace. This is used to name the trace\n     * in the traces dashboard.\n     */\n    workflow_name?: string;\n  }\n\n  /**\n   * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n   * set to `null` to turn off, in which case the client must manually trigger model\n   * response. Server VAD means that the model will detect the start and end of\n   * speech based on audio volume and respond at the end of user speech. Semantic VAD\n   * is more advanced and uses a turn detection model (in conjunction with VAD) to\n   * semantically estimate whether the user has finished speaking, then dynamically\n   * sets a timeout based on this probability. For example, if user audio trails off\n   * with \"uhhm\", the model will score a low probability of turn end and wait longer\n   * for the user to continue speaking. This can be useful for more natural\n   * conversations, but may have a higher latency.\n   */\n  export interface TurnDetection {\n    /**\n     * Whether or not to automatically generate a response when a VAD stop event\n     * occurs.\n     */\n    create_response?: boolean;\n\n    /**\n     * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n     * will wait longer for the user to continue speaking, `high` will respond more\n     * quickly. `auto` is the default and is equivalent to `medium`.\n     */\n    eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n    /**\n     * Whether or not to automatically interrupt any ongoing response with output to\n     * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n     * occurs.\n     */\n    interrupt_response?: boolean;\n\n    /**\n     * Used only for `server_vad` mode. Amount of audio to include before the VAD\n     * detected speech (in milliseconds). Defaults to 300ms.\n     */\n    prefix_padding_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n     * milliseconds). Defaults to 500ms. With shorter values the model will respond\n     * more quickly, but may jump in on short pauses from the user.\n     */\n    silence_duration_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n     * defaults to 0.5. A higher threshold will require louder audio to activate the\n     * model, and thus might perform better in noisy environments.\n     */\n    threshold?: number;\n\n    /**\n     * Type of turn detection.\n     */\n    type?: 'server_vad' | 'semantic_vad';\n  }\n}\n\n/**\n * A new Realtime session configuration, with an ephemeral key. Default TTL for\n * keys is one minute.\n */\nexport interface SessionCreateResponse {\n  /**\n   * Ephemeral key returned by the API.\n   */\n  client_secret: SessionCreateResponse.ClientSecret;\n\n  /**\n   * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n   */\n  input_audio_format?: string;\n\n  /**\n   * Configuration for input audio transcription, defaults to off and can be set to\n   * `null` to turn off once on. Input audio transcription is not native to the\n   * model, since the model consumes audio directly. Transcription runs\n   * asynchronously and should be treated as rough guidance rather than the\n   * representation understood by the model.\n   */\n  input_audio_transcription?: SessionCreateResponse.InputAudioTranscription;\n\n  /**\n   * The default system instructions (i.e. system message) prepended to model calls.\n   * This field allows the client to guide the model on desired responses. The model\n   * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n   * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n   * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n   * instructions are not guaranteed to be followed by the model, but they provide\n   * guidance to the model on the desired behavior.\n   *\n   * Note that the server sets default instructions which will be used if this field\n   * is not set and are visible in the `session.created` event at the start of the\n   * session.\n   */\n  instructions?: string;\n\n  /**\n   * Maximum number of output tokens for a single assistant response, inclusive of\n   * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n   * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n   */\n  max_response_output_tokens?: number | 'inf';\n\n  /**\n   * The set of modalities the model can respond with. To disable audio, set this to\n   * [\"text\"].\n   */\n  modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n   */\n  output_audio_format?: string;\n\n  /**\n   * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the\n   * minimum speed. 1.5 is the maximum speed. This value can only be changed in\n   * between model turns, not while a response is in progress.\n   */\n  speed?: number;\n\n  /**\n   * Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.\n   */\n  temperature?: number;\n\n  /**\n   * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n   * a function.\n   */\n  tool_choice?: string;\n\n  /**\n   * Tools (functions) available to the model.\n   */\n  tools?: Array<SessionCreateResponse.Tool>;\n\n  /**\n   * Configuration options for tracing. Set to null to disable tracing. Once tracing\n   * is enabled for a session, the configuration cannot be modified.\n   *\n   * `auto` will create a trace for the session with default values for the workflow\n   * name, group id, and metadata.\n   */\n  tracing?: 'auto' | SessionCreateResponse.TracingConfiguration;\n\n  /**\n   * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n   * means that the model will detect the start and end of speech based on audio\n   * volume and respond at the end of user speech.\n   */\n  turn_detection?: SessionCreateResponse.TurnDetection;\n\n  /**\n   * The voice the model uses to respond. Voice cannot be changed during the session\n   * once the model has responded with audio at least once. Current voice options are\n   * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n   */\n  voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n}\n\nexport namespace SessionCreateResponse {\n  /**\n   * Ephemeral key returned by the API.\n   */\n  export interface ClientSecret {\n    /**\n     * Timestamp for when the token expires. Currently, all tokens expire after one\n     * minute.\n     */\n    expires_at: number;\n\n    /**\n     * Ephemeral key usable in client environments to authenticate connections to the\n     * Realtime API. Use this in client-side environments rather than a standard API\n     * token, which should only be used server-side.\n     */\n    value: string;\n  }\n\n  /**\n   * Configuration for input audio transcription, defaults to off and can be set to\n   * `null` to turn off once on. Input audio transcription is not native to the\n   * model, since the model consumes audio directly. Transcription runs\n   * asynchronously and should be treated as rough guidance rather than the\n   * representation understood by the model.\n   */\n  export interface InputAudioTranscription {\n    /**\n     * The model to use for transcription.\n     */\n    model?: string;\n  }\n\n  export interface Tool {\n    /**\n     * The description of the function, including guidance on when and how to call it,\n     * and guidance about what to tell the user when calling (if anything).\n     */\n    description?: string;\n\n    /**\n     * The name of the function.\n     */\n    name?: string;\n\n    /**\n     * Parameters of the function in JSON Schema.\n     */\n    parameters?: unknown;\n\n    /**\n     * The type of the tool, i.e. `function`.\n     */\n    type?: 'function';\n  }\n\n  /**\n   * Granular configuration for tracing.\n   */\n  export interface TracingConfiguration {\n    /**\n     * The group id to attach to this trace to enable filtering and grouping in the\n     * traces dashboard.\n     */\n    group_id?: string;\n\n    /**\n     * The arbitrary metadata to attach to this trace to enable filtering in the traces\n     * dashboard.\n     */\n    metadata?: unknown;\n\n    /**\n     * The name of the workflow to attach to this trace. This is used to name the trace\n     * in the traces dashboard.\n     */\n    workflow_name?: string;\n  }\n\n  /**\n   * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n   * means that the model will detect the start and end of speech based on audio\n   * volume and respond at the end of user speech.\n   */\n  export interface TurnDetection {\n    /**\n     * Amount of audio to include before the VAD detected speech (in milliseconds).\n     * Defaults to 300ms.\n     */\n    prefix_padding_ms?: number;\n\n    /**\n     * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.\n     * With shorter values the model will respond more quickly, but may jump in on\n     * short pauses from the user.\n     */\n    silence_duration_ms?: number;\n\n    /**\n     * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher\n     * threshold will require louder audio to activate the model, and thus might\n     * perform better in noisy environments.\n     */\n    threshold?: number;\n\n    /**\n     * Type of turn detection, only `server_vad` is currently supported.\n     */\n    type?: string;\n  }\n}\n\nexport interface SessionCreateParams {\n  /**\n   * Configuration options for the generated client secret.\n   */\n  client_secret?: SessionCreateParams.ClientSecret;\n\n  /**\n   * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n   * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n   * (mono), and little-endian byte order.\n   */\n  input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  input_audio_noise_reduction?: SessionCreateParams.InputAudioNoiseReduction;\n\n  /**\n   * Configuration for input audio transcription, defaults to off and can be set to\n   * `null` to turn off once on. Input audio transcription is not native to the\n   * model, since the model consumes audio directly. Transcription runs\n   * asynchronously through\n   * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n   * and should be treated as guidance of input audio content rather than precisely\n   * what the model heard. The client can optionally set the language and prompt for\n   * transcription, these offer additional guidance to the transcription service.\n   */\n  input_audio_transcription?: SessionCreateParams.InputAudioTranscription;\n\n  /**\n   * The default system instructions (i.e. system message) prepended to model calls.\n   * This field allows the client to guide the model on desired responses. The model\n   * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n   * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n   * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n   * instructions are not guaranteed to be followed by the model, but they provide\n   * guidance to the model on the desired behavior.\n   *\n   * Note that the server sets default instructions which will be used if this field\n   * is not set and are visible in the `session.created` event at the start of the\n   * session.\n   */\n  instructions?: string;\n\n  /**\n   * Maximum number of output tokens for a single assistant response, inclusive of\n   * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n   * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n   */\n  max_response_output_tokens?: number | 'inf';\n\n  /**\n   * The set of modalities the model can respond with. To disable audio, set this to\n   * [\"text\"].\n   */\n  modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * The Realtime model used for this session.\n   */\n  model?:\n    | 'gpt-4o-realtime-preview'\n    | 'gpt-4o-realtime-preview-2024-10-01'\n    | 'gpt-4o-realtime-preview-2024-12-17'\n    | 'gpt-4o-realtime-preview-2025-06-03'\n    | 'gpt-4o-mini-realtime-preview'\n    | 'gpt-4o-mini-realtime-preview-2024-12-17';\n\n  /**\n   * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n   * For `pcm16`, output audio is sampled at a rate of 24kHz.\n   */\n  output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n  /**\n   * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the\n   * minimum speed. 1.5 is the maximum speed. This value can only be changed in\n   * between model turns, not while a response is in progress.\n   */\n  speed?: number;\n\n  /**\n   * Sampling temperature for the model, limited to [0.6, 1.2]. For audio models a\n   * temperature of 0.8 is highly recommended for best performance.\n   */\n  temperature?: number;\n\n  /**\n   * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n   * a function.\n   */\n  tool_choice?: string;\n\n  /**\n   * Tools (functions) available to the model.\n   */\n  tools?: Array<SessionCreateParams.Tool>;\n\n  /**\n   * Configuration options for tracing. Set to null to disable tracing. Once tracing\n   * is enabled for a session, the configuration cannot be modified.\n   *\n   * `auto` will create a trace for the session with default values for the workflow\n   * name, group id, and metadata.\n   */\n  tracing?: 'auto' | SessionCreateParams.TracingConfiguration;\n\n  /**\n   * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n   * set to `null` to turn off, in which case the client must manually trigger model\n   * response. Server VAD means that the model will detect the start and end of\n   * speech based on audio volume and respond at the end of user speech. Semantic VAD\n   * is more advanced and uses a turn detection model (in conjunction with VAD) to\n   * semantically estimate whether the user has finished speaking, then dynamically\n   * sets a timeout based on this probability. For example, if user audio trails off\n   * with \"uhhm\", the model will score a low probability of turn end and wait longer\n   * for the user to continue speaking. This can be useful for more natural\n   * conversations, but may have a higher latency.\n   */\n  turn_detection?: SessionCreateParams.TurnDetection;\n\n  /**\n   * The voice the model uses to respond. Voice cannot be changed during the session\n   * once the model has responded with audio at least once. Current voice options are\n   * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n   */\n  voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n}\n\nexport namespace SessionCreateParams {\n  /**\n   * Configuration options for the generated client secret.\n   */\n  export interface ClientSecret {\n    /**\n     * Configuration for the ephemeral token expiration.\n     */\n    expires_after?: ClientSecret.ExpiresAfter;\n  }\n\n  export namespace ClientSecret {\n    /**\n     * Configuration for the ephemeral token expiration.\n     */\n    export interface ExpiresAfter {\n      /**\n       * The anchor point for the ephemeral token expiration. Only `created_at` is\n       * currently supported.\n       */\n      anchor: 'created_at';\n\n      /**\n       * The number of seconds from the anchor point to the expiration. Select a value\n       * between `10` and `7200`.\n       */\n      seconds?: number;\n    }\n  }\n\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  export interface InputAudioNoiseReduction {\n    /**\n     * Type of noise reduction. `near_field` is for close-talking microphones such as\n     * headphones, `far_field` is for far-field microphones such as laptop or\n     * conference room microphones.\n     */\n    type?: 'near_field' | 'far_field';\n  }\n\n  /**\n   * Configuration for input audio transcription, defaults to off and can be set to\n   * `null` to turn off once on. Input audio transcription is not native to the\n   * model, since the model consumes audio directly. Transcription runs\n   * asynchronously through\n   * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n   * and should be treated as guidance of input audio content rather than precisely\n   * what the model heard. The client can optionally set the language and prompt for\n   * transcription, these offer additional guidance to the transcription service.\n   */\n  export interface InputAudioTranscription {\n    /**\n     * The language of the input audio. Supplying the input language in\n     * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n     * format will improve accuracy and latency.\n     */\n    language?: string;\n\n    /**\n     * The model to use for transcription, current options are `gpt-4o-transcribe`,\n     * `gpt-4o-mini-transcribe`, and `whisper-1`.\n     */\n    model?: string;\n\n    /**\n     * An optional text to guide the model's style or continue a previous audio\n     * segment. For `whisper-1`, the\n     * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n     * For `gpt-4o-transcribe` models, the prompt is a free text string, for example\n     * \"expect words related to technology\".\n     */\n    prompt?: string;\n  }\n\n  export interface Tool {\n    /**\n     * The description of the function, including guidance on when and how to call it,\n     * and guidance about what to tell the user when calling (if anything).\n     */\n    description?: string;\n\n    /**\n     * The name of the function.\n     */\n    name?: string;\n\n    /**\n     * Parameters of the function in JSON Schema.\n     */\n    parameters?: unknown;\n\n    /**\n     * The type of the tool, i.e. `function`.\n     */\n    type?: 'function';\n  }\n\n  /**\n   * Granular configuration for tracing.\n   */\n  export interface TracingConfiguration {\n    /**\n     * The group id to attach to this trace to enable filtering and grouping in the\n     * traces dashboard.\n     */\n    group_id?: string;\n\n    /**\n     * The arbitrary metadata to attach to this trace to enable filtering in the traces\n     * dashboard.\n     */\n    metadata?: unknown;\n\n    /**\n     * The name of the workflow to attach to this trace. This is used to name the trace\n     * in the traces dashboard.\n     */\n    workflow_name?: string;\n  }\n\n  /**\n   * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n   * set to `null` to turn off, in which case the client must manually trigger model\n   * response. Server VAD means that the model will detect the start and end of\n   * speech based on audio volume and respond at the end of user speech. Semantic VAD\n   * is more advanced and uses a turn detection model (in conjunction with VAD) to\n   * semantically estimate whether the user has finished speaking, then dynamically\n   * sets a timeout based on this probability. For example, if user audio trails off\n   * with \"uhhm\", the model will score a low probability of turn end and wait longer\n   * for the user to continue speaking. This can be useful for more natural\n   * conversations, but may have a higher latency.\n   */\n  export interface TurnDetection {\n    /**\n     * Whether or not to automatically generate a response when a VAD stop event\n     * occurs.\n     */\n    create_response?: boolean;\n\n    /**\n     * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n     * will wait longer for the user to continue speaking, `high` will respond more\n     * quickly. `auto` is the default and is equivalent to `medium`.\n     */\n    eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n    /**\n     * Whether or not to automatically interrupt any ongoing response with output to\n     * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n     * occurs.\n     */\n    interrupt_response?: boolean;\n\n    /**\n     * Used only for `server_vad` mode. Amount of audio to include before the VAD\n     * detected speech (in milliseconds). Defaults to 300ms.\n     */\n    prefix_padding_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n     * milliseconds). Defaults to 500ms. With shorter values the model will respond\n     * more quickly, but may jump in on short pauses from the user.\n     */\n    silence_duration_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n     * defaults to 0.5. A higher threshold will require louder audio to activate the\n     * model, and thus might perform better in noisy environments.\n     */\n    threshold?: number;\n\n    /**\n     * Type of turn detection.\n     */\n    type?: 'server_vad' | 'semantic_vad';\n  }\n}\n\nexport declare namespace Sessions {\n  export {\n    type Session as Session,\n    type SessionCreateResponse as SessionCreateResponse,\n    type SessionCreateParams as SessionCreateParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/beta/realtime/transcription-sessions.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { APIPromise } from '../../../core/api-promise';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\n\nexport class TranscriptionSessions extends APIResource {\n  /**\n   * Create an ephemeral API token for use in client-side applications with the\n   * Realtime API specifically for realtime transcriptions. Can be configured with\n   * the same session parameters as the `transcription_session.update` client event.\n   *\n   * It responds with a session object, plus a `client_secret` key which contains a\n   * usable ephemeral API token that can be used to authenticate browser clients for\n   * the Realtime API.\n   *\n   * @example\n   * ```ts\n   * const transcriptionSession =\n   *   await client.beta.realtime.transcriptionSessions.create();\n   * ```\n   */\n  create(body: TranscriptionSessionCreateParams, options?: RequestOptions): APIPromise<TranscriptionSession> {\n    return this._client.post('/realtime/transcription_sessions', {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n}\n\n/**\n * A new Realtime transcription session configuration.\n *\n * When a session is created on the server via REST API, the session object also\n * contains an ephemeral key. Default TTL for keys is 10 minutes. This property is\n * not present when a session is updated via the WebSocket API.\n */\nexport interface TranscriptionSession {\n  /**\n   * Ephemeral key returned by the API. Only present when the session is created on\n   * the server via REST API.\n   */\n  client_secret: TranscriptionSession.ClientSecret;\n\n  /**\n   * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n   */\n  input_audio_format?: string;\n\n  /**\n   * Configuration of the transcription model.\n   */\n  input_audio_transcription?: TranscriptionSession.InputAudioTranscription;\n\n  /**\n   * The set of modalities the model can respond with. To disable audio, set this to\n   * [\"text\"].\n   */\n  modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n   * means that the model will detect the start and end of speech based on audio\n   * volume and respond at the end of user speech.\n   */\n  turn_detection?: TranscriptionSession.TurnDetection;\n}\n\nexport namespace TranscriptionSession {\n  /**\n   * Ephemeral key returned by the API. Only present when the session is created on\n   * the server via REST API.\n   */\n  export interface ClientSecret {\n    /**\n     * Timestamp for when the token expires. Currently, all tokens expire after one\n     * minute.\n     */\n    expires_at: number;\n\n    /**\n     * Ephemeral key usable in client environments to authenticate connections to the\n     * Realtime API. Use this in client-side environments rather than a standard API\n     * token, which should only be used server-side.\n     */\n    value: string;\n  }\n\n  /**\n   * Configuration of the transcription model.\n   */\n  export interface InputAudioTranscription {\n    /**\n     * The language of the input audio. Supplying the input language in\n     * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n     * format will improve accuracy and latency.\n     */\n    language?: string;\n\n    /**\n     * The model to use for transcription. Can be `gpt-4o-transcribe`,\n     * `gpt-4o-mini-transcribe`, or `whisper-1`.\n     */\n    model?: 'gpt-4o-transcribe' | 'gpt-4o-mini-transcribe' | 'whisper-1';\n\n    /**\n     * An optional text to guide the model's style or continue a previous audio\n     * segment. The\n     * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)\n     * should match the audio language.\n     */\n    prompt?: string;\n  }\n\n  /**\n   * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n   * means that the model will detect the start and end of speech based on audio\n   * volume and respond at the end of user speech.\n   */\n  export interface TurnDetection {\n    /**\n     * Amount of audio to include before the VAD detected speech (in milliseconds).\n     * Defaults to 300ms.\n     */\n    prefix_padding_ms?: number;\n\n    /**\n     * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.\n     * With shorter values the model will respond more quickly, but may jump in on\n     * short pauses from the user.\n     */\n    silence_duration_ms?: number;\n\n    /**\n     * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher\n     * threshold will require louder audio to activate the model, and thus might\n     * perform better in noisy environments.\n     */\n    threshold?: number;\n\n    /**\n     * Type of turn detection, only `server_vad` is currently supported.\n     */\n    type?: string;\n  }\n}\n\nexport interface TranscriptionSessionCreateParams {\n  /**\n   * Configuration options for the generated client secret.\n   */\n  client_secret?: TranscriptionSessionCreateParams.ClientSecret;\n\n  /**\n   * The set of items to include in the transcription. Current available items are:\n   *\n   * - `item.input_audio_transcription.logprobs`\n   */\n  include?: Array<string>;\n\n  /**\n   * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n   * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n   * (mono), and little-endian byte order.\n   */\n  input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  input_audio_noise_reduction?: TranscriptionSessionCreateParams.InputAudioNoiseReduction;\n\n  /**\n   * Configuration for input audio transcription. The client can optionally set the\n   * language and prompt for transcription, these offer additional guidance to the\n   * transcription service.\n   */\n  input_audio_transcription?: TranscriptionSessionCreateParams.InputAudioTranscription;\n\n  /**\n   * The set of modalities the model can respond with. To disable audio, set this to\n   * [\"text\"].\n   */\n  modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n   * set to `null` to turn off, in which case the client must manually trigger model\n   * response. Server VAD means that the model will detect the start and end of\n   * speech based on audio volume and respond at the end of user speech. Semantic VAD\n   * is more advanced and uses a turn detection model (in conjunction with VAD) to\n   * semantically estimate whether the user has finished speaking, then dynamically\n   * sets a timeout based on this probability. For example, if user audio trails off\n   * with \"uhhm\", the model will score a low probability of turn end and wait longer\n   * for the user to continue speaking. This can be useful for more natural\n   * conversations, but may have a higher latency.\n   */\n  turn_detection?: TranscriptionSessionCreateParams.TurnDetection;\n}\n\nexport namespace TranscriptionSessionCreateParams {\n  /**\n   * Configuration options for the generated client secret.\n   */\n  export interface ClientSecret {\n    /**\n     * Configuration for the ephemeral token expiration.\n     */\n    expires_at?: ClientSecret.ExpiresAt;\n  }\n\n  export namespace ClientSecret {\n    /**\n     * Configuration for the ephemeral token expiration.\n     */\n    export interface ExpiresAt {\n      /**\n       * The anchor point for the ephemeral token expiration. Only `created_at` is\n       * currently supported.\n       */\n      anchor?: 'created_at';\n\n      /**\n       * The number of seconds from the anchor point to the expiration. Select a value\n       * between `10` and `7200`.\n       */\n      seconds?: number;\n    }\n  }\n\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  export interface InputAudioNoiseReduction {\n    /**\n     * Type of noise reduction. `near_field` is for close-talking microphones such as\n     * headphones, `far_field` is for far-field microphones such as laptop or\n     * conference room microphones.\n     */\n    type?: 'near_field' | 'far_field';\n  }\n\n  /**\n   * Configuration for input audio transcription. The client can optionally set the\n   * language and prompt for transcription, these offer additional guidance to the\n   * transcription service.\n   */\n  export interface InputAudioTranscription {\n    /**\n     * The language of the input audio. Supplying the input language in\n     * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n     * format will improve accuracy and latency.\n     */\n    language?: string;\n\n    /**\n     * The model to use for transcription, current options are `gpt-4o-transcribe`,\n     * `gpt-4o-mini-transcribe`, and `whisper-1`.\n     */\n    model?: 'gpt-4o-transcribe' | 'gpt-4o-mini-transcribe' | 'whisper-1';\n\n    /**\n     * An optional text to guide the model's style or continue a previous audio\n     * segment. For `whisper-1`, the\n     * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n     * For `gpt-4o-transcribe` models, the prompt is a free text string, for example\n     * \"expect words related to technology\".\n     */\n    prompt?: string;\n  }\n\n  /**\n   * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n   * set to `null` to turn off, in which case the client must manually trigger model\n   * response. Server VAD means that the model will detect the start and end of\n   * speech based on audio volume and respond at the end of user speech. Semantic VAD\n   * is more advanced and uses a turn detection model (in conjunction with VAD) to\n   * semantically estimate whether the user has finished speaking, then dynamically\n   * sets a timeout based on this probability. For example, if user audio trails off\n   * with \"uhhm\", the model will score a low probability of turn end and wait longer\n   * for the user to continue speaking. This can be useful for more natural\n   * conversations, but may have a higher latency.\n   */\n  export interface TurnDetection {\n    /**\n     * Whether or not to automatically generate a response when a VAD stop event\n     * occurs. Not available for transcription sessions.\n     */\n    create_response?: boolean;\n\n    /**\n     * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n     * will wait longer for the user to continue speaking, `high` will respond more\n     * quickly. `auto` is the default and is equivalent to `medium`.\n     */\n    eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n    /**\n     * Whether or not to automatically interrupt any ongoing response with output to\n     * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n     * occurs. Not available for transcription sessions.\n     */\n    interrupt_response?: boolean;\n\n    /**\n     * Used only for `server_vad` mode. Amount of audio to include before the VAD\n     * detected speech (in milliseconds). Defaults to 300ms.\n     */\n    prefix_padding_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n     * milliseconds). Defaults to 500ms. With shorter values the model will respond\n     * more quickly, but may jump in on short pauses from the user.\n     */\n    silence_duration_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n     * defaults to 0.5. A higher threshold will require louder audio to activate the\n     * model, and thus might perform better in noisy environments.\n     */\n    threshold?: number;\n\n    /**\n     * Type of turn detection.\n     */\n    type?: 'server_vad' | 'semantic_vad';\n  }\n}\n\nexport declare namespace TranscriptionSessions {\n  export {\n    type TranscriptionSession as TranscriptionSession,\n    type TranscriptionSessionCreateParams as TranscriptionSessionCreateParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/beta/realtime.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './realtime/index';\n"
  },
  {
    "path": "src/resources/beta/threads/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport {\n  Messages,\n  type Annotation,\n  type AnnotationDelta,\n  type FileCitationAnnotation,\n  type FileCitationDeltaAnnotation,\n  type FilePathAnnotation,\n  type FilePathDeltaAnnotation,\n  type ImageFile,\n  type ImageFileContentBlock,\n  type ImageFileDelta,\n  type ImageFileDeltaBlock,\n  type ImageURL,\n  type ImageURLContentBlock,\n  type ImageURLDelta,\n  type ImageURLDeltaBlock,\n  type Message,\n  type MessageContent,\n  type MessageContentDelta,\n  type MessageContentPartParam,\n  type MessageDeleted,\n  type MessageDelta,\n  type MessageDeltaEvent,\n  type RefusalContentBlock,\n  type RefusalDeltaBlock,\n  type Text,\n  type TextContentBlock,\n  type TextContentBlockParam,\n  type TextDelta,\n  type TextDeltaBlock,\n  type MessageCreateParams,\n  type MessageRetrieveParams,\n  type MessageUpdateParams,\n  type MessageListParams,\n  type MessageDeleteParams,\n  type MessagesPage,\n} from './messages';\nexport {\n  Runs,\n  type RequiredActionFunctionToolCall,\n  type Run,\n  type RunStatus,\n  type RunCreateParams,\n  type RunCreateParamsNonStreaming,\n  type RunCreateParamsStreaming,\n  type RunRetrieveParams,\n  type RunUpdateParams,\n  type RunListParams,\n  type RunCancelParams,\n  type RunSubmitToolOutputsParams,\n  type RunSubmitToolOutputsParamsNonStreaming,\n  type RunSubmitToolOutputsParamsStreaming,\n  type RunsPage,\n  type RunCreateAndPollParams,\n  type RunCreateAndStreamParams,\n  type RunStreamParams,\n  type RunSubmitToolOutputsAndPollParams,\n  type RunSubmitToolOutputsStreamParams,\n} from './runs/index';\nexport {\n  Threads,\n  type AssistantResponseFormatOption,\n  type AssistantToolChoice,\n  type AssistantToolChoiceFunction,\n  type AssistantToolChoiceOption,\n  type Thread,\n  type ThreadDeleted,\n  type ThreadCreateParams,\n  type ThreadUpdateParams,\n  type ThreadCreateAndRunParams,\n  type ThreadCreateAndRunParamsNonStreaming,\n  type ThreadCreateAndRunParamsStreaming,\n  type ThreadCreateAndRunPollParams,\n  type ThreadCreateAndRunStreamParams,\n} from './threads';\n"
  },
  {
    "path": "src/resources/beta/threads/messages.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as Shared from '../../shared';\nimport * as AssistantsAPI from '../assistants';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Build Assistants that can call models and use tools.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\nexport class Messages extends APIResource {\n  /**\n   * Create a message.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  create(threadID: string, body: MessageCreateParams, options?: RequestOptions): APIPromise<Message> {\n    return this._client.post(path`/threads/${threadID}/messages`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Retrieve a message.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  retrieve(messageID: string, params: MessageRetrieveParams, options?: RequestOptions): APIPromise<Message> {\n    const { thread_id } = params;\n    return this._client.get(path`/threads/${thread_id}/messages/${messageID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Modifies a message.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  update(messageID: string, params: MessageUpdateParams, options?: RequestOptions): APIPromise<Message> {\n    const { thread_id, ...body } = params;\n    return this._client.post(path`/threads/${thread_id}/messages/${messageID}`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Returns a list of messages for a given thread.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  list(\n    threadID: string,\n    query: MessageListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<MessagesPage, Message> {\n    return this._client.getAPIList(path`/threads/${threadID}/messages`, CursorPage<Message>, {\n      query,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Deletes a message.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  delete(\n    messageID: string,\n    params: MessageDeleteParams,\n    options?: RequestOptions,\n  ): APIPromise<MessageDeleted> {\n    const { thread_id } = params;\n    return this._client.delete(path`/threads/${thread_id}/messages/${messageID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n}\n\nexport type MessagesPage = CursorPage<Message>;\n\n/**\n * A citation within the message that points to a specific quote from a specific\n * File associated with the assistant or the message. Generated when the assistant\n * uses the \"file_search\" tool to search files.\n */\nexport type Annotation = FileCitationAnnotation | FilePathAnnotation;\n\n/**\n * A citation within the message that points to a specific quote from a specific\n * File associated with the assistant or the message. Generated when the assistant\n * uses the \"file_search\" tool to search files.\n */\nexport type AnnotationDelta = FileCitationDeltaAnnotation | FilePathDeltaAnnotation;\n\n/**\n * A citation within the message that points to a specific quote from a specific\n * File associated with the assistant or the message. Generated when the assistant\n * uses the \"file_search\" tool to search files.\n */\nexport interface FileCitationAnnotation {\n  end_index: number;\n\n  file_citation: FileCitationAnnotation.FileCitation;\n\n  start_index: number;\n\n  /**\n   * The text in the message content that needs to be replaced.\n   */\n  text: string;\n\n  /**\n   * Always `file_citation`.\n   */\n  type: 'file_citation';\n}\n\nexport namespace FileCitationAnnotation {\n  export interface FileCitation {\n    /**\n     * The ID of the specific File the citation is from.\n     */\n    file_id: string;\n  }\n}\n\n/**\n * A citation within the message that points to a specific quote from a specific\n * File associated with the assistant or the message. Generated when the assistant\n * uses the \"file_search\" tool to search files.\n */\nexport interface FileCitationDeltaAnnotation {\n  /**\n   * The index of the annotation in the text content part.\n   */\n  index: number;\n\n  /**\n   * Always `file_citation`.\n   */\n  type: 'file_citation';\n\n  end_index?: number;\n\n  file_citation?: FileCitationDeltaAnnotation.FileCitation;\n\n  start_index?: number;\n\n  /**\n   * The text in the message content that needs to be replaced.\n   */\n  text?: string;\n}\n\nexport namespace FileCitationDeltaAnnotation {\n  export interface FileCitation {\n    /**\n     * The ID of the specific File the citation is from.\n     */\n    file_id?: string;\n\n    /**\n     * The specific quote in the file.\n     */\n    quote?: string;\n  }\n}\n\n/**\n * A URL for the file that's generated when the assistant used the\n * `code_interpreter` tool to generate a file.\n */\nexport interface FilePathAnnotation {\n  end_index: number;\n\n  file_path: FilePathAnnotation.FilePath;\n\n  start_index: number;\n\n  /**\n   * The text in the message content that needs to be replaced.\n   */\n  text: string;\n\n  /**\n   * Always `file_path`.\n   */\n  type: 'file_path';\n}\n\nexport namespace FilePathAnnotation {\n  export interface FilePath {\n    /**\n     * The ID of the file that was generated.\n     */\n    file_id: string;\n  }\n}\n\n/**\n * A URL for the file that's generated when the assistant used the\n * `code_interpreter` tool to generate a file.\n */\nexport interface FilePathDeltaAnnotation {\n  /**\n   * The index of the annotation in the text content part.\n   */\n  index: number;\n\n  /**\n   * Always `file_path`.\n   */\n  type: 'file_path';\n\n  end_index?: number;\n\n  file_path?: FilePathDeltaAnnotation.FilePath;\n\n  start_index?: number;\n\n  /**\n   * The text in the message content that needs to be replaced.\n   */\n  text?: string;\n}\n\nexport namespace FilePathDeltaAnnotation {\n  export interface FilePath {\n    /**\n     * The ID of the file that was generated.\n     */\n    file_id?: string;\n  }\n}\n\nexport interface ImageFile {\n  /**\n   * The [File](https://platform.openai.com/docs/api-reference/files) ID of the image\n   * in the message content. Set `purpose=\"vision\"` when uploading the File if you\n   * need to later display the file content.\n   */\n  file_id: string;\n\n  /**\n   * Specifies the detail level of the image if specified by the user. `low` uses\n   * fewer tokens, you can opt in to high resolution using `high`.\n   */\n  detail?: 'auto' | 'low' | 'high';\n}\n\n/**\n * References an image [File](https://platform.openai.com/docs/api-reference/files)\n * in the content of a message.\n */\nexport interface ImageFileContentBlock {\n  image_file: ImageFile;\n\n  /**\n   * Always `image_file`.\n   */\n  type: 'image_file';\n}\n\nexport interface ImageFileDelta {\n  /**\n   * Specifies the detail level of the image if specified by the user. `low` uses\n   * fewer tokens, you can opt in to high resolution using `high`.\n   */\n  detail?: 'auto' | 'low' | 'high';\n\n  /**\n   * The [File](https://platform.openai.com/docs/api-reference/files) ID of the image\n   * in the message content. Set `purpose=\"vision\"` when uploading the File if you\n   * need to later display the file content.\n   */\n  file_id?: string;\n}\n\n/**\n * References an image [File](https://platform.openai.com/docs/api-reference/files)\n * in the content of a message.\n */\nexport interface ImageFileDeltaBlock {\n  /**\n   * The index of the content part in the message.\n   */\n  index: number;\n\n  /**\n   * Always `image_file`.\n   */\n  type: 'image_file';\n\n  image_file?: ImageFileDelta;\n}\n\nexport interface ImageURL {\n  /**\n   * The external URL of the image, must be a supported image types: jpeg, jpg, png,\n   * gif, webp.\n   */\n  url: string;\n\n  /**\n   * Specifies the detail level of the image. `low` uses fewer tokens, you can opt in\n   * to high resolution using `high`. Default value is `auto`\n   */\n  detail?: 'auto' | 'low' | 'high';\n}\n\n/**\n * References an image URL in the content of a message.\n */\nexport interface ImageURLContentBlock {\n  image_url: ImageURL;\n\n  /**\n   * The type of the content part.\n   */\n  type: 'image_url';\n}\n\nexport interface ImageURLDelta {\n  /**\n   * Specifies the detail level of the image. `low` uses fewer tokens, you can opt in\n   * to high resolution using `high`.\n   */\n  detail?: 'auto' | 'low' | 'high';\n\n  /**\n   * The URL of the image, must be a supported image types: jpeg, jpg, png, gif,\n   * webp.\n   */\n  url?: string;\n}\n\n/**\n * References an image URL in the content of a message.\n */\nexport interface ImageURLDeltaBlock {\n  /**\n   * The index of the content part in the message.\n   */\n  index: number;\n\n  /**\n   * Always `image_url`.\n   */\n  type: 'image_url';\n\n  image_url?: ImageURLDelta;\n}\n\n/**\n * Represents a message within a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\nexport interface Message {\n  /**\n   * The identifier, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * If applicable, the ID of the\n   * [assistant](https://platform.openai.com/docs/api-reference/assistants) that\n   * authored this message.\n   */\n  assistant_id: string | null;\n\n  /**\n   * A list of files attached to the message, and the tools they were added to.\n   */\n  attachments: Array<Message.Attachment> | null;\n\n  /**\n   * The Unix timestamp (in seconds) for when the message was completed.\n   */\n  completed_at: number | null;\n\n  /**\n   * The content of the message in array of text and/or images.\n   */\n  content: Array<MessageContent>;\n\n  /**\n   * The Unix timestamp (in seconds) for when the message was created.\n   */\n  created_at: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the message was marked as incomplete.\n   */\n  incomplete_at: number | null;\n\n  /**\n   * On an incomplete message, details about why the message is incomplete.\n   */\n  incomplete_details: Message.IncompleteDetails | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The object type, which is always `thread.message`.\n   */\n  object: 'thread.message';\n\n  /**\n   * The entity that produced the message. One of `user` or `assistant`.\n   */\n  role: 'user' | 'assistant';\n\n  /**\n   * The ID of the [run](https://platform.openai.com/docs/api-reference/runs)\n   * associated with the creation of this message. Value is `null` when messages are\n   * created manually using the create message or create thread endpoints.\n   */\n  run_id: string | null;\n\n  /**\n   * The status of the message, which can be either `in_progress`, `incomplete`, or\n   * `completed`.\n   */\n  status: 'in_progress' | 'incomplete' | 'completed';\n\n  /**\n   * The [thread](https://platform.openai.com/docs/api-reference/threads) ID that\n   * this message belongs to.\n   */\n  thread_id: string;\n}\n\nexport namespace Message {\n  export interface Attachment {\n    /**\n     * The ID of the file to attach to the message.\n     */\n    file_id?: string;\n\n    /**\n     * The tools to add this file to.\n     */\n    tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.AssistantToolsFileSearchTypeOnly>;\n  }\n\n  export namespace Attachment {\n    export interface AssistantToolsFileSearchTypeOnly {\n      /**\n       * The type of tool being defined: `file_search`\n       */\n      type: 'file_search';\n    }\n  }\n\n  /**\n   * On an incomplete message, details about why the message is incomplete.\n   */\n  export interface IncompleteDetails {\n    /**\n     * The reason the message is incomplete.\n     */\n    reason: 'content_filter' | 'max_tokens' | 'run_cancelled' | 'run_expired' | 'run_failed';\n  }\n}\n\n/**\n * References an image [File](https://platform.openai.com/docs/api-reference/files)\n * in the content of a message.\n */\nexport type MessageContent =\n  | ImageFileContentBlock\n  | ImageURLContentBlock\n  | TextContentBlock\n  | RefusalContentBlock;\n\n/**\n * References an image [File](https://platform.openai.com/docs/api-reference/files)\n * in the content of a message.\n */\nexport type MessageContentDelta =\n  | ImageFileDeltaBlock\n  | TextDeltaBlock\n  | RefusalDeltaBlock\n  | ImageURLDeltaBlock;\n\n/**\n * References an image [File](https://platform.openai.com/docs/api-reference/files)\n * in the content of a message.\n */\nexport type MessageContentPartParam = ImageFileContentBlock | ImageURLContentBlock | TextContentBlockParam;\n\nexport interface MessageDeleted {\n  id: string;\n\n  deleted: boolean;\n\n  object: 'thread.message.deleted';\n}\n\n/**\n * The delta containing the fields that have changed on the Message.\n */\nexport interface MessageDelta {\n  /**\n   * The content of the message in array of text and/or images.\n   */\n  content?: Array<MessageContentDelta>;\n\n  /**\n   * The entity that produced the message. One of `user` or `assistant`.\n   */\n  role?: 'user' | 'assistant';\n}\n\n/**\n * Represents a message delta i.e. any changed fields on a message during\n * streaming.\n */\nexport interface MessageDeltaEvent {\n  /**\n   * The identifier of the message, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The delta containing the fields that have changed on the Message.\n   */\n  delta: MessageDelta;\n\n  /**\n   * The object type, which is always `thread.message.delta`.\n   */\n  object: 'thread.message.delta';\n}\n\n/**\n * The refusal content generated by the assistant.\n */\nexport interface RefusalContentBlock {\n  refusal: string;\n\n  /**\n   * Always `refusal`.\n   */\n  type: 'refusal';\n}\n\n/**\n * The refusal content that is part of a message.\n */\nexport interface RefusalDeltaBlock {\n  /**\n   * The index of the refusal part in the message.\n   */\n  index: number;\n\n  /**\n   * Always `refusal`.\n   */\n  type: 'refusal';\n\n  refusal?: string;\n}\n\nexport interface Text {\n  annotations: Array<Annotation>;\n\n  /**\n   * The data that makes up the text.\n   */\n  value: string;\n}\n\n/**\n * The text content that is part of a message.\n */\nexport interface TextContentBlock {\n  text: Text;\n\n  /**\n   * Always `text`.\n   */\n  type: 'text';\n}\n\n/**\n * The text content that is part of a message.\n */\nexport interface TextContentBlockParam {\n  /**\n   * Text content to be sent to the model\n   */\n  text: string;\n\n  /**\n   * Always `text`.\n   */\n  type: 'text';\n}\n\nexport interface TextDelta {\n  annotations?: Array<AnnotationDelta>;\n\n  /**\n   * The data that makes up the text.\n   */\n  value?: string;\n}\n\n/**\n * The text content that is part of a message.\n */\nexport interface TextDeltaBlock {\n  /**\n   * The index of the content part in the message.\n   */\n  index: number;\n\n  /**\n   * Always `text`.\n   */\n  type: 'text';\n\n  text?: TextDelta;\n}\n\nexport interface MessageCreateParams {\n  /**\n   * The text contents of the message.\n   */\n  content: string | Array<MessageContentPartParam>;\n\n  /**\n   * The role of the entity that is creating the message. Allowed values include:\n   *\n   * - `user`: Indicates the message is sent by an actual user and should be used in\n   *   most cases to represent user-generated messages.\n   * - `assistant`: Indicates the message is generated by the assistant. Use this\n   *   value to insert messages from the assistant into the conversation.\n   */\n  role: 'user' | 'assistant';\n\n  /**\n   * A list of files attached to the message, and the tools they should be added to.\n   */\n  attachments?: Array<MessageCreateParams.Attachment> | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n}\n\nexport namespace MessageCreateParams {\n  export interface Attachment {\n    /**\n     * The ID of the file to attach to the message.\n     */\n    file_id?: string;\n\n    /**\n     * The tools to add this file to.\n     */\n    tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;\n  }\n\n  export namespace Attachment {\n    export interface FileSearch {\n      /**\n       * The type of tool being defined: `file_search`\n       */\n      type: 'file_search';\n    }\n  }\n}\n\nexport interface MessageRetrieveParams {\n  /**\n   * The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)\n   * to which this message belongs.\n   */\n  thread_id: string;\n}\n\nexport interface MessageUpdateParams {\n  /**\n   * Path param: The ID of the thread to which this message belongs.\n   */\n  thread_id: string;\n\n  /**\n   * Body param: Set of 16 key-value pairs that can be attached to an object. This\n   * can be useful for storing additional information about the object in a\n   * structured format, and querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n}\n\nexport interface MessageListParams extends CursorPageParams {\n  /**\n   * A cursor for use in pagination. `before` is an object ID that defines your place\n   * in the list. For instance, if you make a list request and receive 100 objects,\n   * starting with obj_foo, your subsequent call can include before=obj_foo in order\n   * to fetch the previous page of the list.\n   */\n  before?: string;\n\n  /**\n   * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n   * order and `desc` for descending order.\n   */\n  order?: 'asc' | 'desc';\n\n  /**\n   * Filter messages by the run ID that generated them.\n   */\n  run_id?: string;\n}\n\nexport interface MessageDeleteParams {\n  /**\n   * The ID of the thread to which this message belongs.\n   */\n  thread_id: string;\n}\n\nexport declare namespace Messages {\n  export {\n    type Annotation as Annotation,\n    type AnnotationDelta as AnnotationDelta,\n    type FileCitationAnnotation as FileCitationAnnotation,\n    type FileCitationDeltaAnnotation as FileCitationDeltaAnnotation,\n    type FilePathAnnotation as FilePathAnnotation,\n    type FilePathDeltaAnnotation as FilePathDeltaAnnotation,\n    type ImageFile as ImageFile,\n    type ImageFileContentBlock as ImageFileContentBlock,\n    type ImageFileDelta as ImageFileDelta,\n    type ImageFileDeltaBlock as ImageFileDeltaBlock,\n    type ImageURL as ImageURL,\n    type ImageURLContentBlock as ImageURLContentBlock,\n    type ImageURLDelta as ImageURLDelta,\n    type ImageURLDeltaBlock as ImageURLDeltaBlock,\n    type Message as Message,\n    type MessageContent as MessageContent,\n    type MessageContentDelta as MessageContentDelta,\n    type MessageContentPartParam as MessageContentPartParam,\n    type MessageDeleted as MessageDeleted,\n    type MessageDelta as MessageDelta,\n    type MessageDeltaEvent as MessageDeltaEvent,\n    type RefusalContentBlock as RefusalContentBlock,\n    type RefusalDeltaBlock as RefusalDeltaBlock,\n    type Text as Text,\n    type TextContentBlock as TextContentBlock,\n    type TextContentBlockParam as TextContentBlockParam,\n    type TextDelta as TextDelta,\n    type TextDeltaBlock as TextDeltaBlock,\n    type MessagesPage as MessagesPage,\n    type MessageCreateParams as MessageCreateParams,\n    type MessageRetrieveParams as MessageRetrieveParams,\n    type MessageUpdateParams as MessageUpdateParams,\n    type MessageListParams as MessageListParams,\n    type MessageDeleteParams as MessageDeleteParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/beta/threads/runs/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport {\n  Runs,\n  type RequiredActionFunctionToolCall,\n  type Run,\n  type RunStatus,\n  type RunCreateParams,\n  type RunCreateParamsNonStreaming,\n  type RunCreateParamsStreaming,\n  type RunRetrieveParams,\n  type RunUpdateParams,\n  type RunListParams,\n  type RunCancelParams,\n  type RunSubmitToolOutputsParams,\n  type RunSubmitToolOutputsParamsNonStreaming,\n  type RunSubmitToolOutputsParamsStreaming,\n  type RunsPage,\n  type RunCreateAndPollParams,\n  type RunCreateAndStreamParams,\n  type RunStreamParams,\n  type RunSubmitToolOutputsAndPollParams,\n  type RunSubmitToolOutputsStreamParams,\n} from './runs';\nexport {\n  Steps,\n  type CodeInterpreterLogs,\n  type CodeInterpreterOutputImage,\n  type CodeInterpreterToolCall,\n  type CodeInterpreterToolCallDelta,\n  type FileSearchToolCall,\n  type FileSearchToolCallDelta,\n  type FunctionToolCall,\n  type FunctionToolCallDelta,\n  type MessageCreationStepDetails,\n  type RunStep,\n  type RunStepInclude,\n  type RunStepDelta,\n  type RunStepDeltaEvent,\n  type RunStepDeltaMessageDelta,\n  type ToolCall,\n  type ToolCallDelta,\n  type ToolCallDeltaObject,\n  type ToolCallsStepDetails,\n  type StepRetrieveParams,\n  type StepListParams,\n  type RunStepsPage,\n} from './steps';\n"
  },
  {
    "path": "src/resources/beta/threads/runs/runs.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../../core/resource';\nimport * as RunsAPI from './runs';\nimport * as Shared from '../../../shared';\nimport * as AssistantsAPI from '../../assistants';\nimport * as MessagesAPI from '../messages';\nimport * as ThreadsAPI from '../threads';\nimport * as StepsAPI from './steps';\nimport {\n  CodeInterpreterLogs,\n  CodeInterpreterOutputImage,\n  CodeInterpreterToolCall,\n  CodeInterpreterToolCallDelta,\n  FileSearchToolCall,\n  FileSearchToolCallDelta,\n  FunctionToolCall,\n  FunctionToolCallDelta,\n  MessageCreationStepDetails,\n  RunStep,\n  RunStepDelta,\n  RunStepDeltaEvent,\n  RunStepDeltaMessageDelta,\n  RunStepInclude,\n  RunStepsPage,\n  StepListParams,\n  StepRetrieveParams,\n  Steps,\n  ToolCall,\n  ToolCallDelta,\n  ToolCallDeltaObject,\n  ToolCallsStepDetails,\n} from './steps';\nimport { APIPromise } from '../../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../../core/pagination';\nimport { Stream } from '../../../../core/streaming';\nimport { buildHeaders } from '../../../../internal/headers';\nimport { RequestOptions } from '../../../../internal/request-options';\nimport { AssistantStream, RunCreateParamsBaseStream } from '../../../../lib/AssistantStream';\nimport { sleep } from '../../../../internal/utils/sleep';\nimport { RunSubmitToolOutputsParamsStream } from '../../../../lib/AssistantStream';\nimport { path } from '../../../../internal/utils/path';\n\n/**\n * Build Assistants that can call models and use tools.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\nexport class Runs extends APIResource {\n  steps: StepsAPI.Steps = new StepsAPI.Steps(this._client);\n\n  /**\n   * Create a run.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  create(threadID: string, params: RunCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Run>;\n  create(\n    threadID: string,\n    params: RunCreateParamsStreaming,\n    options?: RequestOptions,\n  ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n  create(\n    threadID: string,\n    params: RunCreateParamsBase,\n    options?: RequestOptions,\n  ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent> | Run>;\n  create(\n    threadID: string,\n    params: RunCreateParams,\n    options?: RequestOptions,\n  ): APIPromise<Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>> {\n    const { include, ...body } = params;\n    return this._client.post(path`/threads/${threadID}/runs`, {\n      query: { include },\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n      stream: params.stream ?? false,\n      __synthesizeEventData: true,\n    }) as APIPromise<Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n  }\n\n  /**\n   * Retrieves a run.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  retrieve(runID: string, params: RunRetrieveParams, options?: RequestOptions): APIPromise<Run> {\n    const { thread_id } = params;\n    return this._client.get(path`/threads/${thread_id}/runs/${runID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Modifies a run.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  update(runID: string, params: RunUpdateParams, options?: RequestOptions): APIPromise<Run> {\n    const { thread_id, ...body } = params;\n    return this._client.post(path`/threads/${thread_id}/runs/${runID}`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Returns a list of runs belonging to a thread.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  list(\n    threadID: string,\n    query: RunListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<RunsPage, Run> {\n    return this._client.getAPIList(path`/threads/${threadID}/runs`, CursorPage<Run>, {\n      query,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Cancels a run that is `in_progress`.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  cancel(runID: string, params: RunCancelParams, options?: RequestOptions): APIPromise<Run> {\n    const { thread_id } = params;\n    return this._client.post(path`/threads/${thread_id}/runs/${runID}/cancel`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * A helper to create a run an poll for a terminal state. More information on Run\n   * lifecycles can be found here:\n   * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps\n   */\n  async createAndPoll(\n    threadId: string,\n    body: RunCreateParamsNonStreaming,\n    options?: RequestOptions & { pollIntervalMs?: number },\n  ): Promise<Run> {\n    const run = await this.create(threadId, body, options);\n    return await this.poll(run.id, { thread_id: threadId }, options);\n  }\n\n  /**\n   * Create a Run stream\n   *\n   * @deprecated use `stream` instead\n   */\n  createAndStream(\n    threadId: string,\n    body: RunCreateParamsBaseStream,\n    options?: RequestOptions,\n  ): AssistantStream {\n    return AssistantStream.createAssistantStream(threadId, this._client.beta.threads.runs, body, options);\n  }\n\n  /**\n   * A helper to poll a run status until it reaches a terminal state. More\n   * information on Run lifecycles can be found here:\n   * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps\n   */\n  async poll(\n    runId: string,\n    params: RunRetrieveParams,\n    options?: RequestOptions & { pollIntervalMs?: number },\n  ): Promise<Run> {\n    const headers = buildHeaders([\n      options?.headers,\n      {\n        'X-Stainless-Poll-Helper': 'true',\n        'X-Stainless-Custom-Poll-Interval': options?.pollIntervalMs?.toString() ?? undefined,\n      },\n    ]);\n\n    while (true) {\n      const { data: run, response } = await this.retrieve(runId, params, {\n        ...options,\n        headers: { ...options?.headers, ...headers },\n      }).withResponse();\n\n      switch (run.status) {\n        //If we are in any sort of intermediate state we poll\n        case 'queued':\n        case 'in_progress':\n        case 'cancelling':\n          let sleepInterval = 5000;\n\n          if (options?.pollIntervalMs) {\n            sleepInterval = options.pollIntervalMs;\n          } else {\n            const headerInterval = response.headers.get('openai-poll-after-ms');\n            if (headerInterval) {\n              const headerIntervalMs = parseInt(headerInterval);\n              if (!isNaN(headerIntervalMs)) {\n                sleepInterval = headerIntervalMs;\n              }\n            }\n          }\n          await sleep(sleepInterval);\n          break;\n        //We return the run in any terminal state.\n        case 'requires_action':\n        case 'incomplete':\n        case 'cancelled':\n        case 'completed':\n        case 'failed':\n        case 'expired':\n          return run;\n      }\n    }\n  }\n\n  /**\n   * Create a Run stream\n   */\n  stream(threadId: string, body: RunCreateParamsBaseStream, options?: RequestOptions): AssistantStream {\n    return AssistantStream.createAssistantStream(threadId, this._client.beta.threads.runs, body, options);\n  }\n\n  /**\n   * When a run has the `status: \"requires_action\"` and `required_action.type` is\n   * `submit_tool_outputs`, this endpoint can be used to submit the outputs from the\n   * tool calls once they're all completed. All outputs must be submitted in a single\n   * request.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  submitToolOutputs(\n    runID: string,\n    params: RunSubmitToolOutputsParamsNonStreaming,\n    options?: RequestOptions,\n  ): APIPromise<Run>;\n  submitToolOutputs(\n    runID: string,\n    params: RunSubmitToolOutputsParamsStreaming,\n    options?: RequestOptions,\n  ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n  submitToolOutputs(\n    runID: string,\n    params: RunSubmitToolOutputsParamsBase,\n    options?: RequestOptions,\n  ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent> | Run>;\n  submitToolOutputs(\n    runID: string,\n    params: RunSubmitToolOutputsParams,\n    options?: RequestOptions,\n  ): APIPromise<Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>> {\n    const { thread_id, ...body } = params;\n    return this._client.post(path`/threads/${thread_id}/runs/${runID}/submit_tool_outputs`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n      stream: params.stream ?? false,\n      __synthesizeEventData: true,\n    }) as APIPromise<Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n  }\n\n  /**\n   * A helper to submit a tool output to a run and poll for a terminal run state.\n   * More information on Run lifecycles can be found here:\n   * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps\n   */\n  async submitToolOutputsAndPoll(\n    runId: string,\n    params: RunSubmitToolOutputsParamsNonStreaming,\n    options?: RequestOptions & { pollIntervalMs?: number },\n  ): Promise<Run> {\n    const run = await this.submitToolOutputs(runId, params, options);\n    return await this.poll(run.id, params, options);\n  }\n\n  /**\n   * Submit the tool outputs from a previous run and stream the run to a terminal\n   * state. More information on Run lifecycles can be found here:\n   * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps\n   */\n  submitToolOutputsStream(\n    runId: string,\n    params: RunSubmitToolOutputsParamsStream,\n    options?: RequestOptions,\n  ): AssistantStream {\n    return AssistantStream.createToolAssistantStream(runId, this._client.beta.threads.runs, params, options);\n  }\n}\n\nexport type RunsPage = CursorPage<Run>;\n\n/**\n * Tool call objects\n */\nexport interface RequiredActionFunctionToolCall {\n  /**\n   * The ID of the tool call. This ID must be referenced when you submit the tool\n   * outputs in using the\n   * [Submit tool outputs to run](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)\n   * endpoint.\n   */\n  id: string;\n\n  /**\n   * The function definition.\n   */\n  function: RequiredActionFunctionToolCall.Function;\n\n  /**\n   * The type of tool call the output is required for. For now, this is always\n   * `function`.\n   */\n  type: 'function';\n}\n\nexport namespace RequiredActionFunctionToolCall {\n  /**\n   * The function definition.\n   */\n  export interface Function {\n    /**\n     * The arguments that the model expects you to pass to the function.\n     */\n    arguments: string;\n\n    /**\n     * The name of the function.\n     */\n    name: string;\n  }\n}\n\n/**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\nexport interface Run {\n  /**\n   * The identifier, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The ID of the\n   * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for\n   * execution of this run.\n   */\n  assistant_id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run was cancelled.\n   */\n  cancelled_at: number | null;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run was completed.\n   */\n  completed_at: number | null;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run was created.\n   */\n  created_at: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run will expire.\n   */\n  expires_at: number | null;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run failed.\n   */\n  failed_at: number | null;\n\n  /**\n   * Details on why the run is incomplete. Will be `null` if the run is not\n   * incomplete.\n   */\n  incomplete_details: Run.IncompleteDetails | null;\n\n  /**\n   * The instructions that the\n   * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for\n   * this run.\n   */\n  instructions: string;\n\n  /**\n   * The last error associated with this run. Will be `null` if there are no errors.\n   */\n  last_error: Run.LastError | null;\n\n  /**\n   * The maximum number of completion tokens specified to have been used over the\n   * course of the run.\n   */\n  max_completion_tokens: number | null;\n\n  /**\n   * The maximum number of prompt tokens specified to have been used over the course\n   * of the run.\n   */\n  max_prompt_tokens: number | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The model that the\n   * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for\n   * this run.\n   */\n  model: string;\n\n  /**\n   * The object type, which is always `thread.run`.\n   */\n  object: 'thread.run';\n\n  /**\n   * Whether to enable\n   * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)\n   * during tool use.\n   */\n  parallel_tool_calls: boolean;\n\n  /**\n   * Details on the action required to continue the run. Will be `null` if no action\n   * is required.\n   */\n  required_action: Run.RequiredAction | null;\n\n  /**\n   * Specifies the format that the model must output. Compatible with\n   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n   * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n   * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n   *\n   * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n   * Outputs which ensures the model will match your supplied JSON schema. Learn more\n   * in the\n   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n   *\n   * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n   * message the model generates is valid JSON.\n   *\n   * **Important:** when using JSON mode, you **must** also instruct the model to\n   * produce JSON yourself via a system or user message. Without this, the model may\n   * generate an unending stream of whitespace until the generation reaches the token\n   * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n   * the message content may be partially cut off if `finish_reason=\"length\"`, which\n   * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n   * max context length.\n   */\n  response_format: ThreadsAPI.AssistantResponseFormatOption | null;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run was started.\n   */\n  started_at: number | null;\n\n  /**\n   * The status of the run, which can be either `queued`, `in_progress`,\n   * `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`,\n   * `incomplete`, or `expired`.\n   */\n  status: RunStatus;\n\n  /**\n   * The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)\n   * that was executed on as a part of this run.\n   */\n  thread_id: string;\n\n  /**\n   * Controls which (if any) tool is called by the model. `none` means the model will\n   * not call any tools and instead generates a message. `auto` is the default value\n   * and means the model can pick between generating a message or calling one or more\n   * tools. `required` means the model must call one or more tools before responding\n   * to the user. Specifying a particular tool like `{\"type\": \"file_search\"}` or\n   * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n   * call that tool.\n   */\n  tool_choice: ThreadsAPI.AssistantToolChoiceOption | null;\n\n  /**\n   * The list of tools that the\n   * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for\n   * this run.\n   */\n  tools: Array<AssistantsAPI.AssistantTool>;\n\n  /**\n   * Controls for how a thread will be truncated prior to the run. Use this to\n   * control the initial context window of the run.\n   */\n  truncation_strategy: Run.TruncationStrategy | null;\n\n  /**\n   * Usage statistics related to the run. This value will be `null` if the run is not\n   * in a terminal state (i.e. `in_progress`, `queued`, etc.).\n   */\n  usage: Run.Usage | null;\n\n  /**\n   * The sampling temperature used for this run. If not set, defaults to 1.\n   */\n  temperature?: number | null;\n\n  /**\n   * The nucleus sampling value used for this run. If not set, defaults to 1.\n   */\n  top_p?: number | null;\n}\n\nexport namespace Run {\n  /**\n   * Details on why the run is incomplete. Will be `null` if the run is not\n   * incomplete.\n   */\n  export interface IncompleteDetails {\n    /**\n     * The reason why the run is incomplete. This will point to which specific token\n     * limit was reached over the course of the run.\n     */\n    reason?: 'max_completion_tokens' | 'max_prompt_tokens';\n  }\n\n  /**\n   * The last error associated with this run. Will be `null` if there are no errors.\n   */\n  export interface LastError {\n    /**\n     * One of `server_error`, `rate_limit_exceeded`, or `invalid_prompt`.\n     */\n    code: 'server_error' | 'rate_limit_exceeded' | 'invalid_prompt';\n\n    /**\n     * A human-readable description of the error.\n     */\n    message: string;\n  }\n\n  /**\n   * Details on the action required to continue the run. Will be `null` if no action\n   * is required.\n   */\n  export interface RequiredAction {\n    /**\n     * Details on the tool outputs needed for this run to continue.\n     */\n    submit_tool_outputs: RequiredAction.SubmitToolOutputs;\n\n    /**\n     * For now, this is always `submit_tool_outputs`.\n     */\n    type: 'submit_tool_outputs';\n  }\n\n  export namespace RequiredAction {\n    /**\n     * Details on the tool outputs needed for this run to continue.\n     */\n    export interface SubmitToolOutputs {\n      /**\n       * A list of the relevant tool calls.\n       */\n      tool_calls: Array<RunsAPI.RequiredActionFunctionToolCall>;\n    }\n  }\n\n  /**\n   * Controls for how a thread will be truncated prior to the run. Use this to\n   * control the initial context window of the run.\n   */\n  export interface TruncationStrategy {\n    /**\n     * The truncation strategy to use for the thread. The default is `auto`. If set to\n     * `last_messages`, the thread will be truncated to the n most recent messages in\n     * the thread. When set to `auto`, messages in the middle of the thread will be\n     * dropped to fit the context length of the model, `max_prompt_tokens`.\n     */\n    type: 'auto' | 'last_messages';\n\n    /**\n     * The number of most recent messages from the thread when constructing the context\n     * for the run.\n     */\n    last_messages?: number | null;\n  }\n\n  /**\n   * Usage statistics related to the run. This value will be `null` if the run is not\n   * in a terminal state (i.e. `in_progress`, `queued`, etc.).\n   */\n  export interface Usage {\n    /**\n     * Number of completion tokens used over the course of the run.\n     */\n    completion_tokens: number;\n\n    /**\n     * Number of prompt tokens used over the course of the run.\n     */\n    prompt_tokens: number;\n\n    /**\n     * Total number of tokens used (prompt + completion).\n     */\n    total_tokens: number;\n  }\n}\n\n/**\n * The status of the run, which can be either `queued`, `in_progress`,\n * `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`,\n * `incomplete`, or `expired`.\n */\nexport type RunStatus =\n  | 'queued'\n  | 'in_progress'\n  | 'requires_action'\n  | 'cancelling'\n  | 'cancelled'\n  | 'failed'\n  | 'completed'\n  | 'incomplete'\n  | 'expired';\n\nexport type RunCreateParams = RunCreateParamsNonStreaming | RunCreateParamsStreaming;\n\nexport interface RunCreateParamsBase {\n  /**\n   * Body param: The ID of the\n   * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to\n   * execute this run.\n   */\n  assistant_id: string;\n\n  /**\n   * Query param: A list of additional fields to include in the response. Currently\n   * the only supported value is\n   * `step_details.tool_calls[*].file_search.results[*].content` to fetch the file\n   * search result content.\n   *\n   * See the\n   * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n   * for more information.\n   */\n  include?: Array<StepsAPI.RunStepInclude>;\n\n  /**\n   * Body param: Appends additional instructions at the end of the instructions for\n   * the run. This is useful for modifying the behavior on a per-run basis without\n   * overriding other instructions.\n   */\n  additional_instructions?: string | null;\n\n  /**\n   * Body param: Adds additional messages to the thread before creating the run.\n   */\n  additional_messages?: Array<RunCreateParams.AdditionalMessage> | null;\n\n  /**\n   * Body param: Overrides the\n   * [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)\n   * of the assistant. This is useful for modifying the behavior on a per-run basis.\n   */\n  instructions?: string | null;\n\n  /**\n   * Body param: The maximum number of completion tokens that may be used over the\n   * course of the run. The run will make a best effort to use only the number of\n   * completion tokens specified, across multiple turns of the run. If the run\n   * exceeds the number of completion tokens specified, the run will end with status\n   * `incomplete`. See `incomplete_details` for more info.\n   */\n  max_completion_tokens?: number | null;\n\n  /**\n   * Body param: The maximum number of prompt tokens that may be used over the course\n   * of the run. The run will make a best effort to use only the number of prompt\n   * tokens specified, across multiple turns of the run. If the run exceeds the\n   * number of prompt tokens specified, the run will end with status `incomplete`.\n   * See `incomplete_details` for more info.\n   */\n  max_prompt_tokens?: number | null;\n\n  /**\n   * Body param: Set of 16 key-value pairs that can be attached to an object. This\n   * can be useful for storing additional information about the object in a\n   * structured format, and querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * Body param: The ID of the\n   * [Model](https://platform.openai.com/docs/api-reference/models) to be used to\n   * execute this run. If a value is provided here, it will override the model\n   * associated with the assistant. If not, the model associated with the assistant\n   * will be used.\n   */\n  model?: (string & {}) | Shared.ChatModel | null;\n\n  /**\n   * Body param: Whether to enable\n   * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)\n   * during tool use.\n   */\n  parallel_tool_calls?: boolean;\n\n  /**\n   * Body param: Constrains effort on reasoning for\n   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n   * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n   * Reducing reasoning effort can result in faster responses and fewer tokens used\n   * on reasoning in a response.\n   *\n   * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n   *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n   *   calls are supported for all reasoning values in gpt-5.1.\n   * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n   *   support `none`.\n   * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n   * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n   */\n  reasoning_effort?: Shared.ReasoningEffort | null;\n\n  /**\n   * Body param: Specifies the format that the model must output. Compatible with\n   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n   * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n   * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n   *\n   * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n   * Outputs which ensures the model will match your supplied JSON schema. Learn more\n   * in the\n   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n   *\n   * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n   * message the model generates is valid JSON.\n   *\n   * **Important:** when using JSON mode, you **must** also instruct the model to\n   * produce JSON yourself via a system or user message. Without this, the model may\n   * generate an unending stream of whitespace until the generation reaches the token\n   * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n   * the message content may be partially cut off if `finish_reason=\"length\"`, which\n   * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n   * max context length.\n   */\n  response_format?: ThreadsAPI.AssistantResponseFormatOption | null;\n\n  /**\n   * Body param: If `true`, returns a stream of events that happen during the Run as\n   * server-sent events, terminating when the Run enters a terminal state with a\n   * `data: [DONE]` message.\n   */\n  stream?: boolean | null;\n\n  /**\n   * Body param: What sampling temperature to use, between 0 and 2. Higher values\n   * like 0.8 will make the output more random, while lower values like 0.2 will make\n   * it more focused and deterministic.\n   */\n  temperature?: number | null;\n\n  /**\n   * Body param: Controls which (if any) tool is called by the model. `none` means\n   * the model will not call any tools and instead generates a message. `auto` is the\n   * default value and means the model can pick between generating a message or\n   * calling one or more tools. `required` means the model must call one or more\n   * tools before responding to the user. Specifying a particular tool like\n   * `{\"type\": \"file_search\"}` or\n   * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n   * call that tool.\n   */\n  tool_choice?: ThreadsAPI.AssistantToolChoiceOption | null;\n\n  /**\n   * Body param: Override the tools the assistant can use for this run. This is\n   * useful for modifying the behavior on a per-run basis.\n   */\n  tools?: Array<AssistantsAPI.AssistantTool> | null;\n\n  /**\n   * Body param: An alternative to sampling with temperature, called nucleus\n   * sampling, where the model considers the results of the tokens with top_p\n   * probability mass. So 0.1 means only the tokens comprising the top 10%\n   * probability mass are considered.\n   *\n   * We generally recommend altering this or temperature but not both.\n   */\n  top_p?: number | null;\n\n  /**\n   * Body param: Controls for how a thread will be truncated prior to the run. Use\n   * this to control the initial context window of the run.\n   */\n  truncation_strategy?: RunCreateParams.TruncationStrategy | null;\n}\n\nexport namespace RunCreateParams {\n  export interface AdditionalMessage {\n    /**\n     * The text contents of the message.\n     */\n    content: string | Array<MessagesAPI.MessageContentPartParam>;\n\n    /**\n     * The role of the entity that is creating the message. Allowed values include:\n     *\n     * - `user`: Indicates the message is sent by an actual user and should be used in\n     *   most cases to represent user-generated messages.\n     * - `assistant`: Indicates the message is generated by the assistant. Use this\n     *   value to insert messages from the assistant into the conversation.\n     */\n    role: 'user' | 'assistant';\n\n    /**\n     * A list of files attached to the message, and the tools they should be added to.\n     */\n    attachments?: Array<AdditionalMessage.Attachment> | null;\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard.\n     *\n     * Keys are strings with a maximum length of 64 characters. Values are strings with\n     * a maximum length of 512 characters.\n     */\n    metadata?: Shared.Metadata | null;\n  }\n\n  export namespace AdditionalMessage {\n    export interface Attachment {\n      /**\n       * The ID of the file to attach to the message.\n       */\n      file_id?: string;\n\n      /**\n       * The tools to add this file to.\n       */\n      tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;\n    }\n\n    export namespace Attachment {\n      export interface FileSearch {\n        /**\n         * The type of tool being defined: `file_search`\n         */\n        type: 'file_search';\n      }\n    }\n  }\n\n  /**\n   * Controls for how a thread will be truncated prior to the run. Use this to\n   * control the initial context window of the run.\n   */\n  export interface TruncationStrategy {\n    /**\n     * The truncation strategy to use for the thread. The default is `auto`. If set to\n     * `last_messages`, the thread will be truncated to the n most recent messages in\n     * the thread. When set to `auto`, messages in the middle of the thread will be\n     * dropped to fit the context length of the model, `max_prompt_tokens`.\n     */\n    type: 'auto' | 'last_messages';\n\n    /**\n     * The number of most recent messages from the thread when constructing the context\n     * for the run.\n     */\n    last_messages?: number | null;\n  }\n\n  export type RunCreateParamsNonStreaming = RunsAPI.RunCreateParamsNonStreaming;\n  export type RunCreateParamsStreaming = RunsAPI.RunCreateParamsStreaming;\n}\n\nexport interface RunCreateParamsNonStreaming extends RunCreateParamsBase {\n  /**\n   * Body param: If `true`, returns a stream of events that happen during the Run as\n   * server-sent events, terminating when the Run enters a terminal state with a\n   * `data: [DONE]` message.\n   */\n  stream?: false | null;\n}\n\nexport interface RunCreateParamsStreaming extends RunCreateParamsBase {\n  /**\n   * Body param: If `true`, returns a stream of events that happen during the Run as\n   * server-sent events, terminating when the Run enters a terminal state with a\n   * `data: [DONE]` message.\n   */\n  stream: true;\n}\n\nexport interface RunRetrieveParams {\n  /**\n   * The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)\n   * that was run.\n   */\n  thread_id: string;\n}\n\nexport interface RunUpdateParams {\n  /**\n   * Path param: The ID of the\n   * [thread](https://platform.openai.com/docs/api-reference/threads) that was run.\n   */\n  thread_id: string;\n\n  /**\n   * Body param: Set of 16 key-value pairs that can be attached to an object. This\n   * can be useful for storing additional information about the object in a\n   * structured format, and querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n}\n\nexport interface RunListParams extends CursorPageParams {\n  /**\n   * A cursor for use in pagination. `before` is an object ID that defines your place\n   * in the list. For instance, if you make a list request and receive 100 objects,\n   * starting with obj_foo, your subsequent call can include before=obj_foo in order\n   * to fetch the previous page of the list.\n   */\n  before?: string;\n\n  /**\n   * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n   * order and `desc` for descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport interface RunCancelParams {\n  /**\n   * The ID of the thread to which this run belongs.\n   */\n  thread_id: string;\n}\n\nexport type RunCreateAndPollParams = ThreadsAPI.ThreadCreateAndRunParamsNonStreaming;\n\nexport type RunCreateAndStreamParams = RunCreateParamsBaseStream;\n\nexport type RunStreamParams = RunCreateParamsBaseStream;\n\nexport type RunSubmitToolOutputsParams =\n  | RunSubmitToolOutputsParamsNonStreaming\n  | RunSubmitToolOutputsParamsStreaming;\n\nexport interface RunSubmitToolOutputsParamsBase {\n  /**\n   * Path param: The ID of the\n   * [thread](https://platform.openai.com/docs/api-reference/threads) to which this\n   * run belongs.\n   */\n  thread_id: string;\n\n  /**\n   * Body param: A list of tools for which the outputs are being submitted.\n   */\n  tool_outputs: Array<RunSubmitToolOutputsParams.ToolOutput>;\n\n  /**\n   * Body param: If `true`, returns a stream of events that happen during the Run as\n   * server-sent events, terminating when the Run enters a terminal state with a\n   * `data: [DONE]` message.\n   */\n  stream?: boolean | null;\n}\n\nexport namespace RunSubmitToolOutputsParams {\n  export interface ToolOutput {\n    /**\n     * The output of the tool call to be submitted to continue the run.\n     */\n    output?: string;\n\n    /**\n     * The ID of the tool call in the `required_action` object within the run object\n     * the output is being submitted for.\n     */\n    tool_call_id?: string;\n  }\n\n  export type RunSubmitToolOutputsParamsNonStreaming = RunsAPI.RunSubmitToolOutputsParamsNonStreaming;\n  export type RunSubmitToolOutputsParamsStreaming = RunsAPI.RunSubmitToolOutputsParamsStreaming;\n}\n\nexport interface RunSubmitToolOutputsParamsNonStreaming extends RunSubmitToolOutputsParamsBase {\n  /**\n   * Body param: If `true`, returns a stream of events that happen during the Run as\n   * server-sent events, terminating when the Run enters a terminal state with a\n   * `data: [DONE]` message.\n   */\n  stream?: false | null;\n}\n\nexport interface RunSubmitToolOutputsParamsStreaming extends RunSubmitToolOutputsParamsBase {\n  /**\n   * Body param: If `true`, returns a stream of events that happen during the Run as\n   * server-sent events, terminating when the Run enters a terminal state with a\n   * `data: [DONE]` message.\n   */\n  stream: true;\n}\n\nexport type RunSubmitToolOutputsAndPollParams = RunSubmitToolOutputsParamsNonStreaming;\nexport type RunSubmitToolOutputsStreamParams = RunSubmitToolOutputsParamsStream;\n\nRuns.Steps = Steps;\n\nexport declare namespace Runs {\n  export {\n    type RequiredActionFunctionToolCall as RequiredActionFunctionToolCall,\n    type Run as Run,\n    type RunStatus as RunStatus,\n    type RunsPage as RunsPage,\n    type RunCreateParams as RunCreateParams,\n    type RunCreateParamsNonStreaming as RunCreateParamsNonStreaming,\n    type RunCreateParamsStreaming as RunCreateParamsStreaming,\n    type RunRetrieveParams as RunRetrieveParams,\n    type RunUpdateParams as RunUpdateParams,\n    type RunListParams as RunListParams,\n    type RunCreateAndPollParams,\n    type RunCreateAndStreamParams,\n    type RunStreamParams,\n    type RunSubmitToolOutputsParams as RunSubmitToolOutputsParams,\n    type RunSubmitToolOutputsParamsNonStreaming as RunSubmitToolOutputsParamsNonStreaming,\n    type RunSubmitToolOutputsParamsStreaming as RunSubmitToolOutputsParamsStreaming,\n    type RunSubmitToolOutputsAndPollParams,\n    type RunSubmitToolOutputsStreamParams,\n  };\n\n  export {\n    Steps as Steps,\n    type CodeInterpreterLogs as CodeInterpreterLogs,\n    type CodeInterpreterOutputImage as CodeInterpreterOutputImage,\n    type CodeInterpreterToolCall as CodeInterpreterToolCall,\n    type CodeInterpreterToolCallDelta as CodeInterpreterToolCallDelta,\n    type FileSearchToolCall as FileSearchToolCall,\n    type FileSearchToolCallDelta as FileSearchToolCallDelta,\n    type FunctionToolCall as FunctionToolCall,\n    type FunctionToolCallDelta as FunctionToolCallDelta,\n    type MessageCreationStepDetails as MessageCreationStepDetails,\n    type RunStep as RunStep,\n    type RunStepDelta as RunStepDelta,\n    type RunStepDeltaEvent as RunStepDeltaEvent,\n    type RunStepDeltaMessageDelta as RunStepDeltaMessageDelta,\n    type RunStepInclude as RunStepInclude,\n    type ToolCall as ToolCall,\n    type ToolCallDelta as ToolCallDelta,\n    type ToolCallDeltaObject as ToolCallDeltaObject,\n    type ToolCallsStepDetails as ToolCallsStepDetails,\n    type RunStepsPage as RunStepsPage,\n    type StepRetrieveParams as StepRetrieveParams,\n    type StepListParams as StepListParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/beta/threads/runs/steps.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../../core/resource';\nimport * as StepsAPI from './steps';\nimport * as Shared from '../../../shared';\nimport { APIPromise } from '../../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../../core/pagination';\nimport { buildHeaders } from '../../../../internal/headers';\nimport { RequestOptions } from '../../../../internal/request-options';\nimport { path } from '../../../../internal/utils/path';\n\n/**\n * Build Assistants that can call models and use tools.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\nexport class Steps extends APIResource {\n  /**\n   * Retrieves a run step.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  retrieve(stepID: string, params: StepRetrieveParams, options?: RequestOptions): APIPromise<RunStep> {\n    const { thread_id, run_id, ...query } = params;\n    return this._client.get(path`/threads/${thread_id}/runs/${run_id}/steps/${stepID}`, {\n      query,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Returns a list of run steps belonging to a run.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  list(runID: string, params: StepListParams, options?: RequestOptions): PagePromise<RunStepsPage, RunStep> {\n    const { thread_id, ...query } = params;\n    return this._client.getAPIList(path`/threads/${thread_id}/runs/${runID}/steps`, CursorPage<RunStep>, {\n      query,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n}\n\nexport type RunStepsPage = CursorPage<RunStep>;\n\n/**\n * Text output from the Code Interpreter tool call as part of a run step.\n */\nexport interface CodeInterpreterLogs {\n  /**\n   * The index of the output in the outputs array.\n   */\n  index: number;\n\n  /**\n   * Always `logs`.\n   */\n  type: 'logs';\n\n  /**\n   * The text output from the Code Interpreter tool call.\n   */\n  logs?: string;\n}\n\nexport interface CodeInterpreterOutputImage {\n  /**\n   * The index of the output in the outputs array.\n   */\n  index: number;\n\n  /**\n   * Always `image`.\n   */\n  type: 'image';\n\n  image?: CodeInterpreterOutputImage.Image;\n}\n\nexport namespace CodeInterpreterOutputImage {\n  export interface Image {\n    /**\n     * The [file](https://platform.openai.com/docs/api-reference/files) ID of the\n     * image.\n     */\n    file_id?: string;\n  }\n}\n\n/**\n * Details of the Code Interpreter tool call the run step was involved in.\n */\nexport interface CodeInterpreterToolCall {\n  /**\n   * The ID of the tool call.\n   */\n  id: string;\n\n  /**\n   * The Code Interpreter tool call definition.\n   */\n  code_interpreter: CodeInterpreterToolCall.CodeInterpreter;\n\n  /**\n   * The type of tool call. This is always going to be `code_interpreter` for this\n   * type of tool call.\n   */\n  type: 'code_interpreter';\n}\n\nexport namespace CodeInterpreterToolCall {\n  /**\n   * The Code Interpreter tool call definition.\n   */\n  export interface CodeInterpreter {\n    /**\n     * The input to the Code Interpreter tool call.\n     */\n    input: string;\n\n    /**\n     * The outputs from the Code Interpreter tool call. Code Interpreter can output one\n     * or more items, including text (`logs`) or images (`image`). Each of these are\n     * represented by a different object type.\n     */\n    outputs: Array<CodeInterpreter.Logs | CodeInterpreter.Image>;\n  }\n\n  export namespace CodeInterpreter {\n    /**\n     * Text output from the Code Interpreter tool call as part of a run step.\n     */\n    export interface Logs {\n      /**\n       * The text output from the Code Interpreter tool call.\n       */\n      logs: string;\n\n      /**\n       * Always `logs`.\n       */\n      type: 'logs';\n    }\n\n    export interface Image {\n      image: Image.Image;\n\n      /**\n       * Always `image`.\n       */\n      type: 'image';\n    }\n\n    export namespace Image {\n      export interface Image {\n        /**\n         * The [file](https://platform.openai.com/docs/api-reference/files) ID of the\n         * image.\n         */\n        file_id: string;\n      }\n    }\n  }\n}\n\n/**\n * Details of the Code Interpreter tool call the run step was involved in.\n */\nexport interface CodeInterpreterToolCallDelta {\n  /**\n   * The index of the tool call in the tool calls array.\n   */\n  index: number;\n\n  /**\n   * The type of tool call. This is always going to be `code_interpreter` for this\n   * type of tool call.\n   */\n  type: 'code_interpreter';\n\n  /**\n   * The ID of the tool call.\n   */\n  id?: string;\n\n  /**\n   * The Code Interpreter tool call definition.\n   */\n  code_interpreter?: CodeInterpreterToolCallDelta.CodeInterpreter;\n}\n\nexport namespace CodeInterpreterToolCallDelta {\n  /**\n   * The Code Interpreter tool call definition.\n   */\n  export interface CodeInterpreter {\n    /**\n     * The input to the Code Interpreter tool call.\n     */\n    input?: string;\n\n    /**\n     * The outputs from the Code Interpreter tool call. Code Interpreter can output one\n     * or more items, including text (`logs`) or images (`image`). Each of these are\n     * represented by a different object type.\n     */\n    outputs?: Array<StepsAPI.CodeInterpreterLogs | StepsAPI.CodeInterpreterOutputImage>;\n  }\n}\n\nexport interface FileSearchToolCall {\n  /**\n   * The ID of the tool call object.\n   */\n  id: string;\n\n  /**\n   * For now, this is always going to be an empty object.\n   */\n  file_search: FileSearchToolCall.FileSearch;\n\n  /**\n   * The type of tool call. This is always going to be `file_search` for this type of\n   * tool call.\n   */\n  type: 'file_search';\n}\n\nexport namespace FileSearchToolCall {\n  /**\n   * For now, this is always going to be an empty object.\n   */\n  export interface FileSearch {\n    /**\n     * The ranking options for the file search.\n     */\n    ranking_options?: FileSearch.RankingOptions;\n\n    /**\n     * The results of the file search.\n     */\n    results?: Array<FileSearch.Result>;\n  }\n\n  export namespace FileSearch {\n    /**\n     * The ranking options for the file search.\n     */\n    export interface RankingOptions {\n      /**\n       * The ranker to use for the file search. If not specified will use the `auto`\n       * ranker.\n       */\n      ranker: 'auto' | 'default_2024_08_21';\n\n      /**\n       * The score threshold for the file search. All values must be a floating point\n       * number between 0 and 1.\n       */\n      score_threshold: number;\n    }\n\n    /**\n     * A result instance of the file search.\n     */\n    export interface Result {\n      /**\n       * The ID of the file that result was found in.\n       */\n      file_id: string;\n\n      /**\n       * The name of the file that result was found in.\n       */\n      file_name: string;\n\n      /**\n       * The score of the result. All values must be a floating point number between 0\n       * and 1.\n       */\n      score: number;\n\n      /**\n       * The content of the result that was found. The content is only included if\n       * requested via the include query parameter.\n       */\n      content?: Array<Result.Content>;\n    }\n\n    export namespace Result {\n      export interface Content {\n        /**\n         * The text content of the file.\n         */\n        text?: string;\n\n        /**\n         * The type of the content.\n         */\n        type?: 'text';\n      }\n    }\n  }\n}\n\nexport interface FileSearchToolCallDelta {\n  /**\n   * For now, this is always going to be an empty object.\n   */\n  file_search: unknown;\n\n  /**\n   * The index of the tool call in the tool calls array.\n   */\n  index: number;\n\n  /**\n   * The type of tool call. This is always going to be `file_search` for this type of\n   * tool call.\n   */\n  type: 'file_search';\n\n  /**\n   * The ID of the tool call object.\n   */\n  id?: string;\n}\n\nexport interface FunctionToolCall {\n  /**\n   * The ID of the tool call object.\n   */\n  id: string;\n\n  /**\n   * The definition of the function that was called.\n   */\n  function: FunctionToolCall.Function;\n\n  /**\n   * The type of tool call. This is always going to be `function` for this type of\n   * tool call.\n   */\n  type: 'function';\n}\n\nexport namespace FunctionToolCall {\n  /**\n   * The definition of the function that was called.\n   */\n  export interface Function {\n    /**\n     * The arguments passed to the function.\n     */\n    arguments: string;\n\n    /**\n     * The name of the function.\n     */\n    name: string;\n\n    /**\n     * The output of the function. This will be `null` if the outputs have not been\n     * [submitted](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)\n     * yet.\n     */\n    output: string | null;\n  }\n}\n\nexport interface FunctionToolCallDelta {\n  /**\n   * The index of the tool call in the tool calls array.\n   */\n  index: number;\n\n  /**\n   * The type of tool call. This is always going to be `function` for this type of\n   * tool call.\n   */\n  type: 'function';\n\n  /**\n   * The ID of the tool call object.\n   */\n  id?: string;\n\n  /**\n   * The definition of the function that was called.\n   */\n  function?: FunctionToolCallDelta.Function;\n}\n\nexport namespace FunctionToolCallDelta {\n  /**\n   * The definition of the function that was called.\n   */\n  export interface Function {\n    /**\n     * The arguments passed to the function.\n     */\n    arguments?: string;\n\n    /**\n     * The name of the function.\n     */\n    name?: string;\n\n    /**\n     * The output of the function. This will be `null` if the outputs have not been\n     * [submitted](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)\n     * yet.\n     */\n    output?: string | null;\n  }\n}\n\n/**\n * Details of the message creation by the run step.\n */\nexport interface MessageCreationStepDetails {\n  message_creation: MessageCreationStepDetails.MessageCreation;\n\n  /**\n   * Always `message_creation`.\n   */\n  type: 'message_creation';\n}\n\nexport namespace MessageCreationStepDetails {\n  export interface MessageCreation {\n    /**\n     * The ID of the message that was created by this run step.\n     */\n    message_id: string;\n  }\n}\n\n/**\n * Represents a step in execution of a run.\n */\nexport interface RunStep {\n  /**\n   * The identifier of the run step, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The ID of the\n   * [assistant](https://platform.openai.com/docs/api-reference/assistants)\n   * associated with the run step.\n   */\n  assistant_id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run step was cancelled.\n   */\n  cancelled_at: number | null;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run step completed.\n   */\n  completed_at: number | null;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run step was created.\n   */\n  created_at: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run step expired. A step is\n   * considered expired if the parent run is expired.\n   */\n  expired_at: number | null;\n\n  /**\n   * The Unix timestamp (in seconds) for when the run step failed.\n   */\n  failed_at: number | null;\n\n  /**\n   * The last error associated with this run step. Will be `null` if there are no\n   * errors.\n   */\n  last_error: RunStep.LastError | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The object type, which is always `thread.run.step`.\n   */\n  object: 'thread.run.step';\n\n  /**\n   * The ID of the [run](https://platform.openai.com/docs/api-reference/runs) that\n   * this run step is a part of.\n   */\n  run_id: string;\n\n  /**\n   * The status of the run step, which can be either `in_progress`, `cancelled`,\n   * `failed`, `completed`, or `expired`.\n   */\n  status: 'in_progress' | 'cancelled' | 'failed' | 'completed' | 'expired';\n\n  /**\n   * The details of the run step.\n   */\n  step_details: MessageCreationStepDetails | ToolCallsStepDetails;\n\n  /**\n   * The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)\n   * that was run.\n   */\n  thread_id: string;\n\n  /**\n   * The type of run step, which can be either `message_creation` or `tool_calls`.\n   */\n  type: 'message_creation' | 'tool_calls';\n\n  /**\n   * Usage statistics related to the run step. This value will be `null` while the\n   * run step's status is `in_progress`.\n   */\n  usage: RunStep.Usage | null;\n}\n\nexport namespace RunStep {\n  /**\n   * The last error associated with this run step. Will be `null` if there are no\n   * errors.\n   */\n  export interface LastError {\n    /**\n     * One of `server_error` or `rate_limit_exceeded`.\n     */\n    code: 'server_error' | 'rate_limit_exceeded';\n\n    /**\n     * A human-readable description of the error.\n     */\n    message: string;\n  }\n\n  /**\n   * Usage statistics related to the run step. This value will be `null` while the\n   * run step's status is `in_progress`.\n   */\n  export interface Usage {\n    /**\n     * Number of completion tokens used over the course of the run step.\n     */\n    completion_tokens: number;\n\n    /**\n     * Number of prompt tokens used over the course of the run step.\n     */\n    prompt_tokens: number;\n\n    /**\n     * Total number of tokens used (prompt + completion).\n     */\n    total_tokens: number;\n  }\n}\n\n/**\n * The delta containing the fields that have changed on the run step.\n */\nexport interface RunStepDelta {\n  /**\n   * The details of the run step.\n   */\n  step_details?: RunStepDeltaMessageDelta | ToolCallDeltaObject;\n}\n\n/**\n * Represents a run step delta i.e. any changed fields on a run step during\n * streaming.\n */\nexport interface RunStepDeltaEvent {\n  /**\n   * The identifier of the run step, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The delta containing the fields that have changed on the run step.\n   */\n  delta: RunStepDelta;\n\n  /**\n   * The object type, which is always `thread.run.step.delta`.\n   */\n  object: 'thread.run.step.delta';\n}\n\n/**\n * Details of the message creation by the run step.\n */\nexport interface RunStepDeltaMessageDelta {\n  /**\n   * Always `message_creation`.\n   */\n  type: 'message_creation';\n\n  message_creation?: RunStepDeltaMessageDelta.MessageCreation;\n}\n\nexport namespace RunStepDeltaMessageDelta {\n  export interface MessageCreation {\n    /**\n     * The ID of the message that was created by this run step.\n     */\n    message_id?: string;\n  }\n}\n\nexport type RunStepInclude = 'step_details.tool_calls[*].file_search.results[*].content';\n\n/**\n * Details of the Code Interpreter tool call the run step was involved in.\n */\nexport type ToolCall = CodeInterpreterToolCall | FileSearchToolCall | FunctionToolCall;\n\n/**\n * Details of the Code Interpreter tool call the run step was involved in.\n */\nexport type ToolCallDelta = CodeInterpreterToolCallDelta | FileSearchToolCallDelta | FunctionToolCallDelta;\n\n/**\n * Details of the tool call.\n */\nexport interface ToolCallDeltaObject {\n  /**\n   * Always `tool_calls`.\n   */\n  type: 'tool_calls';\n\n  /**\n   * An array of tool calls the run step was involved in. These can be associated\n   * with one of three types of tools: `code_interpreter`, `file_search`, or\n   * `function`.\n   */\n  tool_calls?: Array<ToolCallDelta>;\n}\n\n/**\n * Details of the tool call.\n */\nexport interface ToolCallsStepDetails {\n  /**\n   * An array of tool calls the run step was involved in. These can be associated\n   * with one of three types of tools: `code_interpreter`, `file_search`, or\n   * `function`.\n   */\n  tool_calls: Array<ToolCall>;\n\n  /**\n   * Always `tool_calls`.\n   */\n  type: 'tool_calls';\n}\n\nexport interface StepRetrieveParams {\n  /**\n   * Path param: The ID of the thread to which the run and run step belongs.\n   */\n  thread_id: string;\n\n  /**\n   * Path param: The ID of the run to which the run step belongs.\n   */\n  run_id: string;\n\n  /**\n   * Query param: A list of additional fields to include in the response. Currently\n   * the only supported value is\n   * `step_details.tool_calls[*].file_search.results[*].content` to fetch the file\n   * search result content.\n   *\n   * See the\n   * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n   * for more information.\n   */\n  include?: Array<RunStepInclude>;\n}\n\nexport interface StepListParams extends CursorPageParams {\n  /**\n   * Path param: The ID of the thread the run and run steps belong to.\n   */\n  thread_id: string;\n\n  /**\n   * Query param: A cursor for use in pagination. `before` is an object ID that\n   * defines your place in the list. For instance, if you make a list request and\n   * receive 100 objects, starting with obj_foo, your subsequent call can include\n   * before=obj_foo in order to fetch the previous page of the list.\n   */\n  before?: string;\n\n  /**\n   * Query param: A list of additional fields to include in the response. Currently\n   * the only supported value is\n   * `step_details.tool_calls[*].file_search.results[*].content` to fetch the file\n   * search result content.\n   *\n   * See the\n   * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n   * for more information.\n   */\n  include?: Array<RunStepInclude>;\n\n  /**\n   * Query param: Sort order by the `created_at` timestamp of the objects. `asc` for\n   * ascending order and `desc` for descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport declare namespace Steps {\n  export {\n    type CodeInterpreterLogs as CodeInterpreterLogs,\n    type CodeInterpreterOutputImage as CodeInterpreterOutputImage,\n    type CodeInterpreterToolCall as CodeInterpreterToolCall,\n    type CodeInterpreterToolCallDelta as CodeInterpreterToolCallDelta,\n    type FileSearchToolCall as FileSearchToolCall,\n    type FileSearchToolCallDelta as FileSearchToolCallDelta,\n    type FunctionToolCall as FunctionToolCall,\n    type FunctionToolCallDelta as FunctionToolCallDelta,\n    type MessageCreationStepDetails as MessageCreationStepDetails,\n    type RunStep as RunStep,\n    type RunStepDelta as RunStepDelta,\n    type RunStepDeltaEvent as RunStepDeltaEvent,\n    type RunStepDeltaMessageDelta as RunStepDeltaMessageDelta,\n    type RunStepInclude as RunStepInclude,\n    type ToolCall as ToolCall,\n    type ToolCallDelta as ToolCallDelta,\n    type ToolCallDeltaObject as ToolCallDeltaObject,\n    type ToolCallsStepDetails as ToolCallsStepDetails,\n    type RunStepsPage as RunStepsPage,\n    type StepRetrieveParams as StepRetrieveParams,\n    type StepListParams as StepListParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/beta/threads/runs.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './runs/index';\n"
  },
  {
    "path": "src/resources/beta/threads/threads.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ThreadsAPI from './threads';\nimport * as Shared from '../../shared';\nimport * as AssistantsAPI from '../assistants';\nimport * as MessagesAPI from './messages';\nimport {\n  Annotation,\n  AnnotationDelta,\n  FileCitationAnnotation,\n  FileCitationDeltaAnnotation,\n  FilePathAnnotation,\n  FilePathDeltaAnnotation,\n  ImageFile,\n  ImageFileContentBlock,\n  ImageFileDelta,\n  ImageFileDeltaBlock,\n  ImageURL,\n  ImageURLContentBlock,\n  ImageURLDelta,\n  ImageURLDeltaBlock,\n  Message as MessagesAPIMessage,\n  MessageContent,\n  MessageContentDelta,\n  MessageContentPartParam,\n  MessageCreateParams,\n  MessageDeleteParams,\n  MessageDeleted,\n  MessageDelta,\n  MessageDeltaEvent,\n  MessageListParams,\n  MessageRetrieveParams,\n  MessageUpdateParams,\n  Messages,\n  MessagesPage,\n  RefusalContentBlock,\n  RefusalDeltaBlock,\n  Text,\n  TextContentBlock,\n  TextContentBlockParam,\n  TextDelta,\n  TextDeltaBlock,\n} from './messages';\nimport * as RunsAPI from './runs/runs';\nimport {\n  RequiredActionFunctionToolCall,\n  Run,\n  RunCreateAndPollParams,\n  RunCreateAndStreamParams,\n  RunCancelParams,\n  RunCreateParams,\n  RunCreateParamsNonStreaming,\n  RunCreateParamsStreaming,\n  RunListParams,\n  RunRetrieveParams,\n  RunStatus,\n  RunStreamParams,\n  RunSubmitToolOutputsAndPollParams,\n  RunSubmitToolOutputsParams,\n  RunSubmitToolOutputsParamsNonStreaming,\n  RunSubmitToolOutputsParamsStreaming,\n  RunSubmitToolOutputsStreamParams,\n  RunUpdateParams,\n  Runs,\n  RunsPage,\n} from './runs/runs';\nimport { APIPromise } from '../../../core/api-promise';\nimport { Stream } from '../../../core/streaming';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { AssistantStream, ThreadCreateAndRunParamsBaseStream } from '../../../lib/AssistantStream';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Build Assistants that can call models and use tools.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\nexport class Threads extends APIResource {\n  runs: RunsAPI.Runs = new RunsAPI.Runs(this._client);\n  messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);\n\n  /**\n   * Create a thread.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  create(body: ThreadCreateParams | null | undefined = {}, options?: RequestOptions): APIPromise<Thread> {\n    return this._client.post('/threads', {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Retrieves a thread.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  retrieve(threadID: string, options?: RequestOptions): APIPromise<Thread> {\n    return this._client.get(path`/threads/${threadID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Modifies a thread.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  update(threadID: string, body: ThreadUpdateParams, options?: RequestOptions): APIPromise<Thread> {\n    return this._client.post(path`/threads/${threadID}`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Delete a thread.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  delete(threadID: string, options?: RequestOptions): APIPromise<ThreadDeleted> {\n    return this._client.delete(path`/threads/${threadID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Create a thread and run it in one request.\n   *\n   * @deprecated The Assistants API is deprecated in favor of the Responses API\n   */\n  createAndRun(body: ThreadCreateAndRunParamsNonStreaming, options?: RequestOptions): APIPromise<RunsAPI.Run>;\n  createAndRun(\n    body: ThreadCreateAndRunParamsStreaming,\n    options?: RequestOptions,\n  ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n  createAndRun(\n    body: ThreadCreateAndRunParamsBase,\n    options?: RequestOptions,\n  ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent> | RunsAPI.Run>;\n  createAndRun(\n    body: ThreadCreateAndRunParams,\n    options?: RequestOptions,\n  ): APIPromise<RunsAPI.Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>> {\n    return this._client.post('/threads/runs', {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n      stream: body.stream ?? false,\n      __synthesizeEventData: true,\n    }) as APIPromise<RunsAPI.Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n  }\n\n  /**\n   * A helper to create a thread, start a run and then poll for a terminal state.\n   * More information on Run lifecycles can be found here:\n   * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps\n   */\n  async createAndRunPoll(\n    body: ThreadCreateAndRunParamsNonStreaming,\n    options?: RequestOptions & { pollIntervalMs?: number },\n  ): Promise<Threads.Run> {\n    const run = await this.createAndRun(body, options);\n    return await this.runs.poll(run.id, { thread_id: run.thread_id }, options);\n  }\n\n  /**\n   * Create a thread and stream the run back\n   */\n  createAndRunStream(body: ThreadCreateAndRunParamsBaseStream, options?: RequestOptions): AssistantStream {\n    return AssistantStream.createThreadAssistantStream(body, this._client.beta.threads, options);\n  }\n}\n\n/**\n * Specifies the format that the model must output. Compatible with\n * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n *\n * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n * Outputs which ensures the model will match your supplied JSON schema. Learn more\n * in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n * message the model generates is valid JSON.\n *\n * **Important:** when using JSON mode, you **must** also instruct the model to\n * produce JSON yourself via a system or user message. Without this, the model may\n * generate an unending stream of whitespace until the generation reaches the token\n * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n * the message content may be partially cut off if `finish_reason=\"length\"`, which\n * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n * max context length.\n */\nexport type AssistantResponseFormatOption =\n  | 'auto'\n  | Shared.ResponseFormatText\n  | Shared.ResponseFormatJSONObject\n  | Shared.ResponseFormatJSONSchema;\n\n/**\n * Specifies a tool the model should use. Use to force the model to call a specific\n * tool.\n */\nexport interface AssistantToolChoice {\n  /**\n   * The type of the tool. If type is `function`, the function name must be set\n   */\n  type: 'function' | 'code_interpreter' | 'file_search';\n\n  function?: AssistantToolChoiceFunction;\n}\n\nexport interface AssistantToolChoiceFunction {\n  /**\n   * The name of the function to call.\n   */\n  name: string;\n}\n\n/**\n * Controls which (if any) tool is called by the model. `none` means the model will\n * not call any tools and instead generates a message. `auto` is the default value\n * and means the model can pick between generating a message or calling one or more\n * tools. `required` means the model must call one or more tools before responding\n * to the user. Specifying a particular tool like `{\"type\": \"file_search\"}` or\n * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n * call that tool.\n */\nexport type AssistantToolChoiceOption = 'none' | 'auto' | 'required' | AssistantToolChoice;\n\n/**\n * Represents a thread that contains\n * [messages](https://platform.openai.com/docs/api-reference/messages).\n */\nexport interface Thread {\n  /**\n   * The identifier, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the thread was created.\n   */\n  created_at: number;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The object type, which is always `thread`.\n   */\n  object: 'thread';\n\n  /**\n   * A set of resources that are made available to the assistant's tools in this\n   * thread. The resources are specific to the type of tool. For example, the\n   * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n   * tool requires a list of vector store IDs.\n   */\n  tool_resources: Thread.ToolResources | null;\n}\n\nexport namespace Thread {\n  /**\n   * A set of resources that are made available to the assistant's tools in this\n   * thread. The resources are specific to the type of tool. For example, the\n   * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n   * tool requires a list of vector store IDs.\n   */\n  export interface ToolResources {\n    code_interpreter?: ToolResources.CodeInterpreter;\n\n    file_search?: ToolResources.FileSearch;\n  }\n\n  export namespace ToolResources {\n    export interface CodeInterpreter {\n      /**\n       * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n       * available to the `code_interpreter` tool. There can be a maximum of 20 files\n       * associated with the tool.\n       */\n      file_ids?: Array<string>;\n    }\n\n    export interface FileSearch {\n      /**\n       * The\n       * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n       * attached to this thread. There can be a maximum of 1 vector store attached to\n       * the thread.\n       */\n      vector_store_ids?: Array<string>;\n    }\n  }\n}\n\nexport interface ThreadDeleted {\n  id: string;\n\n  deleted: boolean;\n\n  object: 'thread.deleted';\n}\n\nexport interface ThreadCreateParams {\n  /**\n   * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to\n   * start the thread with.\n   */\n  messages?: Array<ThreadCreateParams.Message>;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * A set of resources that are made available to the assistant's tools in this\n   * thread. The resources are specific to the type of tool. For example, the\n   * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n   * tool requires a list of vector store IDs.\n   */\n  tool_resources?: ThreadCreateParams.ToolResources | null;\n}\n\nexport namespace ThreadCreateParams {\n  export interface Message {\n    /**\n     * The text contents of the message.\n     */\n    content: string | Array<MessagesAPI.MessageContentPartParam>;\n\n    /**\n     * The role of the entity that is creating the message. Allowed values include:\n     *\n     * - `user`: Indicates the message is sent by an actual user and should be used in\n     *   most cases to represent user-generated messages.\n     * - `assistant`: Indicates the message is generated by the assistant. Use this\n     *   value to insert messages from the assistant into the conversation.\n     */\n    role: 'user' | 'assistant';\n\n    /**\n     * A list of files attached to the message, and the tools they should be added to.\n     */\n    attachments?: Array<Message.Attachment> | null;\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard.\n     *\n     * Keys are strings with a maximum length of 64 characters. Values are strings with\n     * a maximum length of 512 characters.\n     */\n    metadata?: Shared.Metadata | null;\n  }\n\n  export namespace Message {\n    export interface Attachment {\n      /**\n       * The ID of the file to attach to the message.\n       */\n      file_id?: string;\n\n      /**\n       * The tools to add this file to.\n       */\n      tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;\n    }\n\n    export namespace Attachment {\n      export interface FileSearch {\n        /**\n         * The type of tool being defined: `file_search`\n         */\n        type: 'file_search';\n      }\n    }\n  }\n\n  /**\n   * A set of resources that are made available to the assistant's tools in this\n   * thread. The resources are specific to the type of tool. For example, the\n   * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n   * tool requires a list of vector store IDs.\n   */\n  export interface ToolResources {\n    code_interpreter?: ToolResources.CodeInterpreter;\n\n    file_search?: ToolResources.FileSearch;\n  }\n\n  export namespace ToolResources {\n    export interface CodeInterpreter {\n      /**\n       * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n       * available to the `code_interpreter` tool. There can be a maximum of 20 files\n       * associated with the tool.\n       */\n      file_ids?: Array<string>;\n    }\n\n    export interface FileSearch {\n      /**\n       * The\n       * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n       * attached to this thread. There can be a maximum of 1 vector store attached to\n       * the thread.\n       */\n      vector_store_ids?: Array<string>;\n\n      /**\n       * A helper to create a\n       * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n       * with file_ids and attach it to this thread. There can be a maximum of 1 vector\n       * store attached to the thread.\n       */\n      vector_stores?: Array<FileSearch.VectorStore>;\n    }\n\n    export namespace FileSearch {\n      export interface VectorStore {\n        /**\n         * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n         * strategy.\n         */\n        chunking_strategy?: VectorStore.Auto | VectorStore.Static;\n\n        /**\n         * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to\n         * add to the vector store. For vector stores created before Nov 2025, there can be\n         * a maximum of 10,000 files in a vector store. For vector stores created starting\n         * in Nov 2025, the limit is 100,000,000 files.\n         */\n        file_ids?: Array<string>;\n\n        /**\n         * Set of 16 key-value pairs that can be attached to an object. This can be useful\n         * for storing additional information about the object in a structured format, and\n         * querying for objects via API or the dashboard.\n         *\n         * Keys are strings with a maximum length of 64 characters. Values are strings with\n         * a maximum length of 512 characters.\n         */\n        metadata?: Shared.Metadata | null;\n      }\n\n      export namespace VectorStore {\n        /**\n         * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of\n         * `800` and `chunk_overlap_tokens` of `400`.\n         */\n        export interface Auto {\n          /**\n           * Always `auto`.\n           */\n          type: 'auto';\n        }\n\n        export interface Static {\n          static: Static.Static;\n\n          /**\n           * Always `static`.\n           */\n          type: 'static';\n        }\n\n        export namespace Static {\n          export interface Static {\n            /**\n             * The number of tokens that overlap between chunks. The default value is `400`.\n             *\n             * Note that the overlap must not exceed half of `max_chunk_size_tokens`.\n             */\n            chunk_overlap_tokens: number;\n\n            /**\n             * The maximum number of tokens in each chunk. The default value is `800`. The\n             * minimum value is `100` and the maximum value is `4096`.\n             */\n            max_chunk_size_tokens: number;\n          }\n        }\n      }\n    }\n  }\n}\n\nexport interface ThreadUpdateParams {\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * A set of resources that are made available to the assistant's tools in this\n   * thread. The resources are specific to the type of tool. For example, the\n   * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n   * tool requires a list of vector store IDs.\n   */\n  tool_resources?: ThreadUpdateParams.ToolResources | null;\n}\n\nexport namespace ThreadUpdateParams {\n  /**\n   * A set of resources that are made available to the assistant's tools in this\n   * thread. The resources are specific to the type of tool. For example, the\n   * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n   * tool requires a list of vector store IDs.\n   */\n  export interface ToolResources {\n    code_interpreter?: ToolResources.CodeInterpreter;\n\n    file_search?: ToolResources.FileSearch;\n  }\n\n  export namespace ToolResources {\n    export interface CodeInterpreter {\n      /**\n       * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n       * available to the `code_interpreter` tool. There can be a maximum of 20 files\n       * associated with the tool.\n       */\n      file_ids?: Array<string>;\n    }\n\n    export interface FileSearch {\n      /**\n       * The\n       * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n       * attached to this thread. There can be a maximum of 1 vector store attached to\n       * the thread.\n       */\n      vector_store_ids?: Array<string>;\n    }\n  }\n}\n\nexport type ThreadCreateAndRunParams =\n  | ThreadCreateAndRunParamsNonStreaming\n  | ThreadCreateAndRunParamsStreaming;\n\nexport interface ThreadCreateAndRunParamsBase {\n  /**\n   * The ID of the\n   * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to\n   * execute this run.\n   */\n  assistant_id: string;\n\n  /**\n   * Override the default system message of the assistant. This is useful for\n   * modifying the behavior on a per-run basis.\n   */\n  instructions?: string | null;\n\n  /**\n   * The maximum number of completion tokens that may be used over the course of the\n   * run. The run will make a best effort to use only the number of completion tokens\n   * specified, across multiple turns of the run. If the run exceeds the number of\n   * completion tokens specified, the run will end with status `incomplete`. See\n   * `incomplete_details` for more info.\n   */\n  max_completion_tokens?: number | null;\n\n  /**\n   * The maximum number of prompt tokens that may be used over the course of the run.\n   * The run will make a best effort to use only the number of prompt tokens\n   * specified, across multiple turns of the run. If the run exceeds the number of\n   * prompt tokens specified, the run will end with status `incomplete`. See\n   * `incomplete_details` for more info.\n   */\n  max_prompt_tokens?: number | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to\n   * be used to execute this run. If a value is provided here, it will override the\n   * model associated with the assistant. If not, the model associated with the\n   * assistant will be used.\n   */\n  model?: (string & {}) | Shared.ChatModel | null;\n\n  /**\n   * Whether to enable\n   * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)\n   * during tool use.\n   */\n  parallel_tool_calls?: boolean;\n\n  /**\n   * Specifies the format that the model must output. Compatible with\n   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n   * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n   * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n   *\n   * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n   * Outputs which ensures the model will match your supplied JSON schema. Learn more\n   * in the\n   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n   *\n   * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n   * message the model generates is valid JSON.\n   *\n   * **Important:** when using JSON mode, you **must** also instruct the model to\n   * produce JSON yourself via a system or user message. Without this, the model may\n   * generate an unending stream of whitespace until the generation reaches the token\n   * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n   * the message content may be partially cut off if `finish_reason=\"length\"`, which\n   * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n   * max context length.\n   */\n  response_format?: AssistantResponseFormatOption | null;\n\n  /**\n   * If `true`, returns a stream of events that happen during the Run as server-sent\n   * events, terminating when the Run enters a terminal state with a `data: [DONE]`\n   * message.\n   */\n  stream?: boolean | null;\n\n  /**\n   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n   * make the output more random, while lower values like 0.2 will make it more\n   * focused and deterministic.\n   */\n  temperature?: number | null;\n\n  /**\n   * Options to create a new thread. If no thread is provided when running a request,\n   * an empty thread will be created.\n   */\n  thread?: ThreadCreateAndRunParams.Thread;\n\n  /**\n   * Controls which (if any) tool is called by the model. `none` means the model will\n   * not call any tools and instead generates a message. `auto` is the default value\n   * and means the model can pick between generating a message or calling one or more\n   * tools. `required` means the model must call one or more tools before responding\n   * to the user. Specifying a particular tool like `{\"type\": \"file_search\"}` or\n   * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n   * call that tool.\n   */\n  tool_choice?: AssistantToolChoiceOption | null;\n\n  /**\n   * A set of resources that are used by the assistant's tools. The resources are\n   * specific to the type of tool. For example, the `code_interpreter` tool requires\n   * a list of file IDs, while the `file_search` tool requires a list of vector store\n   * IDs.\n   */\n  tool_resources?: ThreadCreateAndRunParams.ToolResources | null;\n\n  /**\n   * Override the tools the assistant can use for this run. This is useful for\n   * modifying the behavior on a per-run basis.\n   */\n  tools?: Array<AssistantsAPI.AssistantTool> | null;\n\n  /**\n   * An alternative to sampling with temperature, called nucleus sampling, where the\n   * model considers the results of the tokens with top_p probability mass. So 0.1\n   * means only the tokens comprising the top 10% probability mass are considered.\n   *\n   * We generally recommend altering this or temperature but not both.\n   */\n  top_p?: number | null;\n\n  /**\n   * Controls for how a thread will be truncated prior to the run. Use this to\n   * control the initial context window of the run.\n   */\n  truncation_strategy?: ThreadCreateAndRunParams.TruncationStrategy | null;\n}\n\nexport namespace ThreadCreateAndRunParams {\n  /**\n   * Options to create a new thread. If no thread is provided when running a request,\n   * an empty thread will be created.\n   */\n  export interface Thread {\n    /**\n     * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to\n     * start the thread with.\n     */\n    messages?: Array<Thread.Message>;\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard.\n     *\n     * Keys are strings with a maximum length of 64 characters. Values are strings with\n     * a maximum length of 512 characters.\n     */\n    metadata?: Shared.Metadata | null;\n\n    /**\n     * A set of resources that are made available to the assistant's tools in this\n     * thread. The resources are specific to the type of tool. For example, the\n     * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n     * tool requires a list of vector store IDs.\n     */\n    tool_resources?: Thread.ToolResources | null;\n  }\n\n  export namespace Thread {\n    export interface Message {\n      /**\n       * The text contents of the message.\n       */\n      content: string | Array<MessagesAPI.MessageContentPartParam>;\n\n      /**\n       * The role of the entity that is creating the message. Allowed values include:\n       *\n       * - `user`: Indicates the message is sent by an actual user and should be used in\n       *   most cases to represent user-generated messages.\n       * - `assistant`: Indicates the message is generated by the assistant. Use this\n       *   value to insert messages from the assistant into the conversation.\n       */\n      role: 'user' | 'assistant';\n\n      /**\n       * A list of files attached to the message, and the tools they should be added to.\n       */\n      attachments?: Array<Message.Attachment> | null;\n\n      /**\n       * Set of 16 key-value pairs that can be attached to an object. This can be useful\n       * for storing additional information about the object in a structured format, and\n       * querying for objects via API or the dashboard.\n       *\n       * Keys are strings with a maximum length of 64 characters. Values are strings with\n       * a maximum length of 512 characters.\n       */\n      metadata?: Shared.Metadata | null;\n    }\n\n    export namespace Message {\n      export interface Attachment {\n        /**\n         * The ID of the file to attach to the message.\n         */\n        file_id?: string;\n\n        /**\n         * The tools to add this file to.\n         */\n        tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;\n      }\n\n      export namespace Attachment {\n        export interface FileSearch {\n          /**\n           * The type of tool being defined: `file_search`\n           */\n          type: 'file_search';\n        }\n      }\n    }\n\n    /**\n     * A set of resources that are made available to the assistant's tools in this\n     * thread. The resources are specific to the type of tool. For example, the\n     * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n     * tool requires a list of vector store IDs.\n     */\n    export interface ToolResources {\n      code_interpreter?: ToolResources.CodeInterpreter;\n\n      file_search?: ToolResources.FileSearch;\n    }\n\n    export namespace ToolResources {\n      export interface CodeInterpreter {\n        /**\n         * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n         * available to the `code_interpreter` tool. There can be a maximum of 20 files\n         * associated with the tool.\n         */\n        file_ids?: Array<string>;\n      }\n\n      export interface FileSearch {\n        /**\n         * The\n         * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n         * attached to this thread. There can be a maximum of 1 vector store attached to\n         * the thread.\n         */\n        vector_store_ids?: Array<string>;\n\n        /**\n         * A helper to create a\n         * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n         * with file_ids and attach it to this thread. There can be a maximum of 1 vector\n         * store attached to the thread.\n         */\n        vector_stores?: Array<FileSearch.VectorStore>;\n      }\n\n      export namespace FileSearch {\n        export interface VectorStore {\n          /**\n           * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n           * strategy.\n           */\n          chunking_strategy?: VectorStore.Auto | VectorStore.Static;\n\n          /**\n           * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to\n           * add to the vector store. For vector stores created before Nov 2025, there can be\n           * a maximum of 10,000 files in a vector store. For vector stores created starting\n           * in Nov 2025, the limit is 100,000,000 files.\n           */\n          file_ids?: Array<string>;\n\n          /**\n           * Set of 16 key-value pairs that can be attached to an object. This can be useful\n           * for storing additional information about the object in a structured format, and\n           * querying for objects via API or the dashboard.\n           *\n           * Keys are strings with a maximum length of 64 characters. Values are strings with\n           * a maximum length of 512 characters.\n           */\n          metadata?: Shared.Metadata | null;\n        }\n\n        export namespace VectorStore {\n          /**\n           * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of\n           * `800` and `chunk_overlap_tokens` of `400`.\n           */\n          export interface Auto {\n            /**\n             * Always `auto`.\n             */\n            type: 'auto';\n          }\n\n          export interface Static {\n            static: Static.Static;\n\n            /**\n             * Always `static`.\n             */\n            type: 'static';\n          }\n\n          export namespace Static {\n            export interface Static {\n              /**\n               * The number of tokens that overlap between chunks. The default value is `400`.\n               *\n               * Note that the overlap must not exceed half of `max_chunk_size_tokens`.\n               */\n              chunk_overlap_tokens: number;\n\n              /**\n               * The maximum number of tokens in each chunk. The default value is `800`. The\n               * minimum value is `100` and the maximum value is `4096`.\n               */\n              max_chunk_size_tokens: number;\n            }\n          }\n        }\n      }\n    }\n  }\n\n  /**\n   * A set of resources that are used by the assistant's tools. The resources are\n   * specific to the type of tool. For example, the `code_interpreter` tool requires\n   * a list of file IDs, while the `file_search` tool requires a list of vector store\n   * IDs.\n   */\n  export interface ToolResources {\n    code_interpreter?: ToolResources.CodeInterpreter;\n\n    file_search?: ToolResources.FileSearch;\n  }\n\n  export namespace ToolResources {\n    export interface CodeInterpreter {\n      /**\n       * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n       * available to the `code_interpreter` tool. There can be a maximum of 20 files\n       * associated with the tool.\n       */\n      file_ids?: Array<string>;\n    }\n\n    export interface FileSearch {\n      /**\n       * The ID of the\n       * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n       * attached to this assistant. There can be a maximum of 1 vector store attached to\n       * the assistant.\n       */\n      vector_store_ids?: Array<string>;\n    }\n  }\n\n  /**\n   * Controls for how a thread will be truncated prior to the run. Use this to\n   * control the initial context window of the run.\n   */\n  export interface TruncationStrategy {\n    /**\n     * The truncation strategy to use for the thread. The default is `auto`. If set to\n     * `last_messages`, the thread will be truncated to the n most recent messages in\n     * the thread. When set to `auto`, messages in the middle of the thread will be\n     * dropped to fit the context length of the model, `max_prompt_tokens`.\n     */\n    type: 'auto' | 'last_messages';\n\n    /**\n     * The number of most recent messages from the thread when constructing the context\n     * for the run.\n     */\n    last_messages?: number | null;\n  }\n\n  export type ThreadCreateAndRunParamsNonStreaming = ThreadsAPI.ThreadCreateAndRunParamsNonStreaming;\n  export type ThreadCreateAndRunParamsStreaming = ThreadsAPI.ThreadCreateAndRunParamsStreaming;\n}\n\nexport interface ThreadCreateAndRunParamsNonStreaming extends ThreadCreateAndRunParamsBase {\n  /**\n   * If `true`, returns a stream of events that happen during the Run as server-sent\n   * events, terminating when the Run enters a terminal state with a `data: [DONE]`\n   * message.\n   */\n  stream?: false | null;\n}\n\nexport interface ThreadCreateAndRunParamsStreaming extends ThreadCreateAndRunParamsBase {\n  /**\n   * If `true`, returns a stream of events that happen during the Run as server-sent\n   * events, terminating when the Run enters a terminal state with a `data: [DONE]`\n   * message.\n   */\n  stream: true;\n}\n\nexport interface ThreadCreateAndRunPollParams {\n  /**\n   * The ID of the\n   * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to\n   * execute this run.\n   */\n  assistant_id: string;\n\n  /**\n   * Override the default system message of the assistant. This is useful for\n   * modifying the behavior on a per-run basis.\n   */\n  instructions?: string | null;\n\n  /**\n   * The maximum number of completion tokens that may be used over the course of the\n   * run. The run will make a best effort to use only the number of completion tokens\n   * specified, across multiple turns of the run. If the run exceeds the number of\n   * completion tokens specified, the run will end with status `incomplete`. See\n   * `incomplete_details` for more info.\n   */\n  max_completion_tokens?: number | null;\n\n  /**\n   * The maximum number of prompt tokens that may be used over the course of the run.\n   * The run will make a best effort to use only the number of prompt tokens\n   * specified, across multiple turns of the run. If the run exceeds the number of\n   * prompt tokens specified, the run will end with status `incomplete`. See\n   * `incomplete_details` for more info.\n   */\n  max_prompt_tokens?: number | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format. Keys\n   * can be a maximum of 64 characters long and values can be a maxium of 512\n   * characters long.\n   */\n  metadata?: unknown | null;\n\n  /**\n   * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to\n   * be used to execute this run. If a value is provided here, it will override the\n   * model associated with the assistant. If not, the model associated with the\n   * assistant will be used.\n   */\n  model?:\n    | (string & {})\n    | 'gpt-4o'\n    | 'gpt-4o-2024-05-13'\n    | 'gpt-4-turbo'\n    | 'gpt-4-turbo-2024-04-09'\n    | 'gpt-4-0125-preview'\n    | 'gpt-4-turbo-preview'\n    | 'gpt-4-1106-preview'\n    | 'gpt-4-vision-preview'\n    | 'gpt-4'\n    | 'gpt-4-0314'\n    | 'gpt-4-0613'\n    | 'gpt-4-32k'\n    | 'gpt-4-32k-0314'\n    | 'gpt-4-32k-0613'\n    | 'gpt-3.5-turbo'\n    | 'gpt-3.5-turbo-16k'\n    | 'gpt-3.5-turbo-0613'\n    | 'gpt-3.5-turbo-1106'\n    | 'gpt-3.5-turbo-0125'\n    | 'gpt-3.5-turbo-16k-0613'\n    | null;\n\n  /**\n   * Specifies the format that the model must output. Compatible with\n   * [GPT-4o](https://platform.openai.com/docs/models/gpt-4o),\n   * [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4),\n   * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n   *\n   * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the\n   * message the model generates is valid JSON.\n   *\n   * **Important:** when using JSON mode, you **must** also instruct the model to\n   * produce JSON yourself via a system or user message. Without this, the model may\n   * generate an unending stream of whitespace until the generation reaches the token\n   * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n   * the message content may be partially cut off if `finish_reason=\"length\"`, which\n   * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n   * max context length.\n   */\n  response_format?: AssistantResponseFormatOption | null;\n\n  /**\n   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n   * make the output more random, while lower values like 0.2 will make it more\n   * focused and deterministic.\n   */\n  temperature?: number | null;\n\n  /**\n   * If no thread is provided, an empty thread will be created.\n   */\n  thread?: ThreadCreateAndRunPollParams.Thread;\n\n  /**\n   * Controls which (if any) tool is called by the model. `none` means the model will\n   * not call any tools and instead generates a message. `auto` is the default value\n   * and means the model can pick between generating a message or calling one or more\n   * tools. `required` means the model must call one or more tools before responding\n   * to the user. Specifying a particular tool like `{\"type\": \"file_search\"}` or\n   * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n   * call that tool.\n   */\n  tool_choice?: AssistantToolChoiceOption | null;\n\n  /**\n   * A set of resources that are used by the assistant's tools. The resources are\n   * specific to the type of tool. For example, the `code_interpreter` tool requires\n   * a list of file IDs, while the `file_search` tool requires a list of vector store\n   * IDs.\n   */\n  tool_resources?: ThreadCreateAndRunPollParams.ToolResources | null;\n\n  /**\n   * Override the tools the assistant can use for this run. This is useful for\n   * modifying the behavior on a per-run basis.\n   */\n  tools?: Array<\n    AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool | AssistantsAPI.FunctionTool\n  > | null;\n\n  /**\n   * An alternative to sampling with temperature, called nucleus sampling, where the\n   * model considers the results of the tokens with top_p probability mass. So 0.1\n   * means only the tokens comprising the top 10% probability mass are considered.\n   *\n   * We generally recommend altering this or temperature but not both.\n   */\n  top_p?: number | null;\n\n  /**\n   * Controls for how a thread will be truncated prior to the run. Use this to\n   * control the intial context window of the run.\n   */\n  truncation_strategy?: ThreadCreateAndRunPollParams.TruncationStrategy | null;\n}\n\nexport namespace ThreadCreateAndRunPollParams {\n  /**\n   * If no thread is provided, an empty thread will be created.\n   */\n  export interface Thread {\n    /**\n     * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to\n     * start the thread with.\n     */\n    messages?: Array<Thread.Message>;\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format. Keys\n     * can be a maximum of 64 characters long and values can be a maxium of 512\n     * characters long.\n     */\n    metadata?: unknown | null;\n\n    /**\n     * A set of resources that are made available to the assistant's tools in this\n     * thread. The resources are specific to the type of tool. For example, the\n     * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n     * tool requires a list of vector store IDs.\n     */\n    tool_resources?: Thread.ToolResources | null;\n  }\n\n  export namespace Thread {\n    export interface Message {\n      /**\n       * The text contents of the message.\n       */\n      content: string | Array<MessagesAPI.MessageContentPartParam>;\n\n      /**\n       * The role of the entity that is creating the message. Allowed values include:\n       *\n       * - `user`: Indicates the message is sent by an actual user and should be used in\n       *   most cases to represent user-generated messages.\n       * - `assistant`: Indicates the message is generated by the assistant. Use this\n       *   value to insert messages from the assistant into the conversation.\n       */\n      role: 'user' | 'assistant';\n\n      /**\n       * A list of files attached to the message, and the tools they should be added to.\n       */\n      attachments?: Array<Message.Attachment> | null;\n\n      /**\n       * Set of 16 key-value pairs that can be attached to an object. This can be useful\n       * for storing additional information about the object in a structured format. Keys\n       * can be a maximum of 64 characters long and values can be a maxium of 512\n       * characters long.\n       */\n      metadata?: unknown | null;\n    }\n\n    export namespace Message {\n      export interface Attachment {\n        /**\n         * The ID of the file to attach to the message.\n         */\n        file_id?: string;\n\n        /**\n         * The tools to add this file to.\n         */\n        tools?: Array<AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool>;\n      }\n    }\n\n    /**\n     * A set of resources that are made available to the assistant's tools in this\n     * thread. The resources are specific to the type of tool. For example, the\n     * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n     * tool requires a list of vector store IDs.\n     */\n    export interface ToolResources {\n      code_interpreter?: ToolResources.CodeInterpreter;\n\n      file_search?: ToolResources.FileSearch;\n    }\n\n    export namespace ToolResources {\n      export interface CodeInterpreter {\n        /**\n         * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n         * available to the `code_interpreter` tool. There can be a maximum of 20 files\n         * associated with the tool.\n         */\n        file_ids?: Array<string>;\n      }\n\n      export interface FileSearch {\n        /**\n         * The\n         * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n         * attached to this thread. There can be a maximum of 1 vector store attached to\n         * the thread.\n         */\n        vector_store_ids?: Array<string>;\n\n        /**\n         * A helper to create a\n         * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n         * with file_ids and attach it to this thread. There can be a maximum of 1 vector\n         * store attached to the thread.\n         */\n        vector_stores?: Array<FileSearch.VectorStore>;\n      }\n\n      export namespace FileSearch {\n        export interface VectorStore {\n          /**\n           * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to\n           * add to the vector store. There can be a maximum of 10000 files in a vector\n           * store.\n           */\n          file_ids?: Array<string>;\n\n          /**\n           * Set of 16 key-value pairs that can be attached to a vector store. This can be\n           * useful for storing additional information about the vector store in a structured\n           * format. Keys can be a maximum of 64 characters long and values can be a maxium\n           * of 512 characters long.\n           */\n          metadata?: unknown;\n        }\n      }\n    }\n  }\n\n  /**\n   * A set of resources that are used by the assistant's tools. The resources are\n   * specific to the type of tool. For example, the `code_interpreter` tool requires\n   * a list of file IDs, while the `file_search` tool requires a list of vector store\n   * IDs.\n   */\n  export interface ToolResources {\n    code_interpreter?: ToolResources.CodeInterpreter;\n\n    file_search?: ToolResources.FileSearch;\n  }\n\n  export namespace ToolResources {\n    export interface CodeInterpreter {\n      /**\n       * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n       * available to the `code_interpreter` tool. There can be a maximum of 20 files\n       * associated with the tool.\n       */\n      file_ids?: Array<string>;\n    }\n\n    export interface FileSearch {\n      /**\n       * The ID of the\n       * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n       * attached to this assistant. There can be a maximum of 1 vector store attached to\n       * the assistant.\n       */\n      vector_store_ids?: Array<string>;\n    }\n  }\n\n  /**\n   * Controls for how a thread will be truncated prior to the run. Use this to\n   * control the intial context window of the run.\n   */\n  export interface TruncationStrategy {\n    /**\n     * The truncation strategy to use for the thread. The default is `auto`. If set to\n     * `last_messages`, the thread will be truncated to the n most recent messages in\n     * the thread. When set to `auto`, messages in the middle of the thread will be\n     * dropped to fit the context length of the model, `max_prompt_tokens`.\n     */\n    type: 'auto' | 'last_messages';\n\n    /**\n     * The number of most recent messages from the thread when constructing the context\n     * for the run.\n     */\n    last_messages?: number | null;\n  }\n}\n\nexport type ThreadCreateAndRunStreamParams = ThreadCreateAndRunParamsBaseStream;\n\nThreads.Runs = Runs;\nThreads.Messages = Messages;\n\nexport declare namespace Threads {\n  export {\n    type AssistantResponseFormatOption as AssistantResponseFormatOption,\n    type AssistantToolChoice as AssistantToolChoice,\n    type AssistantToolChoiceFunction as AssistantToolChoiceFunction,\n    type AssistantToolChoiceOption as AssistantToolChoiceOption,\n    type Thread as Thread,\n    type ThreadDeleted as ThreadDeleted,\n    type ThreadCreateParams as ThreadCreateParams,\n    type ThreadUpdateParams as ThreadUpdateParams,\n    type ThreadCreateAndRunParams as ThreadCreateAndRunParams,\n    type ThreadCreateAndRunParamsNonStreaming as ThreadCreateAndRunParamsNonStreaming,\n    type ThreadCreateAndRunParamsStreaming as ThreadCreateAndRunParamsStreaming,\n    type ThreadCreateAndRunPollParams,\n    type ThreadCreateAndRunStreamParams,\n  };\n\n  export {\n    Runs as Runs,\n    type RequiredActionFunctionToolCall as RequiredActionFunctionToolCall,\n    type Run as Run,\n    type RunStatus as RunStatus,\n    type RunsPage as RunsPage,\n    type RunCreateParams as RunCreateParams,\n    type RunCreateParamsNonStreaming as RunCreateParamsNonStreaming,\n    type RunCreateParamsStreaming as RunCreateParamsStreaming,\n    type RunRetrieveParams as RunRetrieveParams,\n    type RunUpdateParams as RunUpdateParams,\n    type RunListParams as RunListParams,\n    type RunCancelParams as RunCancelParams,\n    type RunCreateAndPollParams,\n    type RunCreateAndStreamParams,\n    type RunStreamParams,\n    type RunSubmitToolOutputsParams as RunSubmitToolOutputsParams,\n    type RunSubmitToolOutputsParamsNonStreaming as RunSubmitToolOutputsParamsNonStreaming,\n    type RunSubmitToolOutputsParamsStreaming as RunSubmitToolOutputsParamsStreaming,\n    type RunSubmitToolOutputsAndPollParams,\n    type RunSubmitToolOutputsStreamParams,\n  };\n\n  export {\n    Messages as Messages,\n    type Annotation as Annotation,\n    type AnnotationDelta as AnnotationDelta,\n    type FileCitationAnnotation as FileCitationAnnotation,\n    type FileCitationDeltaAnnotation as FileCitationDeltaAnnotation,\n    type FilePathAnnotation as FilePathAnnotation,\n    type FilePathDeltaAnnotation as FilePathDeltaAnnotation,\n    type ImageFile as ImageFile,\n    type ImageFileContentBlock as ImageFileContentBlock,\n    type ImageFileDelta as ImageFileDelta,\n    type ImageFileDeltaBlock as ImageFileDeltaBlock,\n    type ImageURL as ImageURL,\n    type ImageURLContentBlock as ImageURLContentBlock,\n    type ImageURLDelta as ImageURLDelta,\n    type ImageURLDeltaBlock as ImageURLDeltaBlock,\n    type MessagesAPIMessage as Message,\n    type MessageContent as MessageContent,\n    type MessageContentDelta as MessageContentDelta,\n    type MessageContentPartParam as MessageContentPartParam,\n    type MessageDeleted as MessageDeleted,\n    type MessageDelta as MessageDelta,\n    type MessageDeltaEvent as MessageDeltaEvent,\n    type RefusalContentBlock as RefusalContentBlock,\n    type RefusalDeltaBlock as RefusalDeltaBlock,\n    type Text as Text,\n    type TextContentBlock as TextContentBlock,\n    type TextContentBlockParam as TextContentBlockParam,\n    type TextDelta as TextDelta,\n    type TextDeltaBlock as TextDeltaBlock,\n    type MessagesPage as MessagesPage,\n    type MessageCreateParams as MessageCreateParams,\n    type MessageRetrieveParams as MessageRetrieveParams,\n    type MessageUpdateParams as MessageUpdateParams,\n    type MessageListParams as MessageListParams,\n    type MessageDeleteParams as MessageDeleteParams,\n  };\n\n  export { AssistantStream };\n}\n"
  },
  {
    "path": "src/resources/beta/threads.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './threads/index';\n"
  },
  {
    "path": "src/resources/beta.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './beta/index';\n"
  },
  {
    "path": "src/resources/chat/chat.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as CompletionsAPI from './completions/completions';\nimport {\n  ChatCompletion,\n  ChatCompletionAllowedToolChoice,\n  ChatCompletionAllowedTools,\n  ChatCompletionAssistantMessageParam,\n  ChatCompletionAudio,\n  ChatCompletionAudioParam,\n  ChatCompletionChunk,\n  ChatCompletionContentPart,\n  ChatCompletionContentPartImage,\n  ChatCompletionContentPartInputAudio,\n  ChatCompletionContentPartRefusal,\n  ChatCompletionContentPartText,\n  ChatCompletionCreateParams,\n  ChatCompletionCreateParamsNonStreaming,\n  ChatCompletionCreateParamsStreaming,\n  ChatCompletionCustomTool,\n  ChatCompletionDeleted,\n  ChatCompletionDeveloperMessageParam,\n  ChatCompletionFunctionCallOption,\n  ChatCompletionFunctionMessageParam,\n  ChatCompletionFunctionTool,\n  ChatCompletionListParams,\n  ChatCompletionMessage,\n  ChatCompletionMessageCustomToolCall,\n  ChatCompletionMessageFunctionToolCall,\n  ChatCompletionMessageParam,\n  ChatCompletionMessageToolCall,\n  ChatCompletionModality,\n  ChatCompletionNamedToolChoice,\n  ChatCompletionNamedToolChoiceCustom,\n  ChatCompletionPredictionContent,\n  ChatCompletionReasoningEffort,\n  ChatCompletionRole,\n  ChatCompletionStoreMessage,\n  ChatCompletionStreamOptions,\n  ChatCompletionSystemMessageParam,\n  ChatCompletionTokenLogprob,\n  ChatCompletionTool,\n  ChatCompletionToolChoiceOption,\n  ChatCompletionToolMessageParam,\n  ChatCompletionUpdateParams,\n  ChatCompletionUserMessageParam,\n  ChatCompletionsPage,\n  Completions,\n} from './completions/completions';\n\nexport class Chat extends APIResource {\n  completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this._client);\n}\n\nexport type ChatModel = Shared.ChatModel;\n\nChat.Completions = Completions;\n\nexport declare namespace Chat {\n  export { type ChatModel as ChatModel };\n\n  export {\n    Completions as Completions,\n    type ChatCompletion as ChatCompletion,\n    type ChatCompletionAllowedToolChoice as ChatCompletionAllowedToolChoice,\n    type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,\n    type ChatCompletionAudio as ChatCompletionAudio,\n    type ChatCompletionAudioParam as ChatCompletionAudioParam,\n    type ChatCompletionChunk as ChatCompletionChunk,\n    type ChatCompletionContentPart as ChatCompletionContentPart,\n    type ChatCompletionContentPartImage as ChatCompletionContentPartImage,\n    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,\n    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,\n    type ChatCompletionContentPartText as ChatCompletionContentPartText,\n    type ChatCompletionCustomTool as ChatCompletionCustomTool,\n    type ChatCompletionDeleted as ChatCompletionDeleted,\n    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,\n    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,\n    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,\n    type ChatCompletionFunctionTool as ChatCompletionFunctionTool,\n    type ChatCompletionMessage as ChatCompletionMessage,\n    type ChatCompletionMessageCustomToolCall as ChatCompletionMessageCustomToolCall,\n    type ChatCompletionMessageFunctionToolCall as ChatCompletionMessageFunctionToolCall,\n    type ChatCompletionMessageParam as ChatCompletionMessageParam,\n    type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,\n    type ChatCompletionModality as ChatCompletionModality,\n    type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,\n    type ChatCompletionNamedToolChoiceCustom as ChatCompletionNamedToolChoiceCustom,\n    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,\n    type ChatCompletionRole as ChatCompletionRole,\n    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,\n    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,\n    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,\n    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,\n    type ChatCompletionTool as ChatCompletionTool,\n    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,\n    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,\n    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,\n    type ChatCompletionAllowedTools as ChatCompletionAllowedTools,\n    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,\n    type ChatCompletionsPage as ChatCompletionsPage,\n    type ChatCompletionCreateParams as ChatCompletionCreateParams,\n    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,\n    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,\n    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,\n    type ChatCompletionListParams as ChatCompletionListParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/chat/completions/completions.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ChatCompletionsAPI from './completions';\nimport * as CompletionsAPI from '../../completions';\nimport * as Shared from '../../shared';\nimport * as MessagesAPI from './messages';\nimport { MessageListParams, Messages } from './messages';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { Stream } from '../../../core/streaming';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\nimport { ChatCompletionRunner } from '../../../lib/ChatCompletionRunner';\nimport { ChatCompletionStreamingRunner } from '../../../lib/ChatCompletionStreamingRunner';\nimport { RunnerOptions } from '../../../lib/AbstractChatCompletionRunner';\nimport { ChatCompletionToolRunnerParams } from '../../../lib/ChatCompletionRunner';\nimport { ChatCompletionStreamingToolRunnerParams } from '../../../lib/ChatCompletionStreamingRunner';\nimport { ChatCompletionStream, type ChatCompletionStreamParams } from '../../../lib/ChatCompletionStream';\nimport { ExtractParsedContentFromParams, parseChatCompletion, validateInputTools } from '../../../lib/parser';\n\n/**\n * Given a list of messages comprising a conversation, the model will return a response.\n */\nexport class Completions extends APIResource {\n  messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);\n\n  /**\n   * **Starting a new project?** We recommend trying\n   * [Responses](https://platform.openai.com/docs/api-reference/responses) to take\n   * advantage of the latest OpenAI platform features. Compare\n   * [Chat Completions with Responses](https://platform.openai.com/docs/guides/responses-vs-chat-completions?api-mode=responses).\n   *\n   * ---\n   *\n   * Creates a model response for the given chat conversation. Learn more in the\n   * [text generation](https://platform.openai.com/docs/guides/text-generation),\n   * [vision](https://platform.openai.com/docs/guides/vision), and\n   * [audio](https://platform.openai.com/docs/guides/audio) guides.\n   *\n   * Parameter support can differ depending on the model used to generate the\n   * response, particularly for newer reasoning models. Parameters that are only\n   * supported for reasoning models are noted below. For the current state of\n   * unsupported parameters in reasoning models,\n   * [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).\n   *\n   * Returns a chat completion object, or a streamed sequence of chat completion\n   * chunk objects if the request is streamed.\n   *\n   * @example\n   * ```ts\n   * const chatCompletion = await client.chat.completions.create(\n   *   {\n   *     messages: [{ content: 'string', role: 'developer' }],\n   *     model: 'gpt-5.4',\n   *   },\n   * );\n   * ```\n   */\n  create(body: ChatCompletionCreateParamsNonStreaming, options?: RequestOptions): APIPromise<ChatCompletion>;\n  create(\n    body: ChatCompletionCreateParamsStreaming,\n    options?: RequestOptions,\n  ): APIPromise<Stream<ChatCompletionChunk>>;\n  create(\n    body: ChatCompletionCreateParamsBase,\n    options?: RequestOptions,\n  ): APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>;\n  create(\n    body: ChatCompletionCreateParams,\n    options?: RequestOptions,\n  ): APIPromise<ChatCompletion> | APIPromise<Stream<ChatCompletionChunk>> {\n    return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false }) as\n      | APIPromise<ChatCompletion>\n      | APIPromise<Stream<ChatCompletionChunk>>;\n  }\n\n  /**\n   * Get a stored chat completion. Only Chat Completions that have been created with\n   * the `store` parameter set to `true` will be returned.\n   *\n   * @example\n   * ```ts\n   * const chatCompletion =\n   *   await client.chat.completions.retrieve('completion_id');\n   * ```\n   */\n  retrieve(completionID: string, options?: RequestOptions): APIPromise<ChatCompletion> {\n    return this._client.get(path`/chat/completions/${completionID}`, options);\n  }\n\n  /**\n   * Modify a stored chat completion. Only Chat Completions that have been created\n   * with the `store` parameter set to `true` can be modified. Currently, the only\n   * supported modification is to update the `metadata` field.\n   *\n   * @example\n   * ```ts\n   * const chatCompletion = await client.chat.completions.update(\n   *   'completion_id',\n   *   { metadata: { foo: 'string' } },\n   * );\n   * ```\n   */\n  update(\n    completionID: string,\n    body: ChatCompletionUpdateParams,\n    options?: RequestOptions,\n  ): APIPromise<ChatCompletion> {\n    return this._client.post(path`/chat/completions/${completionID}`, { body, ...options });\n  }\n\n  /**\n   * List stored Chat Completions. Only Chat Completions that have been stored with\n   * the `store` parameter set to `true` will be returned.\n   *\n   * @example\n   * ```ts\n   * // Automatically fetches more pages as needed.\n   * for await (const chatCompletion of client.chat.completions.list()) {\n   *   // ...\n   * }\n   * ```\n   */\n  list(\n    query: ChatCompletionListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<ChatCompletionsPage, ChatCompletion> {\n    return this._client.getAPIList('/chat/completions', CursorPage<ChatCompletion>, { query, ...options });\n  }\n\n  /**\n   * Delete a stored chat completion. Only Chat Completions that have been created\n   * with the `store` parameter set to `true` can be deleted.\n   *\n   * @example\n   * ```ts\n   * const chatCompletionDeleted =\n   *   await client.chat.completions.delete('completion_id');\n   * ```\n   */\n  delete(completionID: string, options?: RequestOptions): APIPromise<ChatCompletionDeleted> {\n    return this._client.delete(path`/chat/completions/${completionID}`, options);\n  }\n\n  parse<Params extends ChatCompletionParseParams, ParsedT = ExtractParsedContentFromParams<Params>>(\n    body: Params,\n    options?: RequestOptions,\n  ): APIPromise<ParsedChatCompletion<ParsedT>> {\n    validateInputTools(body.tools);\n\n    return this._client.chat.completions\n      .create(body, {\n        ...options,\n        headers: {\n          ...options?.headers,\n          'X-Stainless-Helper-Method': 'chat.completions.parse',\n        },\n      })\n      ._thenUnwrap((completion) => parseChatCompletion(completion, body));\n  }\n\n  /**\n   * A convenience helper for using tool calls with the /chat/completions endpoint\n   * which automatically calls the JavaScript functions you provide and sends their\n   * results back to the /chat/completions endpoint, looping as long as the model\n   * requests function calls.\n   *\n   * For more details and examples, see\n   * [the docs](https://github.com/openai/openai-node#automated-function-calls)\n   */\n  runTools<\n    Params extends ChatCompletionToolRunnerParams<any>,\n    ParsedT = ExtractParsedContentFromParams<Params>,\n  >(body: Params, options?: RunnerOptions): ChatCompletionRunner<ParsedT>;\n\n  runTools<\n    Params extends ChatCompletionStreamingToolRunnerParams<any>,\n    ParsedT = ExtractParsedContentFromParams<Params>,\n  >(body: Params, options?: RunnerOptions): ChatCompletionStreamingRunner<ParsedT>;\n\n  runTools<\n    Params extends ChatCompletionToolRunnerParams<any> | ChatCompletionStreamingToolRunnerParams<any>,\n    ParsedT = ExtractParsedContentFromParams<Params>,\n  >(\n    body: Params,\n    options?: RunnerOptions,\n  ): ChatCompletionRunner<ParsedT> | ChatCompletionStreamingRunner<ParsedT> {\n    if (body.stream) {\n      return ChatCompletionStreamingRunner.runTools(\n        this._client,\n        body as ChatCompletionStreamingToolRunnerParams<any>,\n        options,\n      );\n    }\n\n    return ChatCompletionRunner.runTools(this._client, body as ChatCompletionToolRunnerParams<any>, options);\n  }\n\n  /**\n   * Creates a chat completion stream\n   */\n  stream<Params extends ChatCompletionStreamParams, ParsedT = ExtractParsedContentFromParams<Params>>(\n    body: Params,\n    options?: RequestOptions,\n  ): ChatCompletionStream<ParsedT> {\n    return ChatCompletionStream.createChatCompletion(this._client, body, options);\n  }\n}\n\nexport interface ParsedFunction extends ChatCompletionMessageFunctionToolCall.Function {\n  parsed_arguments?: unknown;\n}\n\nexport interface ParsedFunctionToolCall extends ChatCompletionMessageFunctionToolCall {\n  function: ParsedFunction;\n}\n\nexport interface ParsedChatCompletionMessage<ParsedT> extends ChatCompletionMessage {\n  parsed: ParsedT | null;\n  tool_calls?: Array<ParsedFunctionToolCall>;\n}\n\nexport interface ParsedChoice<ParsedT> extends ChatCompletion.Choice {\n  message: ParsedChatCompletionMessage<ParsedT>;\n}\n\nexport interface ParsedChatCompletion<ParsedT> extends ChatCompletion {\n  choices: Array<ParsedChoice<ParsedT>>;\n}\n\nexport type ChatCompletionParseParams = ChatCompletionCreateParamsNonStreaming;\n\nexport { ChatCompletionStreamingRunner } from '../../../lib/ChatCompletionStreamingRunner';\nexport {\n  type RunnableFunctionWithParse,\n  type RunnableFunctionWithoutParse,\n  ParsingToolFunction,\n} from '../../../lib/RunnableFunction';\nexport { type ChatCompletionToolRunnerParams } from '../../../lib/ChatCompletionRunner';\nexport { type ChatCompletionStreamingToolRunnerParams } from '../../../lib/ChatCompletionStreamingRunner';\nexport { ChatCompletionStream, type ChatCompletionStreamParams } from '../../../lib/ChatCompletionStream';\nexport { ChatCompletionRunner } from '../../../lib/ChatCompletionRunner';\n\nexport type ChatCompletionsPage = CursorPage<ChatCompletion>;\n\nexport type ChatCompletionStoreMessagesPage = CursorPage<ChatCompletionStoreMessage>;\n\n/**\n * Represents a chat completion response returned by model, based on the provided\n * input.\n */\nexport interface ChatCompletion {\n  /**\n   * A unique identifier for the chat completion.\n   */\n  id: string;\n\n  /**\n   * A list of chat completion choices. Can be more than one if `n` is greater\n   * than 1.\n   */\n  choices: Array<ChatCompletion.Choice>;\n\n  /**\n   * The Unix timestamp (in seconds) of when the chat completion was created.\n   */\n  created: number;\n\n  /**\n   * The model used for the chat completion.\n   */\n  model: string;\n\n  /**\n   * The object type, which is always `chat.completion`.\n   */\n  object: 'chat.completion';\n\n  /**\n   * Specifies the processing type used for serving the request.\n   *\n   * - If set to 'auto', then the request will be processed with the service tier\n   *   configured in the Project settings. Unless otherwise configured, the Project\n   *   will use 'default'.\n   * - If set to 'default', then the request will be processed with the standard\n   *   pricing and performance for the selected model.\n   * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n   *   '[priority](https://openai.com/api-priority-processing/)', then the request\n   *   will be processed with the corresponding service tier.\n   * - When not set, the default behavior is 'auto'.\n   *\n   * When the `service_tier` parameter is set, the response body will include the\n   * `service_tier` value based on the processing mode actually used to serve the\n   * request. This response value may be different from the value set in the\n   * parameter.\n   */\n  service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n  /**\n   * @deprecated This fingerprint represents the backend configuration that the model\n   * runs with.\n   *\n   * Can be used in conjunction with the `seed` request parameter to understand when\n   * backend changes have been made that might impact determinism.\n   */\n  system_fingerprint?: string;\n\n  /**\n   * Usage statistics for the completion request.\n   */\n  usage?: CompletionsAPI.CompletionUsage;\n}\n\nexport namespace ChatCompletion {\n  export interface Choice {\n    /**\n     * The reason the model stopped generating tokens. This will be `stop` if the model\n     * hit a natural stop point or a provided stop sequence, `length` if the maximum\n     * number of tokens specified in the request was reached, `content_filter` if\n     * content was omitted due to a flag from our content filters, `tool_calls` if the\n     * model called a tool, or `function_call` (deprecated) if the model called a\n     * function.\n     */\n    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';\n\n    /**\n     * The index of the choice in the list of choices.\n     */\n    index: number;\n\n    /**\n     * Log probability information for the choice.\n     */\n    logprobs: Choice.Logprobs | null;\n\n    /**\n     * A chat completion message generated by the model.\n     */\n    message: ChatCompletionsAPI.ChatCompletionMessage;\n  }\n\n  export namespace Choice {\n    /**\n     * Log probability information for the choice.\n     */\n    export interface Logprobs {\n      /**\n       * A list of message content tokens with log probability information.\n       */\n      content: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;\n\n      /**\n       * A list of message refusal tokens with log probability information.\n       */\n      refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;\n    }\n  }\n}\n\n/**\n * Constrains the tools available to the model to a pre-defined set.\n */\nexport interface ChatCompletionAllowedToolChoice {\n  /**\n   * Constrains the tools available to the model to a pre-defined set.\n   */\n  allowed_tools: ChatCompletionAllowedTools;\n\n  /**\n   * Allowed tool configuration type. Always `allowed_tools`.\n   */\n  type: 'allowed_tools';\n}\n\n/**\n * Messages sent by the model in response to user messages.\n */\nexport interface ChatCompletionAssistantMessageParam {\n  /**\n   * The role of the messages author, in this case `assistant`.\n   */\n  role: 'assistant';\n\n  /**\n   * Data about a previous audio response from the model.\n   * [Learn more](https://platform.openai.com/docs/guides/audio).\n   */\n  audio?: ChatCompletionAssistantMessageParam.Audio | null;\n\n  /**\n   * The contents of the assistant message. Required unless `tool_calls` or\n   * `function_call` is specified.\n   */\n  content?: string | Array<ChatCompletionContentPartText | ChatCompletionContentPartRefusal> | null;\n\n  /**\n   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n   * function that should be called, as generated by the model.\n   */\n  function_call?: ChatCompletionAssistantMessageParam.FunctionCall | null;\n\n  /**\n   * An optional name for the participant. Provides the model information to\n   * differentiate between participants of the same role.\n   */\n  name?: string;\n\n  /**\n   * The refusal message by the assistant.\n   */\n  refusal?: string | null;\n\n  /**\n   * The tool calls generated by the model, such as function calls.\n   */\n  tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionAssistantMessageParam {\n  /**\n   * Data about a previous audio response from the model.\n   * [Learn more](https://platform.openai.com/docs/guides/audio).\n   */\n  export interface Audio {\n    /**\n     * Unique identifier for a previous audio response from the model.\n     */\n    id: string;\n  }\n\n  /**\n   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n   * function that should be called, as generated by the model.\n   */\n  export interface FunctionCall {\n    /**\n     * The arguments to call the function with, as generated by the model in JSON\n     * format. Note that the model does not always generate valid JSON, and may\n     * hallucinate parameters not defined by your function schema. Validate the\n     * arguments in your code before calling your function.\n     */\n    arguments: string;\n\n    /**\n     * The name of the function to call.\n     */\n    name: string;\n  }\n}\n\n/**\n * If the audio output modality is requested, this object contains data about the\n * audio response from the model.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\nexport interface ChatCompletionAudio {\n  /**\n   * Unique identifier for this audio response.\n   */\n  id: string;\n\n  /**\n   * Base64 encoded audio bytes generated by the model, in the format specified in\n   * the request.\n   */\n  data: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when this audio response will no longer be\n   * accessible on the server for use in multi-turn conversations.\n   */\n  expires_at: number;\n\n  /**\n   * Transcript of the audio generated by the model.\n   */\n  transcript: string;\n}\n\n/**\n * Parameters for audio output. Required when audio output is requested with\n * `modalities: [\"audio\"]`.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\nexport interface ChatCompletionAudioParam {\n  /**\n   * Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,\n   * or `pcm16`.\n   */\n  format: 'wav' | 'aac' | 'mp3' | 'flac' | 'opus' | 'pcm16';\n\n  /**\n   * The voice the model uses to respond. Supported built-in voices are `alloy`,\n   * `ash`, `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, `shimmer`,\n   * `marin`, and `cedar`. You may also provide a custom voice object with an `id`,\n   * for example `{ \"id\": \"voice_1234\" }`.\n   */\n  voice:\n    | string\n    | 'alloy'\n    | 'ash'\n    | 'ballad'\n    | 'coral'\n    | 'echo'\n    | 'sage'\n    | 'shimmer'\n    | 'verse'\n    | 'marin'\n    | 'cedar'\n    | ChatCompletionAudioParam.ID;\n}\n\nexport namespace ChatCompletionAudioParam {\n  /**\n   * Custom voice reference.\n   */\n  export interface ID {\n    /**\n     * The custom voice ID, e.g. `voice_1234`.\n     */\n    id: string;\n  }\n}\n\n/**\n * Represents a streamed chunk of a chat completion response returned by the model,\n * based on the provided input.\n * [Learn more](https://platform.openai.com/docs/guides/streaming-responses).\n */\nexport interface ChatCompletionChunk {\n  /**\n   * A unique identifier for the chat completion. Each chunk has the same ID.\n   */\n  id: string;\n\n  /**\n   * A list of chat completion choices. Can contain more than one elements if `n` is\n   * greater than 1. Can also be empty for the last chunk if you set\n   * `stream_options: {\"include_usage\": true}`.\n   */\n  choices: Array<ChatCompletionChunk.Choice>;\n\n  /**\n   * The Unix timestamp (in seconds) of when the chat completion was created. Each\n   * chunk has the same timestamp.\n   */\n  created: number;\n\n  /**\n   * The model to generate the completion.\n   */\n  model: string;\n\n  /**\n   * The object type, which is always `chat.completion.chunk`.\n   */\n  object: 'chat.completion.chunk';\n\n  /**\n   * Specifies the processing type used for serving the request.\n   *\n   * - If set to 'auto', then the request will be processed with the service tier\n   *   configured in the Project settings. Unless otherwise configured, the Project\n   *   will use 'default'.\n   * - If set to 'default', then the request will be processed with the standard\n   *   pricing and performance for the selected model.\n   * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n   *   '[priority](https://openai.com/api-priority-processing/)', then the request\n   *   will be processed with the corresponding service tier.\n   * - When not set, the default behavior is 'auto'.\n   *\n   * When the `service_tier` parameter is set, the response body will include the\n   * `service_tier` value based on the processing mode actually used to serve the\n   * request. This response value may be different from the value set in the\n   * parameter.\n   */\n  service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n  /**\n   * @deprecated This fingerprint represents the backend configuration that the model\n   * runs with. Can be used in conjunction with the `seed` request parameter to\n   * understand when backend changes have been made that might impact determinism.\n   */\n  system_fingerprint?: string;\n\n  /**\n   * An optional field that will only be present when you set\n   * `stream_options: {\"include_usage\": true}` in your request. When present, it\n   * contains a null value **except for the last chunk** which contains the token\n   * usage statistics for the entire request.\n   *\n   * **NOTE:** If the stream is interrupted or cancelled, you may not receive the\n   * final usage chunk which contains the total token usage for the request.\n   */\n  usage?: CompletionsAPI.CompletionUsage | null;\n}\n\nexport namespace ChatCompletionChunk {\n  export interface Choice {\n    /**\n     * A chat completion delta generated by streamed model responses.\n     */\n    delta: Choice.Delta;\n\n    /**\n     * The reason the model stopped generating tokens. This will be `stop` if the model\n     * hit a natural stop point or a provided stop sequence, `length` if the maximum\n     * number of tokens specified in the request was reached, `content_filter` if\n     * content was omitted due to a flag from our content filters, `tool_calls` if the\n     * model called a tool, or `function_call` (deprecated) if the model called a\n     * function.\n     */\n    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | null;\n\n    /**\n     * The index of the choice in the list of choices.\n     */\n    index: number;\n\n    /**\n     * Log probability information for the choice.\n     */\n    logprobs?: Choice.Logprobs | null;\n  }\n\n  export namespace Choice {\n    /**\n     * A chat completion delta generated by streamed model responses.\n     */\n    export interface Delta {\n      /**\n       * The contents of the chunk message.\n       */\n      content?: string | null;\n\n      /**\n       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n       * function that should be called, as generated by the model.\n       */\n      function_call?: Delta.FunctionCall;\n\n      /**\n       * The refusal message generated by the model.\n       */\n      refusal?: string | null;\n\n      /**\n       * The role of the author of this message.\n       */\n      role?: 'developer' | 'system' | 'user' | 'assistant' | 'tool';\n\n      tool_calls?: Array<Delta.ToolCall>;\n    }\n\n    export namespace Delta {\n      /**\n       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n       * function that should be called, as generated by the model.\n       */\n      export interface FunctionCall {\n        /**\n         * The arguments to call the function with, as generated by the model in JSON\n         * format. Note that the model does not always generate valid JSON, and may\n         * hallucinate parameters not defined by your function schema. Validate the\n         * arguments in your code before calling your function.\n         */\n        arguments?: string;\n\n        /**\n         * The name of the function to call.\n         */\n        name?: string;\n      }\n\n      export interface ToolCall {\n        index: number;\n\n        /**\n         * The ID of the tool call.\n         */\n        id?: string;\n\n        function?: ToolCall.Function;\n\n        /**\n         * The type of the tool. Currently, only `function` is supported.\n         */\n        type?: 'function';\n      }\n\n      export namespace ToolCall {\n        export interface Function {\n          /**\n           * The arguments to call the function with, as generated by the model in JSON\n           * format. Note that the model does not always generate valid JSON, and may\n           * hallucinate parameters not defined by your function schema. Validate the\n           * arguments in your code before calling your function.\n           */\n          arguments?: string;\n\n          /**\n           * The name of the function to call.\n           */\n          name?: string;\n        }\n      }\n    }\n\n    /**\n     * Log probability information for the choice.\n     */\n    export interface Logprobs {\n      /**\n       * A list of message content tokens with log probability information.\n       */\n      content: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;\n\n      /**\n       * A list of message refusal tokens with log probability information.\n       */\n      refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;\n    }\n  }\n}\n\n/**\n * Learn about\n * [text inputs](https://platform.openai.com/docs/guides/text-generation).\n */\nexport type ChatCompletionContentPart =\n  | ChatCompletionContentPartText\n  | ChatCompletionContentPartImage\n  | ChatCompletionContentPartInputAudio\n  | ChatCompletionContentPart.File;\n\nexport namespace ChatCompletionContentPart {\n  /**\n   * Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text\n   * generation.\n   */\n  export interface File {\n    file: File.File;\n\n    /**\n     * The type of the content part. Always `file`.\n     */\n    type: 'file';\n  }\n\n  export namespace File {\n    export interface File {\n      /**\n       * The base64 encoded file data, used when passing the file to the model as a\n       * string.\n       */\n      file_data?: string;\n\n      /**\n       * The ID of an uploaded file to use as input.\n       */\n      file_id?: string;\n\n      /**\n       * The name of the file, used when passing the file to the model as a string.\n       */\n      filename?: string;\n    }\n  }\n}\n\n/**\n * Learn about [image inputs](https://platform.openai.com/docs/guides/vision).\n */\nexport interface ChatCompletionContentPartImage {\n  image_url: ChatCompletionContentPartImage.ImageURL;\n\n  /**\n   * The type of the content part.\n   */\n  type: 'image_url';\n}\n\nexport namespace ChatCompletionContentPartImage {\n  export interface ImageURL {\n    /**\n     * Either a URL of the image or the base64 encoded image data.\n     */\n    url: string;\n\n    /**\n     * Specifies the detail level of the image. Learn more in the\n     * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).\n     */\n    detail?: 'auto' | 'low' | 'high';\n  }\n}\n\n/**\n * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).\n */\nexport interface ChatCompletionContentPartInputAudio {\n  input_audio: ChatCompletionContentPartInputAudio.InputAudio;\n\n  /**\n   * The type of the content part. Always `input_audio`.\n   */\n  type: 'input_audio';\n}\n\nexport namespace ChatCompletionContentPartInputAudio {\n  export interface InputAudio {\n    /**\n     * Base64 encoded audio data.\n     */\n    data: string;\n\n    /**\n     * The format of the encoded audio data. Currently supports \"wav\" and \"mp3\".\n     */\n    format: 'wav' | 'mp3';\n  }\n}\n\nexport interface ChatCompletionContentPartRefusal {\n  /**\n   * The refusal message generated by the model.\n   */\n  refusal: string;\n\n  /**\n   * The type of the content part.\n   */\n  type: 'refusal';\n}\n\n/**\n * Learn about\n * [text inputs](https://platform.openai.com/docs/guides/text-generation).\n */\nexport interface ChatCompletionContentPartText {\n  /**\n   * The text content.\n   */\n  text: string;\n\n  /**\n   * The type of the content part.\n   */\n  type: 'text';\n}\n\n/**\n * A custom tool that processes input using a specified format.\n */\nexport interface ChatCompletionCustomTool {\n  /**\n   * Properties of the custom tool.\n   */\n  custom: ChatCompletionCustomTool.Custom;\n\n  /**\n   * The type of the custom tool. Always `custom`.\n   */\n  type: 'custom';\n}\n\nexport namespace ChatCompletionCustomTool {\n  /**\n   * Properties of the custom tool.\n   */\n  export interface Custom {\n    /**\n     * The name of the custom tool, used to identify it in tool calls.\n     */\n    name: string;\n\n    /**\n     * Optional description of the custom tool, used to provide more context.\n     */\n    description?: string;\n\n    /**\n     * The input format for the custom tool. Default is unconstrained text.\n     */\n    format?: Custom.Text | Custom.Grammar;\n  }\n\n  export namespace Custom {\n    /**\n     * Unconstrained free-form text.\n     */\n    export interface Text {\n      /**\n       * Unconstrained text format. Always `text`.\n       */\n      type: 'text';\n    }\n\n    /**\n     * A grammar defined by the user.\n     */\n    export interface Grammar {\n      /**\n       * Your chosen grammar.\n       */\n      grammar: Grammar.Grammar;\n\n      /**\n       * Grammar format. Always `grammar`.\n       */\n      type: 'grammar';\n    }\n\n    export namespace Grammar {\n      /**\n       * Your chosen grammar.\n       */\n      export interface Grammar {\n        /**\n         * The grammar definition.\n         */\n        definition: string;\n\n        /**\n         * The syntax of the grammar definition. One of `lark` or `regex`.\n         */\n        syntax: 'lark' | 'regex';\n      }\n    }\n  }\n}\n\nexport interface ChatCompletionDeleted {\n  /**\n   * The ID of the chat completion that was deleted.\n   */\n  id: string;\n\n  /**\n   * Whether the chat completion was deleted.\n   */\n  deleted: boolean;\n\n  /**\n   * The type of object being deleted.\n   */\n  object: 'chat.completion.deleted';\n}\n\n/**\n * Developer-provided instructions that the model should follow, regardless of\n * messages sent by the user. With o1 models and newer, `developer` messages\n * replace the previous `system` messages.\n */\nexport interface ChatCompletionDeveloperMessageParam {\n  /**\n   * The contents of the developer message.\n   */\n  content: string | Array<ChatCompletionContentPartText>;\n\n  /**\n   * The role of the messages author, in this case `developer`.\n   */\n  role: 'developer';\n\n  /**\n   * An optional name for the participant. Provides the model information to\n   * differentiate between participants of the same role.\n   */\n  name?: string;\n}\n\n/**\n * Specifying a particular function via `{\"name\": \"my_function\"}` forces the model\n * to call that function.\n */\nexport interface ChatCompletionFunctionCallOption {\n  /**\n   * The name of the function to call.\n   */\n  name: string;\n}\n\n/**\n * @deprecated\n */\nexport interface ChatCompletionFunctionMessageParam {\n  /**\n   * The contents of the function message.\n   */\n  content: string | null;\n\n  /**\n   * The name of the function to call.\n   */\n  name: string;\n\n  /**\n   * The role of the messages author, in this case `function`.\n   */\n  role: 'function';\n}\n\n/**\n * A function tool that can be used to generate a response.\n */\nexport interface ChatCompletionFunctionTool {\n  function: Shared.FunctionDefinition;\n\n  /**\n   * The type of the tool. Currently, only `function` is supported.\n   */\n  type: 'function';\n}\n\n/**\n * A chat completion message generated by the model.\n */\nexport interface ChatCompletionMessage {\n  /**\n   * The contents of the message.\n   */\n  content: string | null;\n\n  /**\n   * The refusal message generated by the model.\n   */\n  refusal: string | null;\n\n  /**\n   * The role of the author of this message.\n   */\n  role: 'assistant';\n\n  /**\n   * Annotations for the message, when applicable, as when using the\n   * [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).\n   */\n  annotations?: Array<ChatCompletionMessage.Annotation>;\n\n  /**\n   * If the audio output modality is requested, this object contains data about the\n   * audio response from the model.\n   * [Learn more](https://platform.openai.com/docs/guides/audio).\n   */\n  audio?: ChatCompletionAudio | null;\n\n  /**\n   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n   * function that should be called, as generated by the model.\n   */\n  function_call?: ChatCompletionMessage.FunctionCall | null;\n\n  /**\n   * The tool calls generated by the model, such as function calls.\n   */\n  tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionMessage {\n  /**\n   * A URL citation when using web search.\n   */\n  export interface Annotation {\n    /**\n     * The type of the URL citation. Always `url_citation`.\n     */\n    type: 'url_citation';\n\n    /**\n     * A URL citation when using web search.\n     */\n    url_citation: Annotation.URLCitation;\n  }\n\n  export namespace Annotation {\n    /**\n     * A URL citation when using web search.\n     */\n    export interface URLCitation {\n      /**\n       * The index of the last character of the URL citation in the message.\n       */\n      end_index: number;\n\n      /**\n       * The index of the first character of the URL citation in the message.\n       */\n      start_index: number;\n\n      /**\n       * The title of the web resource.\n       */\n      title: string;\n\n      /**\n       * The URL of the web resource.\n       */\n      url: string;\n    }\n  }\n\n  /**\n   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n   * function that should be called, as generated by the model.\n   */\n  export interface FunctionCall {\n    /**\n     * The arguments to call the function with, as generated by the model in JSON\n     * format. Note that the model does not always generate valid JSON, and may\n     * hallucinate parameters not defined by your function schema. Validate the\n     * arguments in your code before calling your function.\n     */\n    arguments: string;\n\n    /**\n     * The name of the function to call.\n     */\n    name: string;\n  }\n}\n\n/**\n * A call to a custom tool created by the model.\n */\nexport interface ChatCompletionMessageCustomToolCall {\n  /**\n   * The ID of the tool call.\n   */\n  id: string;\n\n  /**\n   * The custom tool that the model called.\n   */\n  custom: ChatCompletionMessageCustomToolCall.Custom;\n\n  /**\n   * The type of the tool. Always `custom`.\n   */\n  type: 'custom';\n}\n\nexport namespace ChatCompletionMessageCustomToolCall {\n  /**\n   * The custom tool that the model called.\n   */\n  export interface Custom {\n    /**\n     * The input for the custom tool call generated by the model.\n     */\n    input: string;\n\n    /**\n     * The name of the custom tool to call.\n     */\n    name: string;\n  }\n}\n\n/**\n * A call to a function tool created by the model.\n */\nexport interface ChatCompletionMessageFunctionToolCall {\n  /**\n   * The ID of the tool call.\n   */\n  id: string;\n\n  /**\n   * The function that the model called.\n   */\n  function: ChatCompletionMessageFunctionToolCall.Function;\n\n  /**\n   * The type of the tool. Currently, only `function` is supported.\n   */\n  type: 'function';\n}\n\nexport namespace ChatCompletionMessageFunctionToolCall {\n  /**\n   * The function that the model called.\n   */\n  export interface Function {\n    /**\n     * The arguments to call the function with, as generated by the model in JSON\n     * format. Note that the model does not always generate valid JSON, and may\n     * hallucinate parameters not defined by your function schema. Validate the\n     * arguments in your code before calling your function.\n     */\n    arguments: string;\n\n    /**\n     * The name of the function to call.\n     */\n    name: string;\n  }\n}\n\n/**\n * Developer-provided instructions that the model should follow, regardless of\n * messages sent by the user. With o1 models and newer, `developer` messages\n * replace the previous `system` messages.\n */\nexport type ChatCompletionMessageParam =\n  | ChatCompletionDeveloperMessageParam\n  | ChatCompletionSystemMessageParam\n  | ChatCompletionUserMessageParam\n  | ChatCompletionAssistantMessageParam\n  | ChatCompletionToolMessageParam\n  | ChatCompletionFunctionMessageParam;\n\n/**\n * A call to a function tool created by the model.\n */\nexport type ChatCompletionMessageToolCall =\n  | ChatCompletionMessageFunctionToolCall\n  | ChatCompletionMessageCustomToolCall;\n\nexport type ChatCompletionModality = 'text' | 'audio';\n\n/**\n * Specifies a tool the model should use. Use to force the model to call a specific\n * function.\n */\nexport interface ChatCompletionNamedToolChoice {\n  function: ChatCompletionNamedToolChoice.Function;\n\n  /**\n   * For function calling, the type is always `function`.\n   */\n  type: 'function';\n}\n\nexport namespace ChatCompletionNamedToolChoice {\n  export interface Function {\n    /**\n     * The name of the function to call.\n     */\n    name: string;\n  }\n}\n\n/**\n * Specifies a tool the model should use. Use to force the model to call a specific\n * custom tool.\n */\nexport interface ChatCompletionNamedToolChoiceCustom {\n  custom: ChatCompletionNamedToolChoiceCustom.Custom;\n\n  /**\n   * For custom tool calling, the type is always `custom`.\n   */\n  type: 'custom';\n}\n\nexport namespace ChatCompletionNamedToolChoiceCustom {\n  export interface Custom {\n    /**\n     * The name of the custom tool to call.\n     */\n    name: string;\n  }\n}\n\n/**\n * Static predicted output content, such as the content of a text file that is\n * being regenerated.\n */\nexport interface ChatCompletionPredictionContent {\n  /**\n   * The content that should be matched when generating a model response. If\n   * generated tokens would match this content, the entire model response can be\n   * returned much more quickly.\n   */\n  content: string | Array<ChatCompletionContentPartText>;\n\n  /**\n   * The type of the predicted content you want to provide. This type is currently\n   * always `content`.\n   */\n  type: 'content';\n}\n\n/**\n * The role of the author of a message\n */\nexport type ChatCompletionRole = 'developer' | 'system' | 'user' | 'assistant' | 'tool' | 'function';\n\n/**\n * A chat completion message generated by the model.\n */\nexport interface ChatCompletionStoreMessage extends ChatCompletionMessage {\n  /**\n   * The identifier of the chat message.\n   */\n  id: string;\n\n  /**\n   * If a content parts array was provided, this is an array of `text` and\n   * `image_url` parts. Otherwise, null.\n   */\n  content_parts?: Array<ChatCompletionContentPartText | ChatCompletionContentPartImage> | null;\n}\n\n/**\n * Options for streaming response. Only set this when you set `stream: true`.\n */\nexport interface ChatCompletionStreamOptions {\n  /**\n   * When true, stream obfuscation will be enabled. Stream obfuscation adds random\n   * characters to an `obfuscation` field on streaming delta events to normalize\n   * payload sizes as a mitigation to certain side-channel attacks. These obfuscation\n   * fields are included by default, but add a small amount of overhead to the data\n   * stream. You can set `include_obfuscation` to false to optimize for bandwidth if\n   * you trust the network links between your application and the OpenAI API.\n   */\n  include_obfuscation?: boolean;\n\n  /**\n   * If set, an additional chunk will be streamed before the `data: [DONE]` message.\n   * The `usage` field on this chunk shows the token usage statistics for the entire\n   * request, and the `choices` field will always be an empty array.\n   *\n   * All other chunks will also include a `usage` field, but with a null value.\n   * **NOTE:** If the stream is interrupted, you may not receive the final usage\n   * chunk which contains the total token usage for the request.\n   */\n  include_usage?: boolean;\n}\n\n/**\n * Developer-provided instructions that the model should follow, regardless of\n * messages sent by the user. With o1 models and newer, use `developer` messages\n * for this purpose instead.\n */\nexport interface ChatCompletionSystemMessageParam {\n  /**\n   * The contents of the system message.\n   */\n  content: string | Array<ChatCompletionContentPartText>;\n\n  /**\n   * The role of the messages author, in this case `system`.\n   */\n  role: 'system';\n\n  /**\n   * An optional name for the participant. Provides the model information to\n   * differentiate between participants of the same role.\n   */\n  name?: string;\n}\n\nexport interface ChatCompletionTokenLogprob {\n  /**\n   * The token.\n   */\n  token: string;\n\n  /**\n   * A list of integers representing the UTF-8 bytes representation of the token.\n   * Useful in instances where characters are represented by multiple tokens and\n   * their byte representations must be combined to generate the correct text\n   * representation. Can be `null` if there is no bytes representation for the token.\n   */\n  bytes: Array<number> | null;\n\n  /**\n   * The log probability of this token, if it is within the top 20 most likely\n   * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very\n   * unlikely.\n   */\n  logprob: number;\n\n  /**\n   * List of the most likely tokens and their log probability, at this token\n   * position. In rare cases, there may be fewer than the number of requested\n   * `top_logprobs` returned.\n   */\n  top_logprobs: Array<ChatCompletionTokenLogprob.TopLogprob>;\n}\n\nexport namespace ChatCompletionTokenLogprob {\n  export interface TopLogprob {\n    /**\n     * The token.\n     */\n    token: string;\n\n    /**\n     * A list of integers representing the UTF-8 bytes representation of the token.\n     * Useful in instances where characters are represented by multiple tokens and\n     * their byte representations must be combined to generate the correct text\n     * representation. Can be `null` if there is no bytes representation for the token.\n     */\n    bytes: Array<number> | null;\n\n    /**\n     * The log probability of this token, if it is within the top 20 most likely\n     * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very\n     * unlikely.\n     */\n    logprob: number;\n  }\n}\n\n/**\n * A function tool that can be used to generate a response.\n */\nexport type ChatCompletionTool = ChatCompletionFunctionTool | ChatCompletionCustomTool;\n\n/**\n * Controls which (if any) tool is called by the model. `none` means the model will\n * not call any tool and instead generates a message. `auto` means the model can\n * pick between generating a message or calling one or more tools. `required` means\n * the model must call one or more tools. Specifying a particular tool via\n * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n * call that tool.\n *\n * `none` is the default when no tools are present. `auto` is the default if tools\n * are present.\n */\nexport type ChatCompletionToolChoiceOption =\n  | 'none'\n  | 'auto'\n  | 'required'\n  | ChatCompletionAllowedToolChoice\n  | ChatCompletionNamedToolChoice\n  | ChatCompletionNamedToolChoiceCustom;\n\nexport interface ChatCompletionToolMessageParam {\n  /**\n   * The contents of the tool message.\n   */\n  content: string | Array<ChatCompletionContentPartText>;\n\n  /**\n   * The role of the messages author, in this case `tool`.\n   */\n  role: 'tool';\n\n  /**\n   * Tool call that this message is responding to.\n   */\n  tool_call_id: string;\n}\n\n/**\n * Messages sent by an end user, containing prompts or additional context\n * information.\n */\nexport interface ChatCompletionUserMessageParam {\n  /**\n   * The contents of the user message.\n   */\n  content: string | Array<ChatCompletionContentPart>;\n\n  /**\n   * The role of the messages author, in this case `user`.\n   */\n  role: 'user';\n\n  /**\n   * An optional name for the participant. Provides the model information to\n   * differentiate between participants of the same role.\n   */\n  name?: string;\n}\n\n/**\n * Constrains the tools available to the model to a pre-defined set.\n */\nexport interface ChatCompletionAllowedTools {\n  /**\n   * Constrains the tools available to the model to a pre-defined set.\n   *\n   * `auto` allows the model to pick from among the allowed tools and generate a\n   * message.\n   *\n   * `required` requires the model to call one or more of the allowed tools.\n   */\n  mode: 'auto' | 'required';\n\n  /**\n   * A list of tool definitions that the model should be allowed to call.\n   *\n   * For the Chat Completions API, the list of tool definitions might look like:\n   *\n   * ```json\n   * [\n   *   { \"type\": \"function\", \"function\": { \"name\": \"get_weather\" } },\n   *   { \"type\": \"function\", \"function\": { \"name\": \"get_time\" } }\n   * ]\n   * ```\n   */\n  tools: Array<{ [key: string]: unknown }>;\n}\n\nexport type ChatCompletionReasoningEffort = Shared.ReasoningEffort | null;\n\nexport type ChatCompletionCreateParams =\n  | ChatCompletionCreateParamsNonStreaming\n  | ChatCompletionCreateParamsStreaming;\n\nexport interface ChatCompletionCreateParamsBase {\n  /**\n   * A list of messages comprising the conversation so far. Depending on the\n   * [model](https://platform.openai.com/docs/models) you use, different message\n   * types (modalities) are supported, like\n   * [text](https://platform.openai.com/docs/guides/text-generation),\n   * [images](https://platform.openai.com/docs/guides/vision), and\n   * [audio](https://platform.openai.com/docs/guides/audio).\n   */\n  messages: Array<ChatCompletionMessageParam>;\n\n  /**\n   * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a\n   * wide range of models with different capabilities, performance characteristics,\n   * and price points. Refer to the\n   * [model guide](https://platform.openai.com/docs/models) to browse and compare\n   * available models.\n   */\n  model: (string & {}) | Shared.ChatModel;\n\n  /**\n   * Parameters for audio output. Required when audio output is requested with\n   * `modalities: [\"audio\"]`.\n   * [Learn more](https://platform.openai.com/docs/guides/audio).\n   */\n  audio?: ChatCompletionAudioParam | null;\n\n  /**\n   * Number between -2.0 and 2.0. Positive values penalize new tokens based on their\n   * existing frequency in the text so far, decreasing the model's likelihood to\n   * repeat the same line verbatim.\n   */\n  frequency_penalty?: number | null;\n\n  /**\n   * @deprecated Deprecated in favor of `tool_choice`.\n   *\n   * Controls which (if any) function is called by the model.\n   *\n   * `none` means the model will not call a function and instead generates a message.\n   *\n   * `auto` means the model can pick between generating a message or calling a\n   * function.\n   *\n   * Specifying a particular function via `{\"name\": \"my_function\"}` forces the model\n   * to call that function.\n   *\n   * `none` is the default when no functions are present. `auto` is the default if\n   * functions are present.\n   */\n  function_call?: 'none' | 'auto' | ChatCompletionFunctionCallOption;\n\n  /**\n   * @deprecated Deprecated in favor of `tools`.\n   *\n   * A list of functions the model may generate JSON inputs for.\n   */\n  functions?: Array<ChatCompletionCreateParams.Function>;\n\n  /**\n   * Modify the likelihood of specified tokens appearing in the completion.\n   *\n   * Accepts a JSON object that maps tokens (specified by their token ID in the\n   * tokenizer) to an associated bias value from -100 to 100. Mathematically, the\n   * bias is added to the logits generated by the model prior to sampling. The exact\n   * effect will vary per model, but values between -1 and 1 should decrease or\n   * increase likelihood of selection; values like -100 or 100 should result in a ban\n   * or exclusive selection of the relevant token.\n   */\n  logit_bias?: { [key: string]: number } | null;\n\n  /**\n   * Whether to return log probabilities of the output tokens or not. If true,\n   * returns the log probabilities of each output token returned in the `content` of\n   * `message`.\n   */\n  logprobs?: boolean | null;\n\n  /**\n   * An upper bound for the number of tokens that can be generated for a completion,\n   * including visible output tokens and\n   * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).\n   */\n  max_completion_tokens?: number | null;\n\n  /**\n   * @deprecated The maximum number of [tokens](/tokenizer) that can be generated in\n   * the chat completion. This value can be used to control\n   * [costs](https://openai.com/api/pricing/) for text generated via API.\n   *\n   * This value is now deprecated in favor of `max_completion_tokens`, and is not\n   * compatible with\n   * [o-series models](https://platform.openai.com/docs/guides/reasoning).\n   */\n  max_tokens?: number | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * Output types that you would like the model to generate. Most models are capable\n   * of generating text, which is the default:\n   *\n   * `[\"text\"]`\n   *\n   * The `gpt-4o-audio-preview` model can also be used to\n   * [generate audio](https://platform.openai.com/docs/guides/audio). To request that\n   * this model generate both text and audio responses, you can use:\n   *\n   * `[\"text\", \"audio\"]`\n   */\n  modalities?: Array<'text' | 'audio'> | null;\n\n  /**\n   * How many chat completion choices to generate for each input message. Note that\n   * you will be charged based on the number of generated tokens across all of the\n   * choices. Keep `n` as `1` to minimize costs.\n   */\n  n?: number | null;\n\n  /**\n   * Whether to enable\n   * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)\n   * during tool use.\n   */\n  parallel_tool_calls?: boolean;\n\n  /**\n   * Static predicted output content, such as the content of a text file that is\n   * being regenerated.\n   */\n  prediction?: ChatCompletionPredictionContent | null;\n\n  /**\n   * Number between -2.0 and 2.0. Positive values penalize new tokens based on\n   * whether they appear in the text so far, increasing the model's likelihood to\n   * talk about new topics.\n   */\n  presence_penalty?: number | null;\n\n  /**\n   * Used by OpenAI to cache responses for similar requests to optimize your cache\n   * hit rates. Replaces the `user` field.\n   * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n   */\n  prompt_cache_key?: string;\n\n  /**\n   * The retention policy for the prompt cache. Set to `24h` to enable extended\n   * prompt caching, which keeps cached prefixes active for longer, up to a maximum\n   * of 24 hours.\n   * [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).\n   */\n  prompt_cache_retention?: 'in-memory' | '24h' | null;\n\n  /**\n   * Constrains effort on reasoning for\n   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n   * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n   * Reducing reasoning effort can result in faster responses and fewer tokens used\n   * on reasoning in a response.\n   *\n   * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n   *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n   *   calls are supported for all reasoning values in gpt-5.1.\n   * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n   *   support `none`.\n   * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n   * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n   */\n  reasoning_effort?: Shared.ReasoningEffort | null;\n\n  /**\n   * An object specifying the format that the model must output.\n   *\n   * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n   * Outputs which ensures the model will match your supplied JSON schema. Learn more\n   * in the\n   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n   *\n   * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n   * ensures the message the model generates is valid JSON. Using `json_schema` is\n   * preferred for models that support it.\n   */\n  response_format?:\n    | Shared.ResponseFormatText\n    | Shared.ResponseFormatJSONSchema\n    | Shared.ResponseFormatJSONObject;\n\n  /**\n   * A stable identifier used to help detect users of your application that may be\n   * violating OpenAI's usage policies. The IDs should be a string that uniquely\n   * identifies each user, with a maximum length of 64 characters. We recommend\n   * hashing their username or email address, in order to avoid sending us any\n   * identifying information.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n   */\n  safety_identifier?: string;\n\n  /**\n   * @deprecated This feature is in Beta. If specified, our system will make a best\n   * effort to sample deterministically, such that repeated requests with the same\n   * `seed` and parameters should return the same result. Determinism is not\n   * guaranteed, and you should refer to the `system_fingerprint` response parameter\n   * to monitor changes in the backend.\n   */\n  seed?: number | null;\n\n  /**\n   * Specifies the processing type used for serving the request.\n   *\n   * - If set to 'auto', then the request will be processed with the service tier\n   *   configured in the Project settings. Unless otherwise configured, the Project\n   *   will use 'default'.\n   * - If set to 'default', then the request will be processed with the standard\n   *   pricing and performance for the selected model.\n   * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n   *   '[priority](https://openai.com/api-priority-processing/)', then the request\n   *   will be processed with the corresponding service tier.\n   * - When not set, the default behavior is 'auto'.\n   *\n   * When the `service_tier` parameter is set, the response body will include the\n   * `service_tier` value based on the processing mode actually used to serve the\n   * request. This response value may be different from the value set in the\n   * parameter.\n   */\n  service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n  /**\n   * Not supported with latest reasoning models `o3` and `o4-mini`.\n   *\n   * Up to 4 sequences where the API will stop generating further tokens. The\n   * returned text will not contain the stop sequence.\n   */\n  stop?: string | null | Array<string>;\n\n  /**\n   * Whether or not to store the output of this chat completion request for use in\n   * our [model distillation](https://platform.openai.com/docs/guides/distillation)\n   * or [evals](https://platform.openai.com/docs/guides/evals) products.\n   *\n   * Supports text and image inputs. Note: image inputs over 8MB will be dropped.\n   */\n  store?: boolean | null;\n\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section below](https://platform.openai.com/docs/api-reference/chat/streaming)\n   * for more information, along with the\n   * [streaming responses](https://platform.openai.com/docs/guides/streaming-responses)\n   * guide for more information on how to handle the streaming events.\n   */\n  stream?: boolean | null;\n\n  /**\n   * Options for streaming response. Only set this when you set `stream: true`.\n   */\n  stream_options?: ChatCompletionStreamOptions | null;\n\n  /**\n   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n   * make the output more random, while lower values like 0.2 will make it more\n   * focused and deterministic. We generally recommend altering this or `top_p` but\n   * not both.\n   */\n  temperature?: number | null;\n\n  /**\n   * Controls which (if any) tool is called by the model. `none` means the model will\n   * not call any tool and instead generates a message. `auto` means the model can\n   * pick between generating a message or calling one or more tools. `required` means\n   * the model must call one or more tools. Specifying a particular tool via\n   * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n   * call that tool.\n   *\n   * `none` is the default when no tools are present. `auto` is the default if tools\n   * are present.\n   */\n  tool_choice?: ChatCompletionToolChoiceOption;\n\n  /**\n   * A list of tools the model may call. You can provide either\n   * [custom tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)\n   * or [function tools](https://platform.openai.com/docs/guides/function-calling).\n   */\n  tools?: Array<ChatCompletionTool>;\n\n  /**\n   * An integer between 0 and 20 specifying the number of most likely tokens to\n   * return at each token position, each with an associated log probability.\n   * `logprobs` must be set to `true` if this parameter is used.\n   */\n  top_logprobs?: number | null;\n\n  /**\n   * An alternative to sampling with temperature, called nucleus sampling, where the\n   * model considers the results of the tokens with top_p probability mass. So 0.1\n   * means only the tokens comprising the top 10% probability mass are considered.\n   *\n   * We generally recommend altering this or `temperature` but not both.\n   */\n  top_p?: number | null;\n\n  /**\n   * @deprecated This field is being replaced by `safety_identifier` and\n   * `prompt_cache_key`. Use `prompt_cache_key` instead to maintain caching\n   * optimizations. A stable identifier for your end-users. Used to boost cache hit\n   * rates by better bucketing similar requests and to help OpenAI detect and prevent\n   * abuse.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n   */\n  user?: string;\n\n  /**\n   * Constrains the verbosity of the model's response. Lower values will result in\n   * more concise responses, while higher values will result in more verbose\n   * responses. Currently supported values are `low`, `medium`, and `high`.\n   */\n  verbosity?: 'low' | 'medium' | 'high' | null;\n\n  /**\n   * This tool searches the web for relevant results to use in a response. Learn more\n   * about the\n   * [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).\n   */\n  web_search_options?: ChatCompletionCreateParams.WebSearchOptions;\n}\n\nexport namespace ChatCompletionCreateParams {\n  /**\n   * @deprecated\n   */\n  export interface Function {\n    /**\n     * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain\n     * underscores and dashes, with a maximum length of 64.\n     */\n    name: string;\n\n    /**\n     * A description of what the function does, used by the model to choose when and\n     * how to call the function.\n     */\n    description?: string;\n\n    /**\n     * The parameters the functions accepts, described as a JSON Schema object. See the\n     * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,\n     * and the\n     * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for\n     * documentation about the format.\n     *\n     * Omitting `parameters` defines a function with an empty parameter list.\n     */\n    parameters?: Shared.FunctionParameters;\n  }\n\n  /**\n   * This tool searches the web for relevant results to use in a response. Learn more\n   * about the\n   * [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).\n   */\n  export interface WebSearchOptions {\n    /**\n     * High level guidance for the amount of context window space to use for the\n     * search. One of `low`, `medium`, or `high`. `medium` is the default.\n     */\n    search_context_size?: 'low' | 'medium' | 'high';\n\n    /**\n     * Approximate location parameters for the search.\n     */\n    user_location?: WebSearchOptions.UserLocation | null;\n  }\n\n  export namespace WebSearchOptions {\n    /**\n     * Approximate location parameters for the search.\n     */\n    export interface UserLocation {\n      /**\n       * Approximate location parameters for the search.\n       */\n      approximate: UserLocation.Approximate;\n\n      /**\n       * The type of location approximation. Always `approximate`.\n       */\n      type: 'approximate';\n    }\n\n    export namespace UserLocation {\n      /**\n       * Approximate location parameters for the search.\n       */\n      export interface Approximate {\n        /**\n         * Free text input for the city of the user, e.g. `San Francisco`.\n         */\n        city?: string;\n\n        /**\n         * The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of\n         * the user, e.g. `US`.\n         */\n        country?: string;\n\n        /**\n         * Free text input for the region of the user, e.g. `California`.\n         */\n        region?: string;\n\n        /**\n         * The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the\n         * user, e.g. `America/Los_Angeles`.\n         */\n        timezone?: string;\n      }\n    }\n  }\n\n  export type ChatCompletionCreateParamsNonStreaming =\n    ChatCompletionsAPI.ChatCompletionCreateParamsNonStreaming;\n  export type ChatCompletionCreateParamsStreaming = ChatCompletionsAPI.ChatCompletionCreateParamsStreaming;\n}\n\nexport interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section below](https://platform.openai.com/docs/api-reference/chat/streaming)\n   * for more information, along with the\n   * [streaming responses](https://platform.openai.com/docs/guides/streaming-responses)\n   * guide for more information on how to handle the streaming events.\n   */\n  stream?: false | null;\n}\n\nexport interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase {\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section below](https://platform.openai.com/docs/api-reference/chat/streaming)\n   * for more information, along with the\n   * [streaming responses](https://platform.openai.com/docs/guides/streaming-responses)\n   * guide for more information on how to handle the streaming events.\n   */\n  stream: true;\n}\n\nexport interface ChatCompletionUpdateParams {\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n}\n\nexport interface ChatCompletionListParams extends CursorPageParams {\n  /**\n   * A list of metadata keys to filter the Chat Completions by. Example:\n   *\n   * `metadata[key1]=value1&metadata[key2]=value2`\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The model used to generate the Chat Completions.\n   */\n  model?: string;\n\n  /**\n   * Sort order for Chat Completions by timestamp. Use `asc` for ascending order or\n   * `desc` for descending order. Defaults to `asc`.\n   */\n  order?: 'asc' | 'desc';\n}\n\nCompletions.Messages = Messages;\n\nexport declare namespace Completions {\n  export {\n    type ChatCompletion as ChatCompletion,\n    type ChatCompletionAllowedToolChoice as ChatCompletionAllowedToolChoice,\n    type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,\n    type ChatCompletionAudio as ChatCompletionAudio,\n    type ChatCompletionAudioParam as ChatCompletionAudioParam,\n    type ChatCompletionChunk as ChatCompletionChunk,\n    type ChatCompletionContentPart as ChatCompletionContentPart,\n    type ChatCompletionContentPartImage as ChatCompletionContentPartImage,\n    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,\n    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,\n    type ChatCompletionContentPartText as ChatCompletionContentPartText,\n    type ChatCompletionCustomTool as ChatCompletionCustomTool,\n    type ChatCompletionDeleted as ChatCompletionDeleted,\n    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,\n    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,\n    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,\n    type ChatCompletionFunctionTool as ChatCompletionFunctionTool,\n    type ChatCompletionMessage as ChatCompletionMessage,\n    type ChatCompletionMessageCustomToolCall as ChatCompletionMessageCustomToolCall,\n    type ChatCompletionMessageFunctionToolCall as ChatCompletionMessageFunctionToolCall,\n    type ChatCompletionMessageParam as ChatCompletionMessageParam,\n    type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,\n    type ChatCompletionModality as ChatCompletionModality,\n    type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,\n    type ChatCompletionNamedToolChoiceCustom as ChatCompletionNamedToolChoiceCustom,\n    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,\n    type ChatCompletionRole as ChatCompletionRole,\n    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,\n    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,\n    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,\n    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,\n    type ChatCompletionTool as ChatCompletionTool,\n    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,\n    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,\n    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,\n    type ChatCompletionAllowedTools as ChatCompletionAllowedTools,\n    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,\n    type ChatCompletionsPage as ChatCompletionsPage,\n    type ChatCompletionCreateParams as ChatCompletionCreateParams,\n    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,\n    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,\n    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,\n    type ChatCompletionListParams as ChatCompletionListParams,\n  };\n\n  export { Messages as Messages, type MessageListParams as MessageListParams };\n}\n"
  },
  {
    "path": "src/resources/chat/completions/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport {\n  Completions,\n  type ChatCompletion,\n  type ChatCompletionAllowedToolChoice,\n  type ChatCompletionAssistantMessageParam,\n  type ChatCompletionAudio,\n  type ChatCompletionAudioParam,\n  type ChatCompletionChunk,\n  type ChatCompletionContentPart,\n  type ChatCompletionContentPartImage,\n  type ChatCompletionContentPartInputAudio,\n  type ChatCompletionContentPartRefusal,\n  type ChatCompletionContentPartText,\n  type ChatCompletionCustomTool,\n  type ChatCompletionDeleted,\n  type ChatCompletionDeveloperMessageParam,\n  type ChatCompletionFunctionCallOption,\n  type ChatCompletionFunctionMessageParam,\n  type ChatCompletionFunctionTool,\n  type ChatCompletionMessage,\n  type ChatCompletionMessageCustomToolCall,\n  type ChatCompletionMessageFunctionToolCall,\n  type ChatCompletionMessageParam,\n  type ChatCompletionMessageToolCall,\n  type ChatCompletionModality,\n  type ChatCompletionNamedToolChoice,\n  type ChatCompletionNamedToolChoiceCustom,\n  type ChatCompletionPredictionContent,\n  type ChatCompletionRole,\n  type ChatCompletionStoreMessage,\n  type ChatCompletionStreamOptions,\n  type ChatCompletionSystemMessageParam,\n  type ChatCompletionTokenLogprob,\n  type ChatCompletionTool,\n  type ChatCompletionToolChoiceOption,\n  type ChatCompletionToolMessageParam,\n  type ChatCompletionUserMessageParam,\n  type ChatCompletionAllowedTools,\n  type ChatCompletionCreateParams,\n  type ChatCompletionCreateParamsNonStreaming,\n  type ChatCompletionCreateParamsStreaming,\n  type ChatCompletionUpdateParams,\n  type ChatCompletionListParams,\n  type ChatCompletionStoreMessagesPage,\n  type ChatCompletionsPage,\n} from './completions';\nexport * from './completions';\nexport { Messages, type MessageListParams } from './messages';\n"
  },
  {
    "path": "src/resources/chat/completions/messages.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as CompletionsAPI from './completions';\nimport { ChatCompletionStoreMessagesPage } from './completions';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Given a list of messages comprising a conversation, the model will return a response.\n */\nexport class Messages extends APIResource {\n  /**\n   * Get the messages in a stored chat completion. Only Chat Completions that have\n   * been created with the `store` parameter set to `true` will be returned.\n   *\n   * @example\n   * ```ts\n   * // Automatically fetches more pages as needed.\n   * for await (const chatCompletionStoreMessage of client.chat.completions.messages.list(\n   *   'completion_id',\n   * )) {\n   *   // ...\n   * }\n   * ```\n   */\n  list(\n    completionID: string,\n    query: MessageListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage> {\n    return this._client.getAPIList(\n      path`/chat/completions/${completionID}/messages`,\n      CursorPage<CompletionsAPI.ChatCompletionStoreMessage>,\n      { query, ...options },\n    );\n  }\n}\n\nexport interface MessageListParams extends CursorPageParams {\n  /**\n   * Sort order for messages by timestamp. Use `asc` for ascending order or `desc`\n   * for descending order. Defaults to `asc`.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport declare namespace Messages {\n  export { type MessageListParams as MessageListParams };\n}\n\nexport { type ChatCompletionStoreMessagesPage };\n"
  },
  {
    "path": "src/resources/chat/completions.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './completions/index';\n"
  },
  {
    "path": "src/resources/chat/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Chat } from './chat';\nexport {\n  Completions,\n  type ChatCompletion,\n  type ChatCompletionAllowedToolChoice,\n  type ChatCompletionAssistantMessageParam,\n  type ChatCompletionAudio,\n  type ChatCompletionAudioParam,\n  type ChatCompletionChunk,\n  type ChatCompletionContentPart,\n  type ChatCompletionContentPartImage,\n  type ChatCompletionContentPartInputAudio,\n  type ChatCompletionContentPartRefusal,\n  type ChatCompletionContentPartText,\n  type ChatCompletionCustomTool,\n  type ChatCompletionDeleted,\n  type ChatCompletionDeveloperMessageParam,\n  type ChatCompletionFunctionCallOption,\n  type ChatCompletionFunctionMessageParam,\n  type ChatCompletionFunctionTool,\n  type ChatCompletionMessage,\n  type ChatCompletionMessageCustomToolCall,\n  type ChatCompletionMessageFunctionToolCall,\n  type ChatCompletionMessageParam,\n  type ChatCompletionMessageToolCall,\n  type ChatCompletionModality,\n  type ChatCompletionNamedToolChoice,\n  type ChatCompletionNamedToolChoiceCustom,\n  type ChatCompletionPredictionContent,\n  type ChatCompletionRole,\n  type ChatCompletionStoreMessage,\n  type ChatCompletionStreamOptions,\n  type ChatCompletionSystemMessageParam,\n  type ChatCompletionTokenLogprob,\n  type ChatCompletionTool,\n  type ChatCompletionToolChoiceOption,\n  type ChatCompletionToolMessageParam,\n  type ChatCompletionUserMessageParam,\n  type ChatCompletionAllowedTools,\n  type ChatCompletionCreateParams,\n  type ChatCompletionCreateParamsNonStreaming,\n  type ChatCompletionCreateParamsStreaming,\n  type ChatCompletionUpdateParams,\n  type ChatCompletionListParams,\n  type ChatCompletionStoreMessagesPage,\n  type ChatCompletionsPage,\n} from './completions/index';\n"
  },
  {
    "path": "src/resources/chat.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './chat/index';\n"
  },
  {
    "path": "src/resources/completions.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport * as CompletionsAPI from './completions';\nimport * as ChatCompletionsAPI from './chat/completions/completions';\nimport { APIPromise } from '../core/api-promise';\nimport { Stream } from '../core/streaming';\nimport { RequestOptions } from '../internal/request-options';\n\n/**\n * Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.\n */\nexport class Completions extends APIResource {\n  /**\n   * Creates a completion for the provided prompt and parameters.\n   *\n   * Returns a completion object, or a sequence of completion objects if the request\n   * is streamed.\n   *\n   * @example\n   * ```ts\n   * const completion = await client.completions.create({\n   *   model: 'string',\n   *   prompt: 'This is a test.',\n   * });\n   * ```\n   */\n  create(body: CompletionCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Completion>;\n  create(body: CompletionCreateParamsStreaming, options?: RequestOptions): APIPromise<Stream<Completion>>;\n  create(\n    body: CompletionCreateParamsBase,\n    options?: RequestOptions,\n  ): APIPromise<Stream<Completion> | Completion>;\n  create(\n    body: CompletionCreateParams,\n    options?: RequestOptions,\n  ): APIPromise<Completion> | APIPromise<Stream<Completion>> {\n    return this._client.post('/completions', { body, ...options, stream: body.stream ?? false }) as\n      | APIPromise<Completion>\n      | APIPromise<Stream<Completion>>;\n  }\n}\n\n/**\n * Represents a completion response from the API. Note: both the streamed and\n * non-streamed response objects share the same shape (unlike the chat endpoint).\n */\nexport interface Completion {\n  /**\n   * A unique identifier for the completion.\n   */\n  id: string;\n\n  /**\n   * The list of completion choices the model generated for the input prompt.\n   */\n  choices: Array<CompletionChoice>;\n\n  /**\n   * The Unix timestamp (in seconds) of when the completion was created.\n   */\n  created: number;\n\n  /**\n   * The model used for completion.\n   */\n  model: string;\n\n  /**\n   * The object type, which is always \"text_completion\"\n   */\n  object: 'text_completion';\n\n  /**\n   * This fingerprint represents the backend configuration that the model runs with.\n   *\n   * Can be used in conjunction with the `seed` request parameter to understand when\n   * backend changes have been made that might impact determinism.\n   */\n  system_fingerprint?: string;\n\n  /**\n   * Usage statistics for the completion request.\n   */\n  usage?: CompletionUsage;\n}\n\nexport interface CompletionChoice {\n  /**\n   * The reason the model stopped generating tokens. This will be `stop` if the model\n   * hit a natural stop point or a provided stop sequence, `length` if the maximum\n   * number of tokens specified in the request was reached, or `content_filter` if\n   * content was omitted due to a flag from our content filters.\n   */\n  finish_reason: 'stop' | 'length' | 'content_filter';\n\n  index: number;\n\n  logprobs: CompletionChoice.Logprobs | null;\n\n  text: string;\n}\n\nexport namespace CompletionChoice {\n  export interface Logprobs {\n    text_offset?: Array<number>;\n\n    token_logprobs?: Array<number>;\n\n    tokens?: Array<string>;\n\n    top_logprobs?: Array<{ [key: string]: number }>;\n  }\n}\n\n/**\n * Usage statistics for the completion request.\n */\nexport interface CompletionUsage {\n  /**\n   * Number of tokens in the generated completion.\n   */\n  completion_tokens: number;\n\n  /**\n   * Number of tokens in the prompt.\n   */\n  prompt_tokens: number;\n\n  /**\n   * Total number of tokens used in the request (prompt + completion).\n   */\n  total_tokens: number;\n\n  /**\n   * Breakdown of tokens used in a completion.\n   */\n  completion_tokens_details?: CompletionUsage.CompletionTokensDetails;\n\n  /**\n   * Breakdown of tokens used in the prompt.\n   */\n  prompt_tokens_details?: CompletionUsage.PromptTokensDetails;\n}\n\nexport namespace CompletionUsage {\n  /**\n   * Breakdown of tokens used in a completion.\n   */\n  export interface CompletionTokensDetails {\n    /**\n     * When using Predicted Outputs, the number of tokens in the prediction that\n     * appeared in the completion.\n     */\n    accepted_prediction_tokens?: number;\n\n    /**\n     * Audio input tokens generated by the model.\n     */\n    audio_tokens?: number;\n\n    /**\n     * Tokens generated by the model for reasoning.\n     */\n    reasoning_tokens?: number;\n\n    /**\n     * When using Predicted Outputs, the number of tokens in the prediction that did\n     * not appear in the completion. However, like reasoning tokens, these tokens are\n     * still counted in the total completion tokens for purposes of billing, output,\n     * and context window limits.\n     */\n    rejected_prediction_tokens?: number;\n  }\n\n  /**\n   * Breakdown of tokens used in the prompt.\n   */\n  export interface PromptTokensDetails {\n    /**\n     * Audio input tokens present in the prompt.\n     */\n    audio_tokens?: number;\n\n    /**\n     * Cached tokens present in the prompt.\n     */\n    cached_tokens?: number;\n  }\n}\n\nexport type CompletionCreateParams = CompletionCreateParamsNonStreaming | CompletionCreateParamsStreaming;\n\nexport interface CompletionCreateParamsBase {\n  /**\n   * ID of the model to use. You can use the\n   * [List models](https://platform.openai.com/docs/api-reference/models/list) API to\n   * see all of your available models, or see our\n   * [Model overview](https://platform.openai.com/docs/models) for descriptions of\n   * them.\n   */\n  model: (string & {}) | 'gpt-3.5-turbo-instruct' | 'davinci-002' | 'babbage-002';\n\n  /**\n   * The prompt(s) to generate completions for, encoded as a string, array of\n   * strings, array of tokens, or array of token arrays.\n   *\n   * Note that <|endoftext|> is the document separator that the model sees during\n   * training, so if a prompt is not specified the model will generate as if from the\n   * beginning of a new document.\n   */\n  prompt: string | Array<string> | Array<number> | Array<Array<number>> | null;\n\n  /**\n   * Generates `best_of` completions server-side and returns the \"best\" (the one with\n   * the highest log probability per token). Results cannot be streamed.\n   *\n   * When used with `n`, `best_of` controls the number of candidate completions and\n   * `n` specifies how many to return – `best_of` must be greater than `n`.\n   *\n   * **Note:** Because this parameter generates many completions, it can quickly\n   * consume your token quota. Use carefully and ensure that you have reasonable\n   * settings for `max_tokens` and `stop`.\n   */\n  best_of?: number | null;\n\n  /**\n   * Echo back the prompt in addition to the completion\n   */\n  echo?: boolean | null;\n\n  /**\n   * Number between -2.0 and 2.0. Positive values penalize new tokens based on their\n   * existing frequency in the text so far, decreasing the model's likelihood to\n   * repeat the same line verbatim.\n   *\n   * [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation)\n   */\n  frequency_penalty?: number | null;\n\n  /**\n   * Modify the likelihood of specified tokens appearing in the completion.\n   *\n   * Accepts a JSON object that maps tokens (specified by their token ID in the GPT\n   * tokenizer) to an associated bias value from -100 to 100. You can use this\n   * [tokenizer tool](/tokenizer?view=bpe) to convert text to token IDs.\n   * Mathematically, the bias is added to the logits generated by the model prior to\n   * sampling. The exact effect will vary per model, but values between -1 and 1\n   * should decrease or increase likelihood of selection; values like -100 or 100\n   * should result in a ban or exclusive selection of the relevant token.\n   *\n   * As an example, you can pass `{\"50256\": -100}` to prevent the <|endoftext|> token\n   * from being generated.\n   */\n  logit_bias?: { [key: string]: number } | null;\n\n  /**\n   * Include the log probabilities on the `logprobs` most likely output tokens, as\n   * well the chosen tokens. For example, if `logprobs` is 5, the API will return a\n   * list of the 5 most likely tokens. The API will always return the `logprob` of\n   * the sampled token, so there may be up to `logprobs+1` elements in the response.\n   *\n   * The maximum value for `logprobs` is 5.\n   */\n  logprobs?: number | null;\n\n  /**\n   * The maximum number of [tokens](/tokenizer) that can be generated in the\n   * completion.\n   *\n   * The token count of your prompt plus `max_tokens` cannot exceed the model's\n   * context length.\n   * [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)\n   * for counting tokens.\n   */\n  max_tokens?: number | null;\n\n  /**\n   * How many completions to generate for each prompt.\n   *\n   * **Note:** Because this parameter generates many completions, it can quickly\n   * consume your token quota. Use carefully and ensure that you have reasonable\n   * settings for `max_tokens` and `stop`.\n   */\n  n?: number | null;\n\n  /**\n   * Number between -2.0 and 2.0. Positive values penalize new tokens based on\n   * whether they appear in the text so far, increasing the model's likelihood to\n   * talk about new topics.\n   *\n   * [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation)\n   */\n  presence_penalty?: number | null;\n\n  /**\n   * If specified, our system will make a best effort to sample deterministically,\n   * such that repeated requests with the same `seed` and parameters should return\n   * the same result.\n   *\n   * Determinism is not guaranteed, and you should refer to the `system_fingerprint`\n   * response parameter to monitor changes in the backend.\n   */\n  seed?: number | null;\n\n  /**\n   * Not supported with latest reasoning models `o3` and `o4-mini`.\n   *\n   * Up to 4 sequences where the API will stop generating further tokens. The\n   * returned text will not contain the stop sequence.\n   */\n  stop?: string | null | Array<string>;\n\n  /**\n   * Whether to stream back partial progress. If set, tokens will be sent as\n   * data-only\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)\n   * as they become available, with the stream terminated by a `data: [DONE]`\n   * message.\n   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).\n   */\n  stream?: boolean | null;\n\n  /**\n   * Options for streaming response. Only set this when you set `stream: true`.\n   */\n  stream_options?: ChatCompletionsAPI.ChatCompletionStreamOptions | null;\n\n  /**\n   * The suffix that comes after a completion of inserted text.\n   *\n   * This parameter is only supported for `gpt-3.5-turbo-instruct`.\n   */\n  suffix?: string | null;\n\n  /**\n   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n   * make the output more random, while lower values like 0.2 will make it more\n   * focused and deterministic.\n   *\n   * We generally recommend altering this or `top_p` but not both.\n   */\n  temperature?: number | null;\n\n  /**\n   * An alternative to sampling with temperature, called nucleus sampling, where the\n   * model considers the results of the tokens with top_p probability mass. So 0.1\n   * means only the tokens comprising the top 10% probability mass are considered.\n   *\n   * We generally recommend altering this or `temperature` but not both.\n   */\n  top_p?: number | null;\n\n  /**\n   * A unique identifier representing your end-user, which can help OpenAI to monitor\n   * and detect abuse.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).\n   */\n  user?: string;\n}\n\nexport namespace CompletionCreateParams {\n  export type CompletionCreateParamsNonStreaming = CompletionsAPI.CompletionCreateParamsNonStreaming;\n  export type CompletionCreateParamsStreaming = CompletionsAPI.CompletionCreateParamsStreaming;\n}\n\nexport interface CompletionCreateParamsNonStreaming extends CompletionCreateParamsBase {\n  /**\n   * Whether to stream back partial progress. If set, tokens will be sent as\n   * data-only\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)\n   * as they become available, with the stream terminated by a `data: [DONE]`\n   * message.\n   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).\n   */\n  stream?: false | null;\n}\n\nexport interface CompletionCreateParamsStreaming extends CompletionCreateParamsBase {\n  /**\n   * Whether to stream back partial progress. If set, tokens will be sent as\n   * data-only\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)\n   * as they become available, with the stream terminated by a `data: [DONE]`\n   * message.\n   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).\n   */\n  stream: true;\n}\n\nexport declare namespace Completions {\n  export {\n    type Completion as Completion,\n    type CompletionChoice as CompletionChoice,\n    type CompletionUsage as CompletionUsage,\n    type CompletionCreateParams as CompletionCreateParams,\n    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,\n    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,\n  };\n}\n"
  },
  {
    "path": "src/resources/containers/containers.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as ResponsesAPI from '../responses/responses';\nimport * as FilesAPI from './files/files';\nimport {\n  FileCreateParams,\n  FileCreateResponse,\n  FileDeleteParams,\n  FileListParams,\n  FileListResponse,\n  FileListResponsesPage,\n  FileRetrieveParams,\n  FileRetrieveResponse,\n  Files,\n} from './files/files';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport class Containers extends APIResource {\n  files: FilesAPI.Files = new FilesAPI.Files(this._client);\n\n  /**\n   * Create Container\n   */\n  create(body: ContainerCreateParams, options?: RequestOptions): APIPromise<ContainerCreateResponse> {\n    return this._client.post('/containers', { body, ...options });\n  }\n\n  /**\n   * Retrieve Container\n   */\n  retrieve(containerID: string, options?: RequestOptions): APIPromise<ContainerRetrieveResponse> {\n    return this._client.get(path`/containers/${containerID}`, options);\n  }\n\n  /**\n   * List Containers\n   */\n  list(\n    query: ContainerListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<ContainerListResponsesPage, ContainerListResponse> {\n    return this._client.getAPIList('/containers', CursorPage<ContainerListResponse>, { query, ...options });\n  }\n\n  /**\n   * Delete Container\n   */\n  delete(containerID: string, options?: RequestOptions): APIPromise<void> {\n    return this._client.delete(path`/containers/${containerID}`, {\n      ...options,\n      headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n    });\n  }\n}\n\nexport type ContainerListResponsesPage = CursorPage<ContainerListResponse>;\n\nexport interface ContainerCreateResponse {\n  /**\n   * Unique identifier for the container.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the container was created.\n   */\n  created_at: number;\n\n  /**\n   * Name of the container.\n   */\n  name: string;\n\n  /**\n   * The type of this object.\n   */\n  object: string;\n\n  /**\n   * Status of the container (e.g., active, deleted).\n   */\n  status: string;\n\n  /**\n   * The container will expire after this time period. The anchor is the reference\n   * point for the expiration. The minutes is the number of minutes after the anchor\n   * before the container expires.\n   */\n  expires_after?: ContainerCreateResponse.ExpiresAfter;\n\n  /**\n   * Unix timestamp (in seconds) when the container was last active.\n   */\n  last_active_at?: number;\n\n  /**\n   * The memory limit configured for the container.\n   */\n  memory_limit?: '1g' | '4g' | '16g' | '64g';\n\n  /**\n   * Network access policy for the container.\n   */\n  network_policy?: ContainerCreateResponse.NetworkPolicy;\n}\n\nexport namespace ContainerCreateResponse {\n  /**\n   * The container will expire after this time period. The anchor is the reference\n   * point for the expiration. The minutes is the number of minutes after the anchor\n   * before the container expires.\n   */\n  export interface ExpiresAfter {\n    /**\n     * The reference point for the expiration.\n     */\n    anchor?: 'last_active_at';\n\n    /**\n     * The number of minutes after the anchor before the container expires.\n     */\n    minutes?: number;\n  }\n\n  /**\n   * Network access policy for the container.\n   */\n  export interface NetworkPolicy {\n    /**\n     * The network policy mode.\n     */\n    type: 'allowlist' | 'disabled';\n\n    /**\n     * Allowed outbound domains when `type` is `allowlist`.\n     */\n    allowed_domains?: Array<string>;\n  }\n}\n\nexport interface ContainerRetrieveResponse {\n  /**\n   * Unique identifier for the container.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the container was created.\n   */\n  created_at: number;\n\n  /**\n   * Name of the container.\n   */\n  name: string;\n\n  /**\n   * The type of this object.\n   */\n  object: string;\n\n  /**\n   * Status of the container (e.g., active, deleted).\n   */\n  status: string;\n\n  /**\n   * The container will expire after this time period. The anchor is the reference\n   * point for the expiration. The minutes is the number of minutes after the anchor\n   * before the container expires.\n   */\n  expires_after?: ContainerRetrieveResponse.ExpiresAfter;\n\n  /**\n   * Unix timestamp (in seconds) when the container was last active.\n   */\n  last_active_at?: number;\n\n  /**\n   * The memory limit configured for the container.\n   */\n  memory_limit?: '1g' | '4g' | '16g' | '64g';\n\n  /**\n   * Network access policy for the container.\n   */\n  network_policy?: ContainerRetrieveResponse.NetworkPolicy;\n}\n\nexport namespace ContainerRetrieveResponse {\n  /**\n   * The container will expire after this time period. The anchor is the reference\n   * point for the expiration. The minutes is the number of minutes after the anchor\n   * before the container expires.\n   */\n  export interface ExpiresAfter {\n    /**\n     * The reference point for the expiration.\n     */\n    anchor?: 'last_active_at';\n\n    /**\n     * The number of minutes after the anchor before the container expires.\n     */\n    minutes?: number;\n  }\n\n  /**\n   * Network access policy for the container.\n   */\n  export interface NetworkPolicy {\n    /**\n     * The network policy mode.\n     */\n    type: 'allowlist' | 'disabled';\n\n    /**\n     * Allowed outbound domains when `type` is `allowlist`.\n     */\n    allowed_domains?: Array<string>;\n  }\n}\n\nexport interface ContainerListResponse {\n  /**\n   * Unique identifier for the container.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the container was created.\n   */\n  created_at: number;\n\n  /**\n   * Name of the container.\n   */\n  name: string;\n\n  /**\n   * The type of this object.\n   */\n  object: string;\n\n  /**\n   * Status of the container (e.g., active, deleted).\n   */\n  status: string;\n\n  /**\n   * The container will expire after this time period. The anchor is the reference\n   * point for the expiration. The minutes is the number of minutes after the anchor\n   * before the container expires.\n   */\n  expires_after?: ContainerListResponse.ExpiresAfter;\n\n  /**\n   * Unix timestamp (in seconds) when the container was last active.\n   */\n  last_active_at?: number;\n\n  /**\n   * The memory limit configured for the container.\n   */\n  memory_limit?: '1g' | '4g' | '16g' | '64g';\n\n  /**\n   * Network access policy for the container.\n   */\n  network_policy?: ContainerListResponse.NetworkPolicy;\n}\n\nexport namespace ContainerListResponse {\n  /**\n   * The container will expire after this time period. The anchor is the reference\n   * point for the expiration. The minutes is the number of minutes after the anchor\n   * before the container expires.\n   */\n  export interface ExpiresAfter {\n    /**\n     * The reference point for the expiration.\n     */\n    anchor?: 'last_active_at';\n\n    /**\n     * The number of minutes after the anchor before the container expires.\n     */\n    minutes?: number;\n  }\n\n  /**\n   * Network access policy for the container.\n   */\n  export interface NetworkPolicy {\n    /**\n     * The network policy mode.\n     */\n    type: 'allowlist' | 'disabled';\n\n    /**\n     * Allowed outbound domains when `type` is `allowlist`.\n     */\n    allowed_domains?: Array<string>;\n  }\n}\n\nexport interface ContainerCreateParams {\n  /**\n   * Name of the container to create.\n   */\n  name: string;\n\n  /**\n   * Container expiration time in seconds relative to the 'anchor' time.\n   */\n  expires_after?: ContainerCreateParams.ExpiresAfter;\n\n  /**\n   * IDs of files to copy to the container.\n   */\n  file_ids?: Array<string>;\n\n  /**\n   * Optional memory limit for the container. Defaults to \"1g\".\n   */\n  memory_limit?: '1g' | '4g' | '16g' | '64g';\n\n  /**\n   * Network access policy for the container.\n   */\n  network_policy?: ResponsesAPI.ContainerNetworkPolicyDisabled | ResponsesAPI.ContainerNetworkPolicyAllowlist;\n\n  /**\n   * An optional list of skills referenced by id or inline data.\n   */\n  skills?: Array<ResponsesAPI.SkillReference | ResponsesAPI.InlineSkill>;\n}\n\nexport namespace ContainerCreateParams {\n  /**\n   * Container expiration time in seconds relative to the 'anchor' time.\n   */\n  export interface ExpiresAfter {\n    /**\n     * Time anchor for the expiration time. Currently only 'last_active_at' is\n     * supported.\n     */\n    anchor: 'last_active_at';\n\n    minutes: number;\n  }\n}\n\nexport interface ContainerListParams extends CursorPageParams {\n  /**\n   * Filter results by container name.\n   */\n  name?: string;\n\n  /**\n   * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n   * order and `desc` for descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nContainers.Files = Files;\n\nexport declare namespace Containers {\n  export {\n    type ContainerCreateResponse as ContainerCreateResponse,\n    type ContainerRetrieveResponse as ContainerRetrieveResponse,\n    type ContainerListResponse as ContainerListResponse,\n    type ContainerListResponsesPage as ContainerListResponsesPage,\n    type ContainerCreateParams as ContainerCreateParams,\n    type ContainerListParams as ContainerListParams,\n  };\n\n  export {\n    Files as Files,\n    type FileCreateResponse as FileCreateResponse,\n    type FileRetrieveResponse as FileRetrieveResponse,\n    type FileListResponse as FileListResponse,\n    type FileListResponsesPage as FileListResponsesPage,\n    type FileCreateParams as FileCreateParams,\n    type FileRetrieveParams as FileRetrieveParams,\n    type FileListParams as FileListParams,\n    type FileDeleteParams as FileDeleteParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/containers/files/content.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { APIPromise } from '../../../core/api-promise';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\nexport class Content extends APIResource {\n  /**\n   * Retrieve Container File Content\n   */\n  retrieve(fileID: string, params: ContentRetrieveParams, options?: RequestOptions): APIPromise<Response> {\n    const { container_id } = params;\n    return this._client.get(path`/containers/${container_id}/files/${fileID}/content`, {\n      ...options,\n      headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),\n      __binaryResponse: true,\n    });\n  }\n}\n\nexport interface ContentRetrieveParams {\n  container_id: string;\n}\n\nexport declare namespace Content {\n  export { type ContentRetrieveParams as ContentRetrieveParams };\n}\n"
  },
  {
    "path": "src/resources/containers/files/files.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ContentAPI from './content';\nimport { Content, ContentRetrieveParams } from './content';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { type Uploadable } from '../../../core/uploads';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { maybeMultipartFormRequestOptions } from '../../../internal/uploads';\nimport { path } from '../../../internal/utils/path';\n\nexport class Files extends APIResource {\n  content: ContentAPI.Content = new ContentAPI.Content(this._client);\n\n  /**\n   * Create a Container File\n   *\n   * You can send either a multipart/form-data request with the raw file content, or\n   * a JSON request with a file ID.\n   */\n  create(\n    containerID: string,\n    body: FileCreateParams,\n    options?: RequestOptions,\n  ): APIPromise<FileCreateResponse> {\n    return this._client.post(\n      path`/containers/${containerID}/files`,\n      maybeMultipartFormRequestOptions({ body, ...options }, this._client),\n    );\n  }\n\n  /**\n   * Retrieve Container File\n   */\n  retrieve(\n    fileID: string,\n    params: FileRetrieveParams,\n    options?: RequestOptions,\n  ): APIPromise<FileRetrieveResponse> {\n    const { container_id } = params;\n    return this._client.get(path`/containers/${container_id}/files/${fileID}`, options);\n  }\n\n  /**\n   * List Container files\n   */\n  list(\n    containerID: string,\n    query: FileListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<FileListResponsesPage, FileListResponse> {\n    return this._client.getAPIList(path`/containers/${containerID}/files`, CursorPage<FileListResponse>, {\n      query,\n      ...options,\n    });\n  }\n\n  /**\n   * Delete Container File\n   */\n  delete(fileID: string, params: FileDeleteParams, options?: RequestOptions): APIPromise<void> {\n    const { container_id } = params;\n    return this._client.delete(path`/containers/${container_id}/files/${fileID}`, {\n      ...options,\n      headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n    });\n  }\n}\n\nexport type FileListResponsesPage = CursorPage<FileListResponse>;\n\nexport interface FileCreateResponse {\n  /**\n   * Unique identifier for the file.\n   */\n  id: string;\n\n  /**\n   * Size of the file in bytes.\n   */\n  bytes: number;\n\n  /**\n   * The container this file belongs to.\n   */\n  container_id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the file was created.\n   */\n  created_at: number;\n\n  /**\n   * The type of this object (`container.file`).\n   */\n  object: 'container.file';\n\n  /**\n   * Path of the file in the container.\n   */\n  path: string;\n\n  /**\n   * Source of the file (e.g., `user`, `assistant`).\n   */\n  source: string;\n}\n\nexport interface FileRetrieveResponse {\n  /**\n   * Unique identifier for the file.\n   */\n  id: string;\n\n  /**\n   * Size of the file in bytes.\n   */\n  bytes: number;\n\n  /**\n   * The container this file belongs to.\n   */\n  container_id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the file was created.\n   */\n  created_at: number;\n\n  /**\n   * The type of this object (`container.file`).\n   */\n  object: 'container.file';\n\n  /**\n   * Path of the file in the container.\n   */\n  path: string;\n\n  /**\n   * Source of the file (e.g., `user`, `assistant`).\n   */\n  source: string;\n}\n\nexport interface FileListResponse {\n  /**\n   * Unique identifier for the file.\n   */\n  id: string;\n\n  /**\n   * Size of the file in bytes.\n   */\n  bytes: number;\n\n  /**\n   * The container this file belongs to.\n   */\n  container_id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the file was created.\n   */\n  created_at: number;\n\n  /**\n   * The type of this object (`container.file`).\n   */\n  object: 'container.file';\n\n  /**\n   * Path of the file in the container.\n   */\n  path: string;\n\n  /**\n   * Source of the file (e.g., `user`, `assistant`).\n   */\n  source: string;\n}\n\nexport interface FileCreateParams {\n  /**\n   * The File object (not file name) to be uploaded.\n   */\n  file?: Uploadable;\n\n  /**\n   * Name of the file to create.\n   */\n  file_id?: string;\n}\n\nexport interface FileRetrieveParams {\n  container_id: string;\n}\n\nexport interface FileListParams extends CursorPageParams {\n  /**\n   * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n   * order and `desc` for descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport interface FileDeleteParams {\n  container_id: string;\n}\n\nFiles.Content = Content;\n\nexport declare namespace Files {\n  export {\n    type FileCreateResponse as FileCreateResponse,\n    type FileRetrieveResponse as FileRetrieveResponse,\n    type FileListResponse as FileListResponse,\n    type FileListResponsesPage as FileListResponsesPage,\n    type FileCreateParams as FileCreateParams,\n    type FileRetrieveParams as FileRetrieveParams,\n    type FileListParams as FileListParams,\n    type FileDeleteParams as FileDeleteParams,\n  };\n\n  export { Content as Content, type ContentRetrieveParams as ContentRetrieveParams };\n}\n"
  },
  {
    "path": "src/resources/containers/files/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Content, type ContentRetrieveParams } from './content';\nexport {\n  Files,\n  type FileCreateResponse,\n  type FileRetrieveResponse,\n  type FileListResponse,\n  type FileCreateParams,\n  type FileRetrieveParams,\n  type FileListParams,\n  type FileDeleteParams,\n  type FileListResponsesPage,\n} from './files';\n"
  },
  {
    "path": "src/resources/containers/files.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './files/index';\n"
  },
  {
    "path": "src/resources/containers/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport {\n  Containers,\n  type ContainerCreateResponse,\n  type ContainerRetrieveResponse,\n  type ContainerListResponse,\n  type ContainerCreateParams,\n  type ContainerListParams,\n  type ContainerListResponsesPage,\n} from './containers';\nexport {\n  Files,\n  type FileCreateResponse,\n  type FileRetrieveResponse,\n  type FileListResponse,\n  type FileCreateParams,\n  type FileRetrieveParams,\n  type FileListParams,\n  type FileDeleteParams,\n  type FileListResponsesPage,\n} from './files/index';\n"
  },
  {
    "path": "src/resources/containers.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './containers/index';\n"
  },
  {
    "path": "src/resources/conversations/api.md",
    "content": "# Conversations\n\nTypes:\n\n- <code><a href=\"./src/resources/conversations/conversations.ts\">ComputerScreenshotContent</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">Conversation</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">ConversationDeleted</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">ConversationDeletedResource</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">Message</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">SummaryTextContent</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">TextContent</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">InputTextContent</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">OutputTextContent</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">RefusalContent</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">InputImageContent</a></code>\n- <code><a href=\"./src/resources/conversations/conversations.ts\">InputFileContent</a></code>\n\nMethods:\n\n- <code title=\"post /conversations\">client.conversations.<a href=\"./src/resources/conversations/conversations.ts\">create</a>({ ...params }) -> Conversation</code>\n- <code title=\"get /conversations/{conversation_id}\">client.conversations.<a href=\"./src/resources/conversations/conversations.ts\">retrieve</a>(conversationID) -> Conversation</code>\n- <code title=\"post /conversations/{conversation_id}\">client.conversations.<a href=\"./src/resources/conversations/conversations.ts\">update</a>(conversationID, { ...params }) -> Conversation</code>\n- <code title=\"delete /conversations/{conversation_id}\">client.conversations.<a href=\"./src/resources/conversations/conversations.ts\">delete</a>(conversationID) -> ConversationDeletedResource</code>\n\n## Items\n\nTypes:\n\n- <code><a href=\"./src/resources/conversations/items.ts\">ConversationItem</a></code>\n- <code><a href=\"./src/resources/conversations/items.ts\">ConversationItemList</a></code>\n\nMethods:\n\n- <code title=\"post /conversations/{conversation_id}/items\">client.conversations.items.<a href=\"./src/resources/conversations/items.ts\">create</a>(conversationID, { ...params }) -> ConversationItemList</code>\n- <code title=\"get /conversations/{conversation_id}/items/{item_id}\">client.conversations.items.<a href=\"./src/resources/conversations/items.ts\">retrieve</a>(itemID, { ...params }) -> ConversationItem</code>\n- <code title=\"get /conversations/{conversation_id}/items\">client.conversations.items.<a href=\"./src/resources/conversations/items.ts\">list</a>(conversationID, { ...params }) -> ConversationItemsPage</code>\n- <code title=\"delete /conversations/{conversation_id}/items/{item_id}\">client.conversations.items.<a href=\"./src/resources/conversations/items.ts\">delete</a>(itemID, { ...params }) -> Conversation</code>\n"
  },
  {
    "path": "src/resources/conversations/conversations.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as ItemsAPI from './items';\nimport {\n  ConversationItem,\n  ConversationItemList,\n  ConversationItemsPage,\n  ItemCreateParams,\n  ItemDeleteParams,\n  ItemListParams,\n  ItemRetrieveParams,\n  Items,\n} from './items';\nimport * as ResponsesAPI from '../responses/responses';\nimport { APIPromise } from '../../core/api-promise';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\n/**\n * Manage conversations and conversation items.\n */\nexport class Conversations extends APIResource {\n  items: ItemsAPI.Items = new ItemsAPI.Items(this._client);\n\n  /**\n   * Create a conversation.\n   */\n  create(\n    body: ConversationCreateParams | null | undefined = {},\n    options?: RequestOptions,\n  ): APIPromise<Conversation> {\n    return this._client.post('/conversations', { body, ...options });\n  }\n\n  /**\n   * Get a conversation\n   */\n  retrieve(conversationID: string, options?: RequestOptions): APIPromise<Conversation> {\n    return this._client.get(path`/conversations/${conversationID}`, options);\n  }\n\n  /**\n   * Update a conversation\n   */\n  update(\n    conversationID: string,\n    body: ConversationUpdateParams,\n    options?: RequestOptions,\n  ): APIPromise<Conversation> {\n    return this._client.post(path`/conversations/${conversationID}`, { body, ...options });\n  }\n\n  /**\n   * Delete a conversation. Items in the conversation will not be deleted.\n   */\n  delete(conversationID: string, options?: RequestOptions): APIPromise<ConversationDeletedResource> {\n    return this._client.delete(path`/conversations/${conversationID}`, options);\n  }\n}\n\n/**\n * A screenshot of a computer.\n */\nexport interface ComputerScreenshotContent {\n  /**\n   * The detail level of the screenshot image to be sent to the model. One of `high`,\n   * `low`, `auto`, or `original`. Defaults to `auto`.\n   */\n  detail: 'low' | 'high' | 'auto' | 'original';\n\n  /**\n   * The identifier of an uploaded file that contains the screenshot.\n   */\n  file_id: string | null;\n\n  /**\n   * The URL of the screenshot image.\n   */\n  image_url: string | null;\n\n  /**\n   * Specifies the event type. For a computer screenshot, this property is always set\n   * to `computer_screenshot`.\n   */\n  type: 'computer_screenshot';\n}\n\nexport interface Conversation {\n  /**\n   * The unique ID of the conversation.\n   */\n  id: string;\n\n  /**\n   * The time at which the conversation was created, measured in seconds since the\n   * Unix epoch.\n   */\n  created_at: number;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard. Keys are strings with a maximum\n   * length of 64 characters. Values are strings with a maximum length of 512\n   * characters.\n   */\n  metadata: unknown;\n\n  /**\n   * The object type, which is always `conversation`.\n   */\n  object: 'conversation';\n}\n\nexport interface ConversationDeleted {\n  id: string;\n\n  deleted: boolean;\n\n  object: 'conversation.deleted';\n}\n\nexport interface ConversationDeletedResource {\n  id: string;\n\n  deleted: boolean;\n\n  object: 'conversation.deleted';\n}\n\n/**\n * A message to or from the model.\n */\nexport interface Message {\n  /**\n   * The unique ID of the message.\n   */\n  id: string;\n\n  /**\n   * The content of the message\n   */\n  content: Array<\n    | ResponsesAPI.ResponseInputText\n    | ResponsesAPI.ResponseOutputText\n    | TextContent\n    | SummaryTextContent\n    | Message.ReasoningText\n    | ResponsesAPI.ResponseOutputRefusal\n    | ResponsesAPI.ResponseInputImage\n    | ComputerScreenshotContent\n    | ResponsesAPI.ResponseInputFile\n  >;\n\n  /**\n   * The role of the message. One of `unknown`, `user`, `assistant`, `system`,\n   * `critic`, `discriminator`, `developer`, or `tool`.\n   */\n  role: 'unknown' | 'user' | 'assistant' | 'system' | 'critic' | 'discriminator' | 'developer' | 'tool';\n\n  /**\n   * The status of item. One of `in_progress`, `completed`, or `incomplete`.\n   * Populated when items are returned via API.\n   */\n  status: 'in_progress' | 'completed' | 'incomplete';\n\n  /**\n   * The type of the message. Always set to `message`.\n   */\n  type: 'message';\n}\n\nexport namespace Message {\n  /**\n   * Reasoning text from the model.\n   */\n  export interface ReasoningText {\n    /**\n     * The reasoning text from the model.\n     */\n    text: string;\n\n    /**\n     * The type of the reasoning text. Always `reasoning_text`.\n     */\n    type: 'reasoning_text';\n  }\n}\n\n/**\n * A summary text from the model.\n */\nexport interface SummaryTextContent {\n  /**\n   * A summary of the reasoning output from the model so far.\n   */\n  text: string;\n\n  /**\n   * The type of the object. Always `summary_text`.\n   */\n  type: 'summary_text';\n}\n\n/**\n * A text content.\n */\nexport interface TextContent {\n  text: string;\n\n  type: 'text';\n}\n\nexport type InputTextContent = ResponsesAPI.ResponseInputText;\n\nexport type OutputTextContent = ResponsesAPI.ResponseOutputText;\n\nexport type RefusalContent = ResponsesAPI.ResponseOutputRefusal;\n\nexport type InputImageContent = ResponsesAPI.ResponseInputImage;\n\nexport type InputFileContent = ResponsesAPI.ResponseInputFile;\n\nexport interface ConversationCreateParams {\n  /**\n   * Initial items to include in the conversation context. You may add up to 20 items\n   * at a time.\n   */\n  items?: Array<ResponsesAPI.ResponseInputItem> | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n}\n\nexport interface ConversationUpdateParams {\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n}\n\nConversations.Items = Items;\n\nexport declare namespace Conversations {\n  export {\n    type ComputerScreenshotContent as ComputerScreenshotContent,\n    type Conversation as Conversation,\n    type ConversationDeleted as ConversationDeleted,\n    type ConversationDeletedResource as ConversationDeletedResource,\n    type Message as Message,\n    type SummaryTextContent as SummaryTextContent,\n    type TextContent as TextContent,\n    type InputTextContent as InputTextContent,\n    type OutputTextContent as OutputTextContent,\n    type RefusalContent as RefusalContent,\n    type InputImageContent as InputImageContent,\n    type InputFileContent as InputFileContent,\n    type ConversationCreateParams as ConversationCreateParams,\n    type ConversationUpdateParams as ConversationUpdateParams,\n  };\n\n  export {\n    Items as Items,\n    type ConversationItem as ConversationItem,\n    type ConversationItemList as ConversationItemList,\n    type ConversationItemsPage as ConversationItemsPage,\n    type ItemCreateParams as ItemCreateParams,\n    type ItemRetrieveParams as ItemRetrieveParams,\n    type ItemListParams as ItemListParams,\n    type ItemDeleteParams as ItemDeleteParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/conversations/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './conversations';\nexport {\n  Items,\n  type ConversationItem,\n  type ConversationItemList,\n  type ItemCreateParams,\n  type ItemRetrieveParams,\n  type ItemListParams,\n  type ItemDeleteParams,\n  type ConversationItemsPage,\n} from './items';\n"
  },
  {
    "path": "src/resources/conversations/items.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as ConversationsAPI from './conversations';\nimport * as ResponsesAPI from '../responses/responses';\nimport { APIPromise } from '../../core/api-promise';\nimport {\n  ConversationCursorPage,\n  type ConversationCursorPageParams,\n  PagePromise,\n} from '../../core/pagination';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\n/**\n * Manage conversations and conversation items.\n */\nexport class Items extends APIResource {\n  /**\n   * Create items in a conversation with the given ID.\n   */\n  create(\n    conversationID: string,\n    params: ItemCreateParams,\n    options?: RequestOptions,\n  ): APIPromise<ConversationItemList> {\n    const { include, ...body } = params;\n    return this._client.post(path`/conversations/${conversationID}/items`, {\n      query: { include },\n      body,\n      ...options,\n    });\n  }\n\n  /**\n   * Get a single item from a conversation with the given IDs.\n   */\n  retrieve(\n    itemID: string,\n    params: ItemRetrieveParams,\n    options?: RequestOptions,\n  ): APIPromise<ConversationItem> {\n    const { conversation_id, ...query } = params;\n    return this._client.get(path`/conversations/${conversation_id}/items/${itemID}`, { query, ...options });\n  }\n\n  /**\n   * List all items for a conversation with the given ID.\n   */\n  list(\n    conversationID: string,\n    query: ItemListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<ConversationItemsPage, ConversationItem> {\n    return this._client.getAPIList(\n      path`/conversations/${conversationID}/items`,\n      ConversationCursorPage<ConversationItem>,\n      { query, ...options },\n    );\n  }\n\n  /**\n   * Delete an item from a conversation with the given IDs.\n   */\n  delete(\n    itemID: string,\n    params: ItemDeleteParams,\n    options?: RequestOptions,\n  ): APIPromise<ConversationsAPI.Conversation> {\n    const { conversation_id } = params;\n    return this._client.delete(path`/conversations/${conversation_id}/items/${itemID}`, options);\n  }\n}\n\nexport type ConversationItemsPage = ConversationCursorPage<ConversationItem>;\n\n/**\n * A single item within a conversation. The set of possible types are the same as\n * the `output` type of a\n * [Response object](https://platform.openai.com/docs/api-reference/responses/object#responses/object-output).\n */\nexport type ConversationItem =\n  | ConversationsAPI.Message\n  | ResponsesAPI.ResponseFunctionToolCallItem\n  | ResponsesAPI.ResponseFunctionToolCallOutputItem\n  | ResponsesAPI.ResponseFileSearchToolCall\n  | ResponsesAPI.ResponseFunctionWebSearch\n  | ConversationItem.ImageGenerationCall\n  | ResponsesAPI.ResponseComputerToolCall\n  | ResponsesAPI.ResponseComputerToolCallOutputItem\n  | ResponsesAPI.ResponseToolSearchCall\n  | ResponsesAPI.ResponseToolSearchOutputItem\n  | ResponsesAPI.ResponseReasoningItem\n  | ResponsesAPI.ResponseCodeInterpreterToolCall\n  | ConversationItem.LocalShellCall\n  | ConversationItem.LocalShellCallOutput\n  | ResponsesAPI.ResponseFunctionShellToolCall\n  | ResponsesAPI.ResponseFunctionShellToolCallOutput\n  | ResponsesAPI.ResponseApplyPatchToolCall\n  | ResponsesAPI.ResponseApplyPatchToolCallOutput\n  | ConversationItem.McpListTools\n  | ConversationItem.McpApprovalRequest\n  | ConversationItem.McpApprovalResponse\n  | ConversationItem.McpCall\n  | ResponsesAPI.ResponseCustomToolCall\n  | ResponsesAPI.ResponseCustomToolCallOutput;\n\nexport namespace ConversationItem {\n  /**\n   * An image generation request made by the model.\n   */\n  export interface ImageGenerationCall {\n    /**\n     * The unique ID of the image generation call.\n     */\n    id: string;\n\n    /**\n     * The generated image encoded in base64.\n     */\n    result: string | null;\n\n    /**\n     * The status of the image generation call.\n     */\n    status: 'in_progress' | 'completed' | 'generating' | 'failed';\n\n    /**\n     * The type of the image generation call. Always `image_generation_call`.\n     */\n    type: 'image_generation_call';\n  }\n\n  /**\n   * A tool call to run a command on the local shell.\n   */\n  export interface LocalShellCall {\n    /**\n     * The unique ID of the local shell call.\n     */\n    id: string;\n\n    /**\n     * Execute a shell command on the server.\n     */\n    action: LocalShellCall.Action;\n\n    /**\n     * The unique ID of the local shell tool call generated by the model.\n     */\n    call_id: string;\n\n    /**\n     * The status of the local shell call.\n     */\n    status: 'in_progress' | 'completed' | 'incomplete';\n\n    /**\n     * The type of the local shell call. Always `local_shell_call`.\n     */\n    type: 'local_shell_call';\n  }\n\n  export namespace LocalShellCall {\n    /**\n     * Execute a shell command on the server.\n     */\n    export interface Action {\n      /**\n       * The command to run.\n       */\n      command: Array<string>;\n\n      /**\n       * Environment variables to set for the command.\n       */\n      env: { [key: string]: string };\n\n      /**\n       * The type of the local shell action. Always `exec`.\n       */\n      type: 'exec';\n\n      /**\n       * Optional timeout in milliseconds for the command.\n       */\n      timeout_ms?: number | null;\n\n      /**\n       * Optional user to run the command as.\n       */\n      user?: string | null;\n\n      /**\n       * Optional working directory to run the command in.\n       */\n      working_directory?: string | null;\n    }\n  }\n\n  /**\n   * The output of a local shell tool call.\n   */\n  export interface LocalShellCallOutput {\n    /**\n     * The unique ID of the local shell tool call generated by the model.\n     */\n    id: string;\n\n    /**\n     * A JSON string of the output of the local shell tool call.\n     */\n    output: string;\n\n    /**\n     * The type of the local shell tool call output. Always `local_shell_call_output`.\n     */\n    type: 'local_shell_call_output';\n\n    /**\n     * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | null;\n  }\n\n  /**\n   * A list of tools available on an MCP server.\n   */\n  export interface McpListTools {\n    /**\n     * The unique ID of the list.\n     */\n    id: string;\n\n    /**\n     * The label of the MCP server.\n     */\n    server_label: string;\n\n    /**\n     * The tools available on the server.\n     */\n    tools: Array<McpListTools.Tool>;\n\n    /**\n     * The type of the item. Always `mcp_list_tools`.\n     */\n    type: 'mcp_list_tools';\n\n    /**\n     * Error message if the server could not list tools.\n     */\n    error?: string | null;\n  }\n\n  export namespace McpListTools {\n    /**\n     * A tool available on an MCP server.\n     */\n    export interface Tool {\n      /**\n       * The JSON schema describing the tool's input.\n       */\n      input_schema: unknown;\n\n      /**\n       * The name of the tool.\n       */\n      name: string;\n\n      /**\n       * Additional annotations about the tool.\n       */\n      annotations?: unknown | null;\n\n      /**\n       * The description of the tool.\n       */\n      description?: string | null;\n    }\n  }\n\n  /**\n   * A request for human approval of a tool invocation.\n   */\n  export interface McpApprovalRequest {\n    /**\n     * The unique ID of the approval request.\n     */\n    id: string;\n\n    /**\n     * A JSON string of arguments for the tool.\n     */\n    arguments: string;\n\n    /**\n     * The name of the tool to run.\n     */\n    name: string;\n\n    /**\n     * The label of the MCP server making the request.\n     */\n    server_label: string;\n\n    /**\n     * The type of the item. Always `mcp_approval_request`.\n     */\n    type: 'mcp_approval_request';\n  }\n\n  /**\n   * A response to an MCP approval request.\n   */\n  export interface McpApprovalResponse {\n    /**\n     * The unique ID of the approval response\n     */\n    id: string;\n\n    /**\n     * The ID of the approval request being answered.\n     */\n    approval_request_id: string;\n\n    /**\n     * Whether the request was approved.\n     */\n    approve: boolean;\n\n    /**\n     * The type of the item. Always `mcp_approval_response`.\n     */\n    type: 'mcp_approval_response';\n\n    /**\n     * Optional reason for the decision.\n     */\n    reason?: string | null;\n  }\n\n  /**\n   * An invocation of a tool on an MCP server.\n   */\n  export interface McpCall {\n    /**\n     * The unique ID of the tool call.\n     */\n    id: string;\n\n    /**\n     * A JSON string of the arguments passed to the tool.\n     */\n    arguments: string;\n\n    /**\n     * The name of the tool that was run.\n     */\n    name: string;\n\n    /**\n     * The label of the MCP server running the tool.\n     */\n    server_label: string;\n\n    /**\n     * The type of the item. Always `mcp_call`.\n     */\n    type: 'mcp_call';\n\n    /**\n     * Unique identifier for the MCP tool call approval request. Include this value in\n     * a subsequent `mcp_approval_response` input to approve or reject the\n     * corresponding tool call.\n     */\n    approval_request_id?: string | null;\n\n    /**\n     * The error from the tool call, if any.\n     */\n    error?: string | null;\n\n    /**\n     * The output from the tool call.\n     */\n    output?: string | null;\n\n    /**\n     * The status of the tool call. One of `in_progress`, `completed`, `incomplete`,\n     * `calling`, or `failed`.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | 'calling' | 'failed';\n  }\n}\n\n/**\n * A list of Conversation items.\n */\nexport interface ConversationItemList {\n  /**\n   * A list of conversation items.\n   */\n  data: Array<ConversationItem>;\n\n  /**\n   * The ID of the first item in the list.\n   */\n  first_id: string;\n\n  /**\n   * Whether there are more items available.\n   */\n  has_more: boolean;\n\n  /**\n   * The ID of the last item in the list.\n   */\n  last_id: string;\n\n  /**\n   * The type of object returned, must be `list`.\n   */\n  object: 'list';\n}\n\nexport interface ItemCreateParams {\n  /**\n   * Body param: The items to add to the conversation. You may add up to 20 items at\n   * a time.\n   */\n  items: Array<ResponsesAPI.ResponseInputItem>;\n\n  /**\n   * Query param: Additional fields to include in the response. See the `include`\n   * parameter for\n   * [listing Conversation items above](https://platform.openai.com/docs/api-reference/conversations/list-items#conversations_list_items-include)\n   * for more information.\n   */\n  include?: Array<ResponsesAPI.ResponseIncludable>;\n}\n\nexport interface ItemRetrieveParams {\n  /**\n   * Path param: The ID of the conversation that contains the item.\n   */\n  conversation_id: string;\n\n  /**\n   * Query param: Additional fields to include in the response. See the `include`\n   * parameter for\n   * [listing Conversation items above](https://platform.openai.com/docs/api-reference/conversations/list-items#conversations_list_items-include)\n   * for more information.\n   */\n  include?: Array<ResponsesAPI.ResponseIncludable>;\n}\n\nexport interface ItemListParams extends ConversationCursorPageParams {\n  /**\n   * Specify additional output data to include in the model response. Currently\n   * supported values are:\n   *\n   * - `web_search_call.action.sources`: Include the sources of the web search tool\n   *   call.\n   * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n   *   in code interpreter tool call items.\n   * - `computer_call_output.output.image_url`: Include image urls from the computer\n   *   call output.\n   * - `file_search_call.results`: Include the search results of the file search tool\n   *   call.\n   * - `message.input_image.image_url`: Include image urls from the input message.\n   * - `message.output_text.logprobs`: Include logprobs with assistant messages.\n   * - `reasoning.encrypted_content`: Includes an encrypted version of reasoning\n   *   tokens in reasoning item outputs. This enables reasoning items to be used in\n   *   multi-turn conversations when using the Responses API statelessly (like when\n   *   the `store` parameter is set to `false`, or when an organization is enrolled\n   *   in the zero data retention program).\n   */\n  include?: Array<ResponsesAPI.ResponseIncludable>;\n\n  /**\n   * The order to return the input items in. Default is `desc`.\n   *\n   * - `asc`: Return the input items in ascending order.\n   * - `desc`: Return the input items in descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport interface ItemDeleteParams {\n  /**\n   * The ID of the conversation that contains the item.\n   */\n  conversation_id: string;\n}\n\nexport declare namespace Items {\n  export {\n    type ConversationItem as ConversationItem,\n    type ConversationItemList as ConversationItemList,\n    type ConversationItemsPage as ConversationItemsPage,\n    type ItemCreateParams as ItemCreateParams,\n    type ItemRetrieveParams as ItemRetrieveParams,\n    type ItemListParams as ItemListParams,\n    type ItemDeleteParams as ItemDeleteParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/conversations.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './conversations/index';\n"
  },
  {
    "path": "src/resources/embeddings.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport { APIPromise } from '../core/api-promise';\nimport { RequestOptions } from '../internal/request-options';\nimport { loggerFor, toFloat32Array } from '../internal/utils';\n\n/**\n * Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.\n */\nexport class Embeddings extends APIResource {\n  /**\n   * Creates an embedding vector representing the input text.\n   *\n   * @example\n   * ```ts\n   * const createEmbeddingResponse =\n   *   await client.embeddings.create({\n   *     input: 'The quick brown fox jumped over the lazy dog',\n   *     model: 'text-embedding-3-small',\n   *   });\n   * ```\n   */\n  create(body: EmbeddingCreateParams, options?: RequestOptions): APIPromise<CreateEmbeddingResponse> {\n    const hasUserProvidedEncodingFormat = !!body.encoding_format;\n    // No encoding_format specified, defaulting to base64 for performance reasons\n    // See https://github.com/openai/openai-node/pull/1312\n    let encoding_format: EmbeddingCreateParams['encoding_format'] =\n      hasUserProvidedEncodingFormat ? body.encoding_format : 'base64';\n\n    if (hasUserProvidedEncodingFormat) {\n      loggerFor(this._client).debug('embeddings/user defined encoding_format:', body.encoding_format);\n    }\n\n    const response: APIPromise<CreateEmbeddingResponse> = this._client.post('/embeddings', {\n      body: {\n        ...body,\n        encoding_format: encoding_format as EmbeddingCreateParams['encoding_format'],\n      },\n      ...options,\n    });\n\n    // if the user specified an encoding_format, return the response as-is\n    if (hasUserProvidedEncodingFormat) {\n      return response;\n    }\n\n    // in this stage, we are sure the user did not specify an encoding_format\n    // and we defaulted to base64 for performance reasons\n    // we are sure then that the response is base64 encoded, let's decode it\n    // the returned result will be a float32 array since this is OpenAI API's default encoding\n    loggerFor(this._client).debug('embeddings/decoding base64 embeddings from base64');\n\n    return (response as APIPromise<CreateEmbeddingResponse>)._thenUnwrap((response) => {\n      if (response && response.data) {\n        response.data.forEach((embeddingBase64Obj) => {\n          const embeddingBase64Str = embeddingBase64Obj.embedding as unknown as string;\n          embeddingBase64Obj.embedding = toFloat32Array(embeddingBase64Str);\n        });\n      }\n\n      return response;\n    });\n  }\n}\n\nexport interface CreateEmbeddingResponse {\n  /**\n   * The list of embeddings generated by the model.\n   */\n  data: Array<Embedding>;\n\n  /**\n   * The name of the model used to generate the embedding.\n   */\n  model: string;\n\n  /**\n   * The object type, which is always \"list\".\n   */\n  object: 'list';\n\n  /**\n   * The usage information for the request.\n   */\n  usage: CreateEmbeddingResponse.Usage;\n}\n\nexport namespace CreateEmbeddingResponse {\n  /**\n   * The usage information for the request.\n   */\n  export interface Usage {\n    /**\n     * The number of tokens used by the prompt.\n     */\n    prompt_tokens: number;\n\n    /**\n     * The total number of tokens used by the request.\n     */\n    total_tokens: number;\n  }\n}\n\n/**\n * Represents an embedding vector returned by embedding endpoint.\n */\nexport interface Embedding {\n  /**\n   * The embedding vector, which is a list of floats. The length of vector depends on\n   * the model as listed in the\n   * [embedding guide](https://platform.openai.com/docs/guides/embeddings).\n   */\n  embedding: Array<number>;\n\n  /**\n   * The index of the embedding in the list of embeddings.\n   */\n  index: number;\n\n  /**\n   * The object type, which is always \"embedding\".\n   */\n  object: 'embedding';\n}\n\nexport type EmbeddingModel = 'text-embedding-ada-002' | 'text-embedding-3-small' | 'text-embedding-3-large';\n\nexport interface EmbeddingCreateParams {\n  /**\n   * Input text to embed, encoded as a string or array of tokens. To embed multiple\n   * inputs in a single request, pass an array of strings or array of token arrays.\n   * The input must not exceed the max input tokens for the model (8192 tokens for\n   * all embedding models), cannot be an empty string, and any array must be 2048\n   * dimensions or less.\n   * [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)\n   * for counting tokens. In addition to the per-input token limit, all embedding\n   * models enforce a maximum of 300,000 tokens summed across all inputs in a single\n   * request.\n   */\n  input: string | Array<string> | Array<number> | Array<Array<number>>;\n\n  /**\n   * ID of the model to use. You can use the\n   * [List models](https://platform.openai.com/docs/api-reference/models/list) API to\n   * see all of your available models, or see our\n   * [Model overview](https://platform.openai.com/docs/models) for descriptions of\n   * them.\n   */\n  model: (string & {}) | EmbeddingModel;\n\n  /**\n   * The number of dimensions the resulting output embeddings should have. Only\n   * supported in `text-embedding-3` and later models.\n   */\n  dimensions?: number;\n\n  /**\n   * The format to return the embeddings in. Can be either `float` or\n   * [`base64`](https://pypi.org/project/pybase64/).\n   */\n  encoding_format?: 'float' | 'base64';\n\n  /**\n   * A unique identifier representing your end-user, which can help OpenAI to monitor\n   * and detect abuse.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).\n   */\n  user?: string;\n}\n\nexport declare namespace Embeddings {\n  export {\n    type CreateEmbeddingResponse as CreateEmbeddingResponse,\n    type Embedding as Embedding,\n    type EmbeddingModel as EmbeddingModel,\n    type EmbeddingCreateParams as EmbeddingCreateParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/evals/evals.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as GraderModelsAPI from '../graders/grader-models';\nimport * as ResponsesAPI from '../responses/responses';\nimport * as RunsAPI from './runs/runs';\nimport {\n  CreateEvalCompletionsRunDataSource,\n  CreateEvalJSONLRunDataSource,\n  EvalAPIError,\n  RunCancelParams,\n  RunCancelResponse,\n  RunCreateParams,\n  RunCreateResponse,\n  RunDeleteParams,\n  RunDeleteResponse,\n  RunListParams,\n  RunListResponse,\n  RunListResponsesPage,\n  RunRetrieveParams,\n  RunRetrieveResponse,\n  Runs,\n} from './runs/runs';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\n/**\n * Manage and run evals in the OpenAI platform.\n */\nexport class Evals extends APIResource {\n  runs: RunsAPI.Runs = new RunsAPI.Runs(this._client);\n\n  /**\n   * Create the structure of an evaluation that can be used to test a model's\n   * performance. An evaluation is a set of testing criteria and the config for a\n   * data source, which dictates the schema of the data used in the evaluation. After\n   * creating an evaluation, you can run it on different models and model parameters.\n   * We support several types of graders and datasources. For more information, see\n   * the [Evals guide](https://platform.openai.com/docs/guides/evals).\n   */\n  create(body: EvalCreateParams, options?: RequestOptions): APIPromise<EvalCreateResponse> {\n    return this._client.post('/evals', { body, ...options });\n  }\n\n  /**\n   * Get an evaluation by ID.\n   */\n  retrieve(evalID: string, options?: RequestOptions): APIPromise<EvalRetrieveResponse> {\n    return this._client.get(path`/evals/${evalID}`, options);\n  }\n\n  /**\n   * Update certain properties of an evaluation.\n   */\n  update(evalID: string, body: EvalUpdateParams, options?: RequestOptions): APIPromise<EvalUpdateResponse> {\n    return this._client.post(path`/evals/${evalID}`, { body, ...options });\n  }\n\n  /**\n   * List evaluations for a project.\n   */\n  list(\n    query: EvalListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<EvalListResponsesPage, EvalListResponse> {\n    return this._client.getAPIList('/evals', CursorPage<EvalListResponse>, { query, ...options });\n  }\n\n  /**\n   * Delete an evaluation.\n   */\n  delete(evalID: string, options?: RequestOptions): APIPromise<EvalDeleteResponse> {\n    return this._client.delete(path`/evals/${evalID}`, options);\n  }\n}\n\nexport type EvalListResponsesPage = CursorPage<EvalListResponse>;\n\n/**\n * A CustomDataSourceConfig which specifies the schema of your `item` and\n * optionally `sample` namespaces. The response schema defines the shape of the\n * data that will be:\n *\n * - Used to define your testing criteria and\n * - What data is required when creating a run\n */\nexport interface EvalCustomDataSourceConfig {\n  /**\n   * The json schema for the run data source items. Learn how to build JSON schemas\n   * [here](https://json-schema.org/).\n   */\n  schema: { [key: string]: unknown };\n\n  /**\n   * The type of data source. Always `custom`.\n   */\n  type: 'custom';\n}\n\n/**\n * @deprecated Deprecated in favor of LogsDataSourceConfig.\n */\nexport interface EvalStoredCompletionsDataSourceConfig {\n  /**\n   * The json schema for the run data source items. Learn how to build JSON schemas\n   * [here](https://json-schema.org/).\n   */\n  schema: { [key: string]: unknown };\n\n  /**\n   * The type of data source. Always `stored_completions`.\n   */\n  type: 'stored_completions';\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n}\n\n/**\n * An Eval object with a data source config and testing criteria. An Eval\n * represents a task to be done for your LLM integration. Like:\n *\n * - Improve the quality of my chatbot\n * - See how well my chatbot handles customer support\n * - Check if o4-mini is better at my usecase than gpt-4o\n */\nexport interface EvalCreateResponse {\n  /**\n   * Unique identifier for the evaluation.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the eval was created.\n   */\n  created_at: number;\n\n  /**\n   * Configuration of data sources used in runs of the evaluation.\n   */\n  data_source_config:\n    | EvalCustomDataSourceConfig\n    | EvalCreateResponse.Logs\n    | EvalStoredCompletionsDataSourceConfig;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The name of the evaluation.\n   */\n  name: string;\n\n  /**\n   * The object type.\n   */\n  object: 'eval';\n\n  /**\n   * A list of testing criteria.\n   */\n  testing_criteria: Array<\n    | GraderModelsAPI.LabelModelGrader\n    | GraderModelsAPI.StringCheckGrader\n    | EvalCreateResponse.EvalGraderTextSimilarity\n    | EvalCreateResponse.EvalGraderPython\n    | EvalCreateResponse.EvalGraderScoreModel\n  >;\n}\n\nexport namespace EvalCreateResponse {\n  /**\n   * A LogsDataSourceConfig which specifies the metadata property of your logs query.\n   * This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. The\n   * schema returned by this data source config is used to defined what variables are\n   * available in your evals. `item` and `sample` are both defined when using this\n   * data source config.\n   */\n  export interface Logs {\n    /**\n     * The json schema for the run data source items. Learn how to build JSON schemas\n     * [here](https://json-schema.org/).\n     */\n    schema: { [key: string]: unknown };\n\n    /**\n     * The type of data source. Always `logs`.\n     */\n    type: 'logs';\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard.\n     *\n     * Keys are strings with a maximum length of 64 characters. Values are strings with\n     * a maximum length of 512 characters.\n     */\n    metadata?: Shared.Metadata | null;\n  }\n\n  /**\n   * A TextSimilarityGrader object which grades text based on similarity metrics.\n   */\n  export interface EvalGraderTextSimilarity extends GraderModelsAPI.TextSimilarityGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold: number;\n  }\n\n  /**\n   * A PythonGrader object that runs a python script on the input.\n   */\n  export interface EvalGraderPython extends GraderModelsAPI.PythonGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold?: number;\n  }\n\n  /**\n   * A ScoreModelGrader object that uses a model to assign a score to the input.\n   */\n  export interface EvalGraderScoreModel extends GraderModelsAPI.ScoreModelGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold?: number;\n  }\n}\n\n/**\n * An Eval object with a data source config and testing criteria. An Eval\n * represents a task to be done for your LLM integration. Like:\n *\n * - Improve the quality of my chatbot\n * - See how well my chatbot handles customer support\n * - Check if o4-mini is better at my usecase than gpt-4o\n */\nexport interface EvalRetrieveResponse {\n  /**\n   * Unique identifier for the evaluation.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the eval was created.\n   */\n  created_at: number;\n\n  /**\n   * Configuration of data sources used in runs of the evaluation.\n   */\n  data_source_config:\n    | EvalCustomDataSourceConfig\n    | EvalRetrieveResponse.Logs\n    | EvalStoredCompletionsDataSourceConfig;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The name of the evaluation.\n   */\n  name: string;\n\n  /**\n   * The object type.\n   */\n  object: 'eval';\n\n  /**\n   * A list of testing criteria.\n   */\n  testing_criteria: Array<\n    | GraderModelsAPI.LabelModelGrader\n    | GraderModelsAPI.StringCheckGrader\n    | EvalRetrieveResponse.EvalGraderTextSimilarity\n    | EvalRetrieveResponse.EvalGraderPython\n    | EvalRetrieveResponse.EvalGraderScoreModel\n  >;\n}\n\nexport namespace EvalRetrieveResponse {\n  /**\n   * A LogsDataSourceConfig which specifies the metadata property of your logs query.\n   * This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. The\n   * schema returned by this data source config is used to defined what variables are\n   * available in your evals. `item` and `sample` are both defined when using this\n   * data source config.\n   */\n  export interface Logs {\n    /**\n     * The json schema for the run data source items. Learn how to build JSON schemas\n     * [here](https://json-schema.org/).\n     */\n    schema: { [key: string]: unknown };\n\n    /**\n     * The type of data source. Always `logs`.\n     */\n    type: 'logs';\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard.\n     *\n     * Keys are strings with a maximum length of 64 characters. Values are strings with\n     * a maximum length of 512 characters.\n     */\n    metadata?: Shared.Metadata | null;\n  }\n\n  /**\n   * A TextSimilarityGrader object which grades text based on similarity metrics.\n   */\n  export interface EvalGraderTextSimilarity extends GraderModelsAPI.TextSimilarityGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold: number;\n  }\n\n  /**\n   * A PythonGrader object that runs a python script on the input.\n   */\n  export interface EvalGraderPython extends GraderModelsAPI.PythonGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold?: number;\n  }\n\n  /**\n   * A ScoreModelGrader object that uses a model to assign a score to the input.\n   */\n  export interface EvalGraderScoreModel extends GraderModelsAPI.ScoreModelGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold?: number;\n  }\n}\n\n/**\n * An Eval object with a data source config and testing criteria. An Eval\n * represents a task to be done for your LLM integration. Like:\n *\n * - Improve the quality of my chatbot\n * - See how well my chatbot handles customer support\n * - Check if o4-mini is better at my usecase than gpt-4o\n */\nexport interface EvalUpdateResponse {\n  /**\n   * Unique identifier for the evaluation.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the eval was created.\n   */\n  created_at: number;\n\n  /**\n   * Configuration of data sources used in runs of the evaluation.\n   */\n  data_source_config:\n    | EvalCustomDataSourceConfig\n    | EvalUpdateResponse.Logs\n    | EvalStoredCompletionsDataSourceConfig;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The name of the evaluation.\n   */\n  name: string;\n\n  /**\n   * The object type.\n   */\n  object: 'eval';\n\n  /**\n   * A list of testing criteria.\n   */\n  testing_criteria: Array<\n    | GraderModelsAPI.LabelModelGrader\n    | GraderModelsAPI.StringCheckGrader\n    | EvalUpdateResponse.EvalGraderTextSimilarity\n    | EvalUpdateResponse.EvalGraderPython\n    | EvalUpdateResponse.EvalGraderScoreModel\n  >;\n}\n\nexport namespace EvalUpdateResponse {\n  /**\n   * A LogsDataSourceConfig which specifies the metadata property of your logs query.\n   * This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. The\n   * schema returned by this data source config is used to defined what variables are\n   * available in your evals. `item` and `sample` are both defined when using this\n   * data source config.\n   */\n  export interface Logs {\n    /**\n     * The json schema for the run data source items. Learn how to build JSON schemas\n     * [here](https://json-schema.org/).\n     */\n    schema: { [key: string]: unknown };\n\n    /**\n     * The type of data source. Always `logs`.\n     */\n    type: 'logs';\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard.\n     *\n     * Keys are strings with a maximum length of 64 characters. Values are strings with\n     * a maximum length of 512 characters.\n     */\n    metadata?: Shared.Metadata | null;\n  }\n\n  /**\n   * A TextSimilarityGrader object which grades text based on similarity metrics.\n   */\n  export interface EvalGraderTextSimilarity extends GraderModelsAPI.TextSimilarityGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold: number;\n  }\n\n  /**\n   * A PythonGrader object that runs a python script on the input.\n   */\n  export interface EvalGraderPython extends GraderModelsAPI.PythonGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold?: number;\n  }\n\n  /**\n   * A ScoreModelGrader object that uses a model to assign a score to the input.\n   */\n  export interface EvalGraderScoreModel extends GraderModelsAPI.ScoreModelGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold?: number;\n  }\n}\n\n/**\n * An Eval object with a data source config and testing criteria. An Eval\n * represents a task to be done for your LLM integration. Like:\n *\n * - Improve the quality of my chatbot\n * - See how well my chatbot handles customer support\n * - Check if o4-mini is better at my usecase than gpt-4o\n */\nexport interface EvalListResponse {\n  /**\n   * Unique identifier for the evaluation.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the eval was created.\n   */\n  created_at: number;\n\n  /**\n   * Configuration of data sources used in runs of the evaluation.\n   */\n  data_source_config:\n    | EvalCustomDataSourceConfig\n    | EvalListResponse.Logs\n    | EvalStoredCompletionsDataSourceConfig;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The name of the evaluation.\n   */\n  name: string;\n\n  /**\n   * The object type.\n   */\n  object: 'eval';\n\n  /**\n   * A list of testing criteria.\n   */\n  testing_criteria: Array<\n    | GraderModelsAPI.LabelModelGrader\n    | GraderModelsAPI.StringCheckGrader\n    | EvalListResponse.EvalGraderTextSimilarity\n    | EvalListResponse.EvalGraderPython\n    | EvalListResponse.EvalGraderScoreModel\n  >;\n}\n\nexport namespace EvalListResponse {\n  /**\n   * A LogsDataSourceConfig which specifies the metadata property of your logs query.\n   * This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. The\n   * schema returned by this data source config is used to defined what variables are\n   * available in your evals. `item` and `sample` are both defined when using this\n   * data source config.\n   */\n  export interface Logs {\n    /**\n     * The json schema for the run data source items. Learn how to build JSON schemas\n     * [here](https://json-schema.org/).\n     */\n    schema: { [key: string]: unknown };\n\n    /**\n     * The type of data source. Always `logs`.\n     */\n    type: 'logs';\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard.\n     *\n     * Keys are strings with a maximum length of 64 characters. Values are strings with\n     * a maximum length of 512 characters.\n     */\n    metadata?: Shared.Metadata | null;\n  }\n\n  /**\n   * A TextSimilarityGrader object which grades text based on similarity metrics.\n   */\n  export interface EvalGraderTextSimilarity extends GraderModelsAPI.TextSimilarityGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold: number;\n  }\n\n  /**\n   * A PythonGrader object that runs a python script on the input.\n   */\n  export interface EvalGraderPython extends GraderModelsAPI.PythonGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold?: number;\n  }\n\n  /**\n   * A ScoreModelGrader object that uses a model to assign a score to the input.\n   */\n  export interface EvalGraderScoreModel extends GraderModelsAPI.ScoreModelGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold?: number;\n  }\n}\n\nexport interface EvalDeleteResponse {\n  deleted: boolean;\n\n  eval_id: string;\n\n  object: string;\n}\n\nexport interface EvalCreateParams {\n  /**\n   * The configuration for the data source used for the evaluation runs. Dictates the\n   * schema of the data used in the evaluation.\n   */\n  data_source_config: EvalCreateParams.Custom | EvalCreateParams.Logs | EvalCreateParams.StoredCompletions;\n\n  /**\n   * A list of graders for all eval runs in this group. Graders can reference\n   * variables in the data source using double curly braces notation, like\n   * `{{item.variable_name}}`. To reference the model's output, use the `sample`\n   * namespace (ie, `{{sample.output_text}}`).\n   */\n  testing_criteria: Array<\n    | EvalCreateParams.LabelModel\n    | GraderModelsAPI.StringCheckGrader\n    | EvalCreateParams.TextSimilarity\n    | EvalCreateParams.Python\n    | EvalCreateParams.ScoreModel\n  >;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The name of the evaluation.\n   */\n  name?: string;\n}\n\nexport namespace EvalCreateParams {\n  /**\n   * A CustomDataSourceConfig object that defines the schema for the data source used\n   * for the evaluation runs. This schema is used to define the shape of the data\n   * that will be:\n   *\n   * - Used to define your testing criteria and\n   * - What data is required when creating a run\n   */\n  export interface Custom {\n    /**\n     * The json schema for each row in the data source.\n     */\n    item_schema: { [key: string]: unknown };\n\n    /**\n     * The type of data source. Always `custom`.\n     */\n    type: 'custom';\n\n    /**\n     * Whether the eval should expect you to populate the sample namespace (ie, by\n     * generating responses off of your data source)\n     */\n    include_sample_schema?: boolean;\n  }\n\n  /**\n   * A data source config which specifies the metadata property of your logs query.\n   * This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc.\n   */\n  export interface Logs {\n    /**\n     * The type of data source. Always `logs`.\n     */\n    type: 'logs';\n\n    /**\n     * Metadata filters for the logs data source.\n     */\n    metadata?: { [key: string]: unknown };\n  }\n\n  /**\n   * @deprecated Deprecated in favor of LogsDataSourceConfig.\n   */\n  export interface StoredCompletions {\n    /**\n     * The type of data source. Always `stored_completions`.\n     */\n    type: 'stored_completions';\n\n    /**\n     * Metadata filters for the stored completions data source.\n     */\n    metadata?: { [key: string]: unknown };\n  }\n\n  /**\n   * A LabelModelGrader object which uses a model to assign labels to each item in\n   * the evaluation.\n   */\n  export interface LabelModel {\n    /**\n     * A list of chat messages forming the prompt or context. May include variable\n     * references to the `item` namespace, ie {{item.name}}.\n     */\n    input: Array<LabelModel.SimpleInputMessage | LabelModel.EvalItem>;\n\n    /**\n     * The labels to classify to each item in the evaluation.\n     */\n    labels: Array<string>;\n\n    /**\n     * The model to use for the evaluation. Must support structured outputs.\n     */\n    model: string;\n\n    /**\n     * The name of the grader.\n     */\n    name: string;\n\n    /**\n     * The labels that indicate a passing result. Must be a subset of labels.\n     */\n    passing_labels: Array<string>;\n\n    /**\n     * The object type, which is always `label_model`.\n     */\n    type: 'label_model';\n  }\n\n  export namespace LabelModel {\n    export interface SimpleInputMessage {\n      /**\n       * The content of the message.\n       */\n      content: string;\n\n      /**\n       * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n       */\n      role: string;\n    }\n\n    /**\n     * A message input to the model with a role indicating instruction following\n     * hierarchy. Instructions given with the `developer` or `system` role take\n     * precedence over instructions given with the `user` role. Messages with the\n     * `assistant` role are presumed to have been generated by the model in previous\n     * interactions.\n     */\n    export interface EvalItem {\n      /**\n       * Inputs to the model - can contain template strings. Supports text, output text,\n       * input images, and input audio, either as a single item or an array of items.\n       */\n      content:\n        | string\n        | ResponsesAPI.ResponseInputText\n        | EvalItem.OutputText\n        | EvalItem.InputImage\n        | ResponsesAPI.ResponseInputAudio\n        | GraderModelsAPI.GraderInputs;\n\n      /**\n       * The role of the message input. One of `user`, `assistant`, `system`, or\n       * `developer`.\n       */\n      role: 'user' | 'assistant' | 'system' | 'developer';\n\n      /**\n       * The type of the message input. Always `message`.\n       */\n      type?: 'message';\n    }\n\n    export namespace EvalItem {\n      /**\n       * A text output from the model.\n       */\n      export interface OutputText {\n        /**\n         * The text output from the model.\n         */\n        text: string;\n\n        /**\n         * The type of the output text. Always `output_text`.\n         */\n        type: 'output_text';\n      }\n\n      /**\n       * An image input block used within EvalItem content arrays.\n       */\n      export interface InputImage {\n        /**\n         * The URL of the image input.\n         */\n        image_url: string;\n\n        /**\n         * The type of the image input. Always `input_image`.\n         */\n        type: 'input_image';\n\n        /**\n         * The detail level of the image to be sent to the model. One of `high`, `low`, or\n         * `auto`. Defaults to `auto`.\n         */\n        detail?: string;\n      }\n    }\n  }\n\n  /**\n   * A TextSimilarityGrader object which grades text based on similarity metrics.\n   */\n  export interface TextSimilarity extends GraderModelsAPI.TextSimilarityGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold: number;\n  }\n\n  /**\n   * A PythonGrader object that runs a python script on the input.\n   */\n  export interface Python extends GraderModelsAPI.PythonGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold?: number;\n  }\n\n  /**\n   * A ScoreModelGrader object that uses a model to assign a score to the input.\n   */\n  export interface ScoreModel extends GraderModelsAPI.ScoreModelGrader {\n    /**\n     * The threshold for the score.\n     */\n    pass_threshold?: number;\n  }\n}\n\nexport interface EvalUpdateParams {\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * Rename the evaluation.\n   */\n  name?: string;\n}\n\nexport interface EvalListParams extends CursorPageParams {\n  /**\n   * Sort order for evals by timestamp. Use `asc` for ascending order or `desc` for\n   * descending order.\n   */\n  order?: 'asc' | 'desc';\n\n  /**\n   * Evals can be ordered by creation time or last updated time. Use `created_at` for\n   * creation time or `updated_at` for last updated time.\n   */\n  order_by?: 'created_at' | 'updated_at';\n}\n\nEvals.Runs = Runs;\n\nexport declare namespace Evals {\n  export {\n    type EvalCustomDataSourceConfig as EvalCustomDataSourceConfig,\n    type EvalStoredCompletionsDataSourceConfig as EvalStoredCompletionsDataSourceConfig,\n    type EvalCreateResponse as EvalCreateResponse,\n    type EvalRetrieveResponse as EvalRetrieveResponse,\n    type EvalUpdateResponse as EvalUpdateResponse,\n    type EvalListResponse as EvalListResponse,\n    type EvalDeleteResponse as EvalDeleteResponse,\n    type EvalListResponsesPage as EvalListResponsesPage,\n    type EvalCreateParams as EvalCreateParams,\n    type EvalUpdateParams as EvalUpdateParams,\n    type EvalListParams as EvalListParams,\n  };\n\n  export {\n    Runs as Runs,\n    type CreateEvalCompletionsRunDataSource as CreateEvalCompletionsRunDataSource,\n    type CreateEvalJSONLRunDataSource as CreateEvalJSONLRunDataSource,\n    type EvalAPIError as EvalAPIError,\n    type RunCreateResponse as RunCreateResponse,\n    type RunRetrieveResponse as RunRetrieveResponse,\n    type RunListResponse as RunListResponse,\n    type RunDeleteResponse as RunDeleteResponse,\n    type RunCancelResponse as RunCancelResponse,\n    type RunListResponsesPage as RunListResponsesPage,\n    type RunCreateParams as RunCreateParams,\n    type RunRetrieveParams as RunRetrieveParams,\n    type RunListParams as RunListParams,\n    type RunDeleteParams as RunDeleteParams,\n    type RunCancelParams as RunCancelParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/evals/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport {\n  Evals,\n  type EvalCustomDataSourceConfig,\n  type EvalStoredCompletionsDataSourceConfig,\n  type EvalCreateResponse,\n  type EvalRetrieveResponse,\n  type EvalUpdateResponse,\n  type EvalListResponse,\n  type EvalDeleteResponse,\n  type EvalCreateParams,\n  type EvalUpdateParams,\n  type EvalListParams,\n  type EvalListResponsesPage,\n} from './evals';\nexport {\n  Runs,\n  type CreateEvalCompletionsRunDataSource,\n  type CreateEvalJSONLRunDataSource,\n  type EvalAPIError,\n  type RunCreateResponse,\n  type RunRetrieveResponse,\n  type RunListResponse,\n  type RunDeleteResponse,\n  type RunCancelResponse,\n  type RunCreateParams,\n  type RunRetrieveParams,\n  type RunListParams,\n  type RunDeleteParams,\n  type RunCancelParams,\n  type RunListResponsesPage,\n} from './runs/index';\n"
  },
  {
    "path": "src/resources/evals/runs/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport {\n  OutputItems,\n  type OutputItemRetrieveResponse,\n  type OutputItemListResponse,\n  type OutputItemRetrieveParams,\n  type OutputItemListParams,\n  type OutputItemListResponsesPage,\n} from './output-items';\nexport {\n  Runs,\n  type CreateEvalCompletionsRunDataSource,\n  type CreateEvalJSONLRunDataSource,\n  type EvalAPIError,\n  type RunCreateResponse,\n  type RunRetrieveResponse,\n  type RunListResponse,\n  type RunDeleteResponse,\n  type RunCancelResponse,\n  type RunCreateParams,\n  type RunRetrieveParams,\n  type RunListParams,\n  type RunDeleteParams,\n  type RunCancelParams,\n  type RunListResponsesPage,\n} from './runs';\n"
  },
  {
    "path": "src/resources/evals/runs/output-items.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as RunsAPI from './runs';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Manage and run evals in the OpenAI platform.\n */\nexport class OutputItems extends APIResource {\n  /**\n   * Get an evaluation run output item by ID.\n   */\n  retrieve(\n    outputItemID: string,\n    params: OutputItemRetrieveParams,\n    options?: RequestOptions,\n  ): APIPromise<OutputItemRetrieveResponse> {\n    const { eval_id, run_id } = params;\n    return this._client.get(path`/evals/${eval_id}/runs/${run_id}/output_items/${outputItemID}`, options);\n  }\n\n  /**\n   * Get a list of output items for an evaluation run.\n   */\n  list(\n    runID: string,\n    params: OutputItemListParams,\n    options?: RequestOptions,\n  ): PagePromise<OutputItemListResponsesPage, OutputItemListResponse> {\n    const { eval_id, ...query } = params;\n    return this._client.getAPIList(\n      path`/evals/${eval_id}/runs/${runID}/output_items`,\n      CursorPage<OutputItemListResponse>,\n      { query, ...options },\n    );\n  }\n}\n\nexport type OutputItemListResponsesPage = CursorPage<OutputItemListResponse>;\n\n/**\n * A schema representing an evaluation run output item.\n */\nexport interface OutputItemRetrieveResponse {\n  /**\n   * Unique identifier for the evaluation run output item.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the evaluation run was created.\n   */\n  created_at: number;\n\n  /**\n   * Details of the input data source item.\n   */\n  datasource_item: { [key: string]: unknown };\n\n  /**\n   * The identifier for the data source item.\n   */\n  datasource_item_id: number;\n\n  /**\n   * The identifier of the evaluation group.\n   */\n  eval_id: string;\n\n  /**\n   * The type of the object. Always \"eval.run.output_item\".\n   */\n  object: 'eval.run.output_item';\n\n  /**\n   * A list of grader results for this output item.\n   */\n  results: Array<OutputItemRetrieveResponse.Result>;\n\n  /**\n   * The identifier of the evaluation run associated with this output item.\n   */\n  run_id: string;\n\n  /**\n   * A sample containing the input and output of the evaluation run.\n   */\n  sample: OutputItemRetrieveResponse.Sample;\n\n  /**\n   * The status of the evaluation run.\n   */\n  status: string;\n}\n\nexport namespace OutputItemRetrieveResponse {\n  /**\n   * A single grader result for an evaluation run output item.\n   */\n  export interface Result {\n    /**\n     * The name of the grader.\n     */\n    name: string;\n\n    /**\n     * Whether the grader considered the output a pass.\n     */\n    passed: boolean;\n\n    /**\n     * The numeric score produced by the grader.\n     */\n    score: number;\n\n    /**\n     * Optional sample or intermediate data produced by the grader.\n     */\n    sample?: { [key: string]: unknown } | null;\n\n    /**\n     * The grader type (for example, \"string-check-grader\").\n     */\n    type?: string;\n\n    [k: string]: unknown;\n  }\n\n  /**\n   * A sample containing the input and output of the evaluation run.\n   */\n  export interface Sample {\n    /**\n     * An object representing an error response from the Eval API.\n     */\n    error: RunsAPI.EvalAPIError;\n\n    /**\n     * The reason why the sample generation was finished.\n     */\n    finish_reason: string;\n\n    /**\n     * An array of input messages.\n     */\n    input: Array<Sample.Input>;\n\n    /**\n     * The maximum number of tokens allowed for completion.\n     */\n    max_completion_tokens: number;\n\n    /**\n     * The model used for generating the sample.\n     */\n    model: string;\n\n    /**\n     * An array of output messages.\n     */\n    output: Array<Sample.Output>;\n\n    /**\n     * The seed used for generating the sample.\n     */\n    seed: number;\n\n    /**\n     * The sampling temperature used.\n     */\n    temperature: number;\n\n    /**\n     * The top_p value used for sampling.\n     */\n    top_p: number;\n\n    /**\n     * Token usage details for the sample.\n     */\n    usage: Sample.Usage;\n  }\n\n  export namespace Sample {\n    /**\n     * An input message.\n     */\n    export interface Input {\n      /**\n       * The content of the message.\n       */\n      content: string;\n\n      /**\n       * The role of the message sender (e.g., system, user, developer).\n       */\n      role: string;\n    }\n\n    export interface Output {\n      /**\n       * The content of the message.\n       */\n      content?: string;\n\n      /**\n       * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n       */\n      role?: string;\n    }\n\n    /**\n     * Token usage details for the sample.\n     */\n    export interface Usage {\n      /**\n       * The number of tokens retrieved from cache.\n       */\n      cached_tokens: number;\n\n      /**\n       * The number of completion tokens generated.\n       */\n      completion_tokens: number;\n\n      /**\n       * The number of prompt tokens used.\n       */\n      prompt_tokens: number;\n\n      /**\n       * The total number of tokens used.\n       */\n      total_tokens: number;\n    }\n  }\n}\n\n/**\n * A schema representing an evaluation run output item.\n */\nexport interface OutputItemListResponse {\n  /**\n   * Unique identifier for the evaluation run output item.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the evaluation run was created.\n   */\n  created_at: number;\n\n  /**\n   * Details of the input data source item.\n   */\n  datasource_item: { [key: string]: unknown };\n\n  /**\n   * The identifier for the data source item.\n   */\n  datasource_item_id: number;\n\n  /**\n   * The identifier of the evaluation group.\n   */\n  eval_id: string;\n\n  /**\n   * The type of the object. Always \"eval.run.output_item\".\n   */\n  object: 'eval.run.output_item';\n\n  /**\n   * A list of grader results for this output item.\n   */\n  results: Array<OutputItemListResponse.Result>;\n\n  /**\n   * The identifier of the evaluation run associated with this output item.\n   */\n  run_id: string;\n\n  /**\n   * A sample containing the input and output of the evaluation run.\n   */\n  sample: OutputItemListResponse.Sample;\n\n  /**\n   * The status of the evaluation run.\n   */\n  status: string;\n}\n\nexport namespace OutputItemListResponse {\n  /**\n   * A single grader result for an evaluation run output item.\n   */\n  export interface Result {\n    /**\n     * The name of the grader.\n     */\n    name: string;\n\n    /**\n     * Whether the grader considered the output a pass.\n     */\n    passed: boolean;\n\n    /**\n     * The numeric score produced by the grader.\n     */\n    score: number;\n\n    /**\n     * Optional sample or intermediate data produced by the grader.\n     */\n    sample?: { [key: string]: unknown } | null;\n\n    /**\n     * The grader type (for example, \"string-check-grader\").\n     */\n    type?: string;\n\n    [k: string]: unknown;\n  }\n\n  /**\n   * A sample containing the input and output of the evaluation run.\n   */\n  export interface Sample {\n    /**\n     * An object representing an error response from the Eval API.\n     */\n    error: RunsAPI.EvalAPIError;\n\n    /**\n     * The reason why the sample generation was finished.\n     */\n    finish_reason: string;\n\n    /**\n     * An array of input messages.\n     */\n    input: Array<Sample.Input>;\n\n    /**\n     * The maximum number of tokens allowed for completion.\n     */\n    max_completion_tokens: number;\n\n    /**\n     * The model used for generating the sample.\n     */\n    model: string;\n\n    /**\n     * An array of output messages.\n     */\n    output: Array<Sample.Output>;\n\n    /**\n     * The seed used for generating the sample.\n     */\n    seed: number;\n\n    /**\n     * The sampling temperature used.\n     */\n    temperature: number;\n\n    /**\n     * The top_p value used for sampling.\n     */\n    top_p: number;\n\n    /**\n     * Token usage details for the sample.\n     */\n    usage: Sample.Usage;\n  }\n\n  export namespace Sample {\n    /**\n     * An input message.\n     */\n    export interface Input {\n      /**\n       * The content of the message.\n       */\n      content: string;\n\n      /**\n       * The role of the message sender (e.g., system, user, developer).\n       */\n      role: string;\n    }\n\n    export interface Output {\n      /**\n       * The content of the message.\n       */\n      content?: string;\n\n      /**\n       * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n       */\n      role?: string;\n    }\n\n    /**\n     * Token usage details for the sample.\n     */\n    export interface Usage {\n      /**\n       * The number of tokens retrieved from cache.\n       */\n      cached_tokens: number;\n\n      /**\n       * The number of completion tokens generated.\n       */\n      completion_tokens: number;\n\n      /**\n       * The number of prompt tokens used.\n       */\n      prompt_tokens: number;\n\n      /**\n       * The total number of tokens used.\n       */\n      total_tokens: number;\n    }\n  }\n}\n\nexport interface OutputItemRetrieveParams {\n  /**\n   * The ID of the evaluation to retrieve runs for.\n   */\n  eval_id: string;\n\n  /**\n   * The ID of the run to retrieve.\n   */\n  run_id: string;\n}\n\nexport interface OutputItemListParams extends CursorPageParams {\n  /**\n   * Path param: The ID of the evaluation to retrieve runs for.\n   */\n  eval_id: string;\n\n  /**\n   * Query param: Sort order for output items by timestamp. Use `asc` for ascending\n   * order or `desc` for descending order. Defaults to `asc`.\n   */\n  order?: 'asc' | 'desc';\n\n  /**\n   * Query param: Filter output items by status. Use `failed` to filter by failed\n   * output items or `pass` to filter by passed output items.\n   */\n  status?: 'fail' | 'pass';\n}\n\nexport declare namespace OutputItems {\n  export {\n    type OutputItemRetrieveResponse as OutputItemRetrieveResponse,\n    type OutputItemListResponse as OutputItemListResponse,\n    type OutputItemListResponsesPage as OutputItemListResponsesPage,\n    type OutputItemRetrieveParams as OutputItemRetrieveParams,\n    type OutputItemListParams as OutputItemListParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/evals/runs/runs.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as Shared from '../../shared';\nimport * as GraderModelsAPI from '../../graders/grader-models';\nimport * as ResponsesAPI from '../../responses/responses';\nimport * as CompletionsAPI from '../../chat/completions/completions';\nimport * as OutputItemsAPI from './output-items';\nimport {\n  OutputItemListParams,\n  OutputItemListResponse,\n  OutputItemListResponsesPage,\n  OutputItemRetrieveParams,\n  OutputItemRetrieveResponse,\n  OutputItems,\n} from './output-items';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Manage and run evals in the OpenAI platform.\n */\nexport class Runs extends APIResource {\n  outputItems: OutputItemsAPI.OutputItems = new OutputItemsAPI.OutputItems(this._client);\n\n  /**\n   * Kicks off a new run for a given evaluation, specifying the data source, and what\n   * model configuration to use to test. The datasource will be validated against the\n   * schema specified in the config of the evaluation.\n   */\n  create(evalID: string, body: RunCreateParams, options?: RequestOptions): APIPromise<RunCreateResponse> {\n    return this._client.post(path`/evals/${evalID}/runs`, { body, ...options });\n  }\n\n  /**\n   * Get an evaluation run by ID.\n   */\n  retrieve(\n    runID: string,\n    params: RunRetrieveParams,\n    options?: RequestOptions,\n  ): APIPromise<RunRetrieveResponse> {\n    const { eval_id } = params;\n    return this._client.get(path`/evals/${eval_id}/runs/${runID}`, options);\n  }\n\n  /**\n   * Get a list of runs for an evaluation.\n   */\n  list(\n    evalID: string,\n    query: RunListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<RunListResponsesPage, RunListResponse> {\n    return this._client.getAPIList(path`/evals/${evalID}/runs`, CursorPage<RunListResponse>, {\n      query,\n      ...options,\n    });\n  }\n\n  /**\n   * Delete an eval run.\n   */\n  delete(runID: string, params: RunDeleteParams, options?: RequestOptions): APIPromise<RunDeleteResponse> {\n    const { eval_id } = params;\n    return this._client.delete(path`/evals/${eval_id}/runs/${runID}`, options);\n  }\n\n  /**\n   * Cancel an ongoing evaluation run.\n   */\n  cancel(runID: string, params: RunCancelParams, options?: RequestOptions): APIPromise<RunCancelResponse> {\n    const { eval_id } = params;\n    return this._client.post(path`/evals/${eval_id}/runs/${runID}`, options);\n  }\n}\n\nexport type RunListResponsesPage = CursorPage<RunListResponse>;\n\n/**\n * A CompletionsRunDataSource object describing a model sampling configuration.\n */\nexport interface CreateEvalCompletionsRunDataSource {\n  /**\n   * Determines what populates the `item` namespace in this run's data source.\n   */\n  source:\n    | CreateEvalCompletionsRunDataSource.FileContent\n    | CreateEvalCompletionsRunDataSource.FileID\n    | CreateEvalCompletionsRunDataSource.StoredCompletions;\n\n  /**\n   * The type of run data source. Always `completions`.\n   */\n  type: 'completions';\n\n  /**\n   * Used when sampling from a model. Dictates the structure of the messages passed\n   * into the model. Can either be a reference to a prebuilt trajectory (ie,\n   * `item.input_trajectory`), or a template with variable references to the `item`\n   * namespace.\n   */\n  input_messages?:\n    | CreateEvalCompletionsRunDataSource.Template\n    | CreateEvalCompletionsRunDataSource.ItemReference;\n\n  /**\n   * The name of the model to use for generating completions (e.g. \"o3-mini\").\n   */\n  model?: string;\n\n  sampling_params?: CreateEvalCompletionsRunDataSource.SamplingParams;\n}\n\nexport namespace CreateEvalCompletionsRunDataSource {\n  export interface FileContent {\n    /**\n     * The content of the jsonl file.\n     */\n    content: Array<FileContent.Content>;\n\n    /**\n     * The type of jsonl source. Always `file_content`.\n     */\n    type: 'file_content';\n  }\n\n  export namespace FileContent {\n    export interface Content {\n      item: { [key: string]: unknown };\n\n      sample?: { [key: string]: unknown };\n    }\n  }\n\n  export interface FileID {\n    /**\n     * The identifier of the file.\n     */\n    id: string;\n\n    /**\n     * The type of jsonl source. Always `file_id`.\n     */\n    type: 'file_id';\n  }\n\n  /**\n   * A StoredCompletionsRunDataSource configuration describing a set of filters\n   */\n  export interface StoredCompletions {\n    /**\n     * The type of source. Always `stored_completions`.\n     */\n    type: 'stored_completions';\n\n    /**\n     * An optional Unix timestamp to filter items created after this time.\n     */\n    created_after?: number | null;\n\n    /**\n     * An optional Unix timestamp to filter items created before this time.\n     */\n    created_before?: number | null;\n\n    /**\n     * An optional maximum number of items to return.\n     */\n    limit?: number | null;\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard.\n     *\n     * Keys are strings with a maximum length of 64 characters. Values are strings with\n     * a maximum length of 512 characters.\n     */\n    metadata?: Shared.Metadata | null;\n\n    /**\n     * An optional model to filter by (e.g., 'gpt-4o').\n     */\n    model?: string | null;\n  }\n\n  export interface Template {\n    /**\n     * A list of chat messages forming the prompt or context. May include variable\n     * references to the `item` namespace, ie {{item.name}}.\n     */\n    template: Array<ResponsesAPI.EasyInputMessage | Template.EvalItem>;\n\n    /**\n     * The type of input messages. Always `template`.\n     */\n    type: 'template';\n  }\n\n  export namespace Template {\n    /**\n     * A message input to the model with a role indicating instruction following\n     * hierarchy. Instructions given with the `developer` or `system` role take\n     * precedence over instructions given with the `user` role. Messages with the\n     * `assistant` role are presumed to have been generated by the model in previous\n     * interactions.\n     */\n    export interface EvalItem {\n      /**\n       * Inputs to the model - can contain template strings. Supports text, output text,\n       * input images, and input audio, either as a single item or an array of items.\n       */\n      content:\n        | string\n        | ResponsesAPI.ResponseInputText\n        | EvalItem.OutputText\n        | EvalItem.InputImage\n        | ResponsesAPI.ResponseInputAudio\n        | GraderModelsAPI.GraderInputs;\n\n      /**\n       * The role of the message input. One of `user`, `assistant`, `system`, or\n       * `developer`.\n       */\n      role: 'user' | 'assistant' | 'system' | 'developer';\n\n      /**\n       * The type of the message input. Always `message`.\n       */\n      type?: 'message';\n    }\n\n    export namespace EvalItem {\n      /**\n       * A text output from the model.\n       */\n      export interface OutputText {\n        /**\n         * The text output from the model.\n         */\n        text: string;\n\n        /**\n         * The type of the output text. Always `output_text`.\n         */\n        type: 'output_text';\n      }\n\n      /**\n       * An image input block used within EvalItem content arrays.\n       */\n      export interface InputImage {\n        /**\n         * The URL of the image input.\n         */\n        image_url: string;\n\n        /**\n         * The type of the image input. Always `input_image`.\n         */\n        type: 'input_image';\n\n        /**\n         * The detail level of the image to be sent to the model. One of `high`, `low`, or\n         * `auto`. Defaults to `auto`.\n         */\n        detail?: string;\n      }\n    }\n  }\n\n  export interface ItemReference {\n    /**\n     * A reference to a variable in the `item` namespace. Ie, \"item.input_trajectory\"\n     */\n    item_reference: string;\n\n    /**\n     * The type of input messages. Always `item_reference`.\n     */\n    type: 'item_reference';\n  }\n\n  export interface SamplingParams {\n    /**\n     * The maximum number of tokens in the generated output.\n     */\n    max_completion_tokens?: number;\n\n    /**\n     * Constrains effort on reasoning for\n     * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n     * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n     * Reducing reasoning effort can result in faster responses and fewer tokens used\n     * on reasoning in a response.\n     *\n     * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n     *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n     *   calls are supported for all reasoning values in gpt-5.1.\n     * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n     *   support `none`.\n     * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n     * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n     */\n    reasoning_effort?: Shared.ReasoningEffort | null;\n\n    /**\n     * An object specifying the format that the model must output.\n     *\n     * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n     * Outputs which ensures the model will match your supplied JSON schema. Learn more\n     * in the\n     * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n     *\n     * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n     * ensures the message the model generates is valid JSON. Using `json_schema` is\n     * preferred for models that support it.\n     */\n    response_format?:\n      | Shared.ResponseFormatText\n      | Shared.ResponseFormatJSONSchema\n      | Shared.ResponseFormatJSONObject;\n\n    /**\n     * A seed value to initialize the randomness, during sampling.\n     */\n    seed?: number;\n\n    /**\n     * A higher temperature increases randomness in the outputs.\n     */\n    temperature?: number;\n\n    /**\n     * A list of tools the model may call. Currently, only functions are supported as a\n     * tool. Use this to provide a list of functions the model may generate JSON inputs\n     * for. A max of 128 functions are supported.\n     */\n    tools?: Array<CompletionsAPI.ChatCompletionFunctionTool>;\n\n    /**\n     * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n     */\n    top_p?: number;\n  }\n}\n\n/**\n * A JsonlRunDataSource object with that specifies a JSONL file that matches the\n * eval\n */\nexport interface CreateEvalJSONLRunDataSource {\n  /**\n   * Determines what populates the `item` namespace in the data source.\n   */\n  source: CreateEvalJSONLRunDataSource.FileContent | CreateEvalJSONLRunDataSource.FileID;\n\n  /**\n   * The type of data source. Always `jsonl`.\n   */\n  type: 'jsonl';\n}\n\nexport namespace CreateEvalJSONLRunDataSource {\n  export interface FileContent {\n    /**\n     * The content of the jsonl file.\n     */\n    content: Array<FileContent.Content>;\n\n    /**\n     * The type of jsonl source. Always `file_content`.\n     */\n    type: 'file_content';\n  }\n\n  export namespace FileContent {\n    export interface Content {\n      item: { [key: string]: unknown };\n\n      sample?: { [key: string]: unknown };\n    }\n  }\n\n  export interface FileID {\n    /**\n     * The identifier of the file.\n     */\n    id: string;\n\n    /**\n     * The type of jsonl source. Always `file_id`.\n     */\n    type: 'file_id';\n  }\n}\n\n/**\n * An object representing an error response from the Eval API.\n */\nexport interface EvalAPIError {\n  /**\n   * The error code.\n   */\n  code: string;\n\n  /**\n   * The error message.\n   */\n  message: string;\n}\n\n/**\n * A schema representing an evaluation run.\n */\nexport interface RunCreateResponse {\n  /**\n   * Unique identifier for the evaluation run.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the evaluation run was created.\n   */\n  created_at: number;\n\n  /**\n   * Information about the run's data source.\n   */\n  data_source:\n    | CreateEvalJSONLRunDataSource\n    | CreateEvalCompletionsRunDataSource\n    | RunCreateResponse.Responses;\n\n  /**\n   * An object representing an error response from the Eval API.\n   */\n  error: EvalAPIError;\n\n  /**\n   * The identifier of the associated evaluation.\n   */\n  eval_id: string;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The model that is evaluated, if applicable.\n   */\n  model: string;\n\n  /**\n   * The name of the evaluation run.\n   */\n  name: string;\n\n  /**\n   * The type of the object. Always \"eval.run\".\n   */\n  object: 'eval.run';\n\n  /**\n   * Usage statistics for each model during the evaluation run.\n   */\n  per_model_usage: Array<RunCreateResponse.PerModelUsage>;\n\n  /**\n   * Results per testing criteria applied during the evaluation run.\n   */\n  per_testing_criteria_results: Array<RunCreateResponse.PerTestingCriteriaResult>;\n\n  /**\n   * The URL to the rendered evaluation run report on the UI dashboard.\n   */\n  report_url: string;\n\n  /**\n   * Counters summarizing the outcomes of the evaluation run.\n   */\n  result_counts: RunCreateResponse.ResultCounts;\n\n  /**\n   * The status of the evaluation run.\n   */\n  status: string;\n}\n\nexport namespace RunCreateResponse {\n  /**\n   * A ResponsesRunDataSource object describing a model sampling configuration.\n   */\n  export interface Responses {\n    /**\n     * Determines what populates the `item` namespace in this run's data source.\n     */\n    source: Responses.FileContent | Responses.FileID | Responses.Responses;\n\n    /**\n     * The type of run data source. Always `responses`.\n     */\n    type: 'responses';\n\n    /**\n     * Used when sampling from a model. Dictates the structure of the messages passed\n     * into the model. Can either be a reference to a prebuilt trajectory (ie,\n     * `item.input_trajectory`), or a template with variable references to the `item`\n     * namespace.\n     */\n    input_messages?: Responses.Template | Responses.ItemReference;\n\n    /**\n     * The name of the model to use for generating completions (e.g. \"o3-mini\").\n     */\n    model?: string;\n\n    sampling_params?: Responses.SamplingParams;\n  }\n\n  export namespace Responses {\n    export interface FileContent {\n      /**\n       * The content of the jsonl file.\n       */\n      content: Array<FileContent.Content>;\n\n      /**\n       * The type of jsonl source. Always `file_content`.\n       */\n      type: 'file_content';\n    }\n\n    export namespace FileContent {\n      export interface Content {\n        item: { [key: string]: unknown };\n\n        sample?: { [key: string]: unknown };\n      }\n    }\n\n    export interface FileID {\n      /**\n       * The identifier of the file.\n       */\n      id: string;\n\n      /**\n       * The type of jsonl source. Always `file_id`.\n       */\n      type: 'file_id';\n    }\n\n    /**\n     * A EvalResponsesSource object describing a run data source configuration.\n     */\n    export interface Responses {\n      /**\n       * The type of run data source. Always `responses`.\n       */\n      type: 'responses';\n\n      /**\n       * Only include items created after this timestamp (inclusive). This is a query\n       * parameter used to select responses.\n       */\n      created_after?: number | null;\n\n      /**\n       * Only include items created before this timestamp (inclusive). This is a query\n       * parameter used to select responses.\n       */\n      created_before?: number | null;\n\n      /**\n       * Optional string to search the 'instructions' field. This is a query parameter\n       * used to select responses.\n       */\n      instructions_search?: string | null;\n\n      /**\n       * Metadata filter for the responses. This is a query parameter used to select\n       * responses.\n       */\n      metadata?: unknown | null;\n\n      /**\n       * The name of the model to find responses for. This is a query parameter used to\n       * select responses.\n       */\n      model?: string | null;\n\n      /**\n       * Constrains effort on reasoning for\n       * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n       * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n       * Reducing reasoning effort can result in faster responses and fewer tokens used\n       * on reasoning in a response.\n       *\n       * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n       *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n       *   calls are supported for all reasoning values in gpt-5.1.\n       * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n       *   support `none`.\n       * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n       * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n       */\n      reasoning_effort?: Shared.ReasoningEffort | null;\n\n      /**\n       * Sampling temperature. This is a query parameter used to select responses.\n       */\n      temperature?: number | null;\n\n      /**\n       * List of tool names. This is a query parameter used to select responses.\n       */\n      tools?: Array<string> | null;\n\n      /**\n       * Nucleus sampling parameter. This is a query parameter used to select responses.\n       */\n      top_p?: number | null;\n\n      /**\n       * List of user identifiers. This is a query parameter used to select responses.\n       */\n      users?: Array<string> | null;\n    }\n\n    export interface Template {\n      /**\n       * A list of chat messages forming the prompt or context. May include variable\n       * references to the `item` namespace, ie {{item.name}}.\n       */\n      template: Array<Template.ChatMessage | Template.EvalItem>;\n\n      /**\n       * The type of input messages. Always `template`.\n       */\n      type: 'template';\n    }\n\n    export namespace Template {\n      export interface ChatMessage {\n        /**\n         * The content of the message.\n         */\n        content: string;\n\n        /**\n         * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n         */\n        role: string;\n      }\n\n      /**\n       * A message input to the model with a role indicating instruction following\n       * hierarchy. Instructions given with the `developer` or `system` role take\n       * precedence over instructions given with the `user` role. Messages with the\n       * `assistant` role are presumed to have been generated by the model in previous\n       * interactions.\n       */\n      export interface EvalItem {\n        /**\n         * Inputs to the model - can contain template strings. Supports text, output text,\n         * input images, and input audio, either as a single item or an array of items.\n         */\n        content:\n          | string\n          | ResponsesAPI.ResponseInputText\n          | EvalItem.OutputText\n          | EvalItem.InputImage\n          | ResponsesAPI.ResponseInputAudio\n          | GraderModelsAPI.GraderInputs;\n\n        /**\n         * The role of the message input. One of `user`, `assistant`, `system`, or\n         * `developer`.\n         */\n        role: 'user' | 'assistant' | 'system' | 'developer';\n\n        /**\n         * The type of the message input. Always `message`.\n         */\n        type?: 'message';\n      }\n\n      export namespace EvalItem {\n        /**\n         * A text output from the model.\n         */\n        export interface OutputText {\n          /**\n           * The text output from the model.\n           */\n          text: string;\n\n          /**\n           * The type of the output text. Always `output_text`.\n           */\n          type: 'output_text';\n        }\n\n        /**\n         * An image input block used within EvalItem content arrays.\n         */\n        export interface InputImage {\n          /**\n           * The URL of the image input.\n           */\n          image_url: string;\n\n          /**\n           * The type of the image input. Always `input_image`.\n           */\n          type: 'input_image';\n\n          /**\n           * The detail level of the image to be sent to the model. One of `high`, `low`, or\n           * `auto`. Defaults to `auto`.\n           */\n          detail?: string;\n        }\n      }\n    }\n\n    export interface ItemReference {\n      /**\n       * A reference to a variable in the `item` namespace. Ie, \"item.name\"\n       */\n      item_reference: string;\n\n      /**\n       * The type of input messages. Always `item_reference`.\n       */\n      type: 'item_reference';\n    }\n\n    export interface SamplingParams {\n      /**\n       * The maximum number of tokens in the generated output.\n       */\n      max_completion_tokens?: number;\n\n      /**\n       * Constrains effort on reasoning for\n       * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n       * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n       * Reducing reasoning effort can result in faster responses and fewer tokens used\n       * on reasoning in a response.\n       *\n       * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n       *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n       *   calls are supported for all reasoning values in gpt-5.1.\n       * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n       *   support `none`.\n       * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n       * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n       */\n      reasoning_effort?: Shared.ReasoningEffort | null;\n\n      /**\n       * A seed value to initialize the randomness, during sampling.\n       */\n      seed?: number;\n\n      /**\n       * A higher temperature increases randomness in the outputs.\n       */\n      temperature?: number;\n\n      /**\n       * Configuration options for a text response from the model. Can be plain text or\n       * structured JSON data. Learn more:\n       *\n       * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n       * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n       */\n      text?: SamplingParams.Text;\n\n      /**\n       * An array of tools the model may call while generating a response. You can\n       * specify which tool to use by setting the `tool_choice` parameter.\n       *\n       * The two categories of tools you can provide the model are:\n       *\n       * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n       *   capabilities, like\n       *   [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n       *   [file search](https://platform.openai.com/docs/guides/tools-file-search).\n       *   Learn more about\n       *   [built-in tools](https://platform.openai.com/docs/guides/tools).\n       * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n       *   the model to call your own code. Learn more about\n       *   [function calling](https://platform.openai.com/docs/guides/function-calling).\n       */\n      tools?: Array<ResponsesAPI.Tool>;\n\n      /**\n       * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n       */\n      top_p?: number;\n    }\n\n    export namespace SamplingParams {\n      /**\n       * Configuration options for a text response from the model. Can be plain text or\n       * structured JSON data. Learn more:\n       *\n       * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n       * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n       */\n      export interface Text {\n        /**\n         * An object specifying the format that the model must output.\n         *\n         * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n         * ensures the model will match your supplied JSON schema. Learn more in the\n         * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n         *\n         * The default format is `{ \"type\": \"text\" }` with no additional options.\n         *\n         * **Not recommended for gpt-4o and newer models:**\n         *\n         * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n         * ensures the message the model generates is valid JSON. Using `json_schema` is\n         * preferred for models that support it.\n         */\n        format?: ResponsesAPI.ResponseFormatTextConfig;\n      }\n    }\n  }\n\n  export interface PerModelUsage {\n    /**\n     * The number of tokens retrieved from cache.\n     */\n    cached_tokens: number;\n\n    /**\n     * The number of completion tokens generated.\n     */\n    completion_tokens: number;\n\n    /**\n     * The number of invocations.\n     */\n    invocation_count: number;\n\n    /**\n     * The name of the model.\n     */\n    model_name: string;\n\n    /**\n     * The number of prompt tokens used.\n     */\n    prompt_tokens: number;\n\n    /**\n     * The total number of tokens used.\n     */\n    total_tokens: number;\n  }\n\n  export interface PerTestingCriteriaResult {\n    /**\n     * Number of tests failed for this criteria.\n     */\n    failed: number;\n\n    /**\n     * Number of tests passed for this criteria.\n     */\n    passed: number;\n\n    /**\n     * A description of the testing criteria.\n     */\n    testing_criteria: string;\n  }\n\n  /**\n   * Counters summarizing the outcomes of the evaluation run.\n   */\n  export interface ResultCounts {\n    /**\n     * Number of output items that resulted in an error.\n     */\n    errored: number;\n\n    /**\n     * Number of output items that failed to pass the evaluation.\n     */\n    failed: number;\n\n    /**\n     * Number of output items that passed the evaluation.\n     */\n    passed: number;\n\n    /**\n     * Total number of executed output items.\n     */\n    total: number;\n  }\n}\n\n/**\n * A schema representing an evaluation run.\n */\nexport interface RunRetrieveResponse {\n  /**\n   * Unique identifier for the evaluation run.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the evaluation run was created.\n   */\n  created_at: number;\n\n  /**\n   * Information about the run's data source.\n   */\n  data_source:\n    | CreateEvalJSONLRunDataSource\n    | CreateEvalCompletionsRunDataSource\n    | RunRetrieveResponse.Responses;\n\n  /**\n   * An object representing an error response from the Eval API.\n   */\n  error: EvalAPIError;\n\n  /**\n   * The identifier of the associated evaluation.\n   */\n  eval_id: string;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The model that is evaluated, if applicable.\n   */\n  model: string;\n\n  /**\n   * The name of the evaluation run.\n   */\n  name: string;\n\n  /**\n   * The type of the object. Always \"eval.run\".\n   */\n  object: 'eval.run';\n\n  /**\n   * Usage statistics for each model during the evaluation run.\n   */\n  per_model_usage: Array<RunRetrieveResponse.PerModelUsage>;\n\n  /**\n   * Results per testing criteria applied during the evaluation run.\n   */\n  per_testing_criteria_results: Array<RunRetrieveResponse.PerTestingCriteriaResult>;\n\n  /**\n   * The URL to the rendered evaluation run report on the UI dashboard.\n   */\n  report_url: string;\n\n  /**\n   * Counters summarizing the outcomes of the evaluation run.\n   */\n  result_counts: RunRetrieveResponse.ResultCounts;\n\n  /**\n   * The status of the evaluation run.\n   */\n  status: string;\n}\n\nexport namespace RunRetrieveResponse {\n  /**\n   * A ResponsesRunDataSource object describing a model sampling configuration.\n   */\n  export interface Responses {\n    /**\n     * Determines what populates the `item` namespace in this run's data source.\n     */\n    source: Responses.FileContent | Responses.FileID | Responses.Responses;\n\n    /**\n     * The type of run data source. Always `responses`.\n     */\n    type: 'responses';\n\n    /**\n     * Used when sampling from a model. Dictates the structure of the messages passed\n     * into the model. Can either be a reference to a prebuilt trajectory (ie,\n     * `item.input_trajectory`), or a template with variable references to the `item`\n     * namespace.\n     */\n    input_messages?: Responses.Template | Responses.ItemReference;\n\n    /**\n     * The name of the model to use for generating completions (e.g. \"o3-mini\").\n     */\n    model?: string;\n\n    sampling_params?: Responses.SamplingParams;\n  }\n\n  export namespace Responses {\n    export interface FileContent {\n      /**\n       * The content of the jsonl file.\n       */\n      content: Array<FileContent.Content>;\n\n      /**\n       * The type of jsonl source. Always `file_content`.\n       */\n      type: 'file_content';\n    }\n\n    export namespace FileContent {\n      export interface Content {\n        item: { [key: string]: unknown };\n\n        sample?: { [key: string]: unknown };\n      }\n    }\n\n    export interface FileID {\n      /**\n       * The identifier of the file.\n       */\n      id: string;\n\n      /**\n       * The type of jsonl source. Always `file_id`.\n       */\n      type: 'file_id';\n    }\n\n    /**\n     * A EvalResponsesSource object describing a run data source configuration.\n     */\n    export interface Responses {\n      /**\n       * The type of run data source. Always `responses`.\n       */\n      type: 'responses';\n\n      /**\n       * Only include items created after this timestamp (inclusive). This is a query\n       * parameter used to select responses.\n       */\n      created_after?: number | null;\n\n      /**\n       * Only include items created before this timestamp (inclusive). This is a query\n       * parameter used to select responses.\n       */\n      created_before?: number | null;\n\n      /**\n       * Optional string to search the 'instructions' field. This is a query parameter\n       * used to select responses.\n       */\n      instructions_search?: string | null;\n\n      /**\n       * Metadata filter for the responses. This is a query parameter used to select\n       * responses.\n       */\n      metadata?: unknown | null;\n\n      /**\n       * The name of the model to find responses for. This is a query parameter used to\n       * select responses.\n       */\n      model?: string | null;\n\n      /**\n       * Constrains effort on reasoning for\n       * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n       * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n       * Reducing reasoning effort can result in faster responses and fewer tokens used\n       * on reasoning in a response.\n       *\n       * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n       *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n       *   calls are supported for all reasoning values in gpt-5.1.\n       * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n       *   support `none`.\n       * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n       * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n       */\n      reasoning_effort?: Shared.ReasoningEffort | null;\n\n      /**\n       * Sampling temperature. This is a query parameter used to select responses.\n       */\n      temperature?: number | null;\n\n      /**\n       * List of tool names. This is a query parameter used to select responses.\n       */\n      tools?: Array<string> | null;\n\n      /**\n       * Nucleus sampling parameter. This is a query parameter used to select responses.\n       */\n      top_p?: number | null;\n\n      /**\n       * List of user identifiers. This is a query parameter used to select responses.\n       */\n      users?: Array<string> | null;\n    }\n\n    export interface Template {\n      /**\n       * A list of chat messages forming the prompt or context. May include variable\n       * references to the `item` namespace, ie {{item.name}}.\n       */\n      template: Array<Template.ChatMessage | Template.EvalItem>;\n\n      /**\n       * The type of input messages. Always `template`.\n       */\n      type: 'template';\n    }\n\n    export namespace Template {\n      export interface ChatMessage {\n        /**\n         * The content of the message.\n         */\n        content: string;\n\n        /**\n         * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n         */\n        role: string;\n      }\n\n      /**\n       * A message input to the model with a role indicating instruction following\n       * hierarchy. Instructions given with the `developer` or `system` role take\n       * precedence over instructions given with the `user` role. Messages with the\n       * `assistant` role are presumed to have been generated by the model in previous\n       * interactions.\n       */\n      export interface EvalItem {\n        /**\n         * Inputs to the model - can contain template strings. Supports text, output text,\n         * input images, and input audio, either as a single item or an array of items.\n         */\n        content:\n          | string\n          | ResponsesAPI.ResponseInputText\n          | EvalItem.OutputText\n          | EvalItem.InputImage\n          | ResponsesAPI.ResponseInputAudio\n          | GraderModelsAPI.GraderInputs;\n\n        /**\n         * The role of the message input. One of `user`, `assistant`, `system`, or\n         * `developer`.\n         */\n        role: 'user' | 'assistant' | 'system' | 'developer';\n\n        /**\n         * The type of the message input. Always `message`.\n         */\n        type?: 'message';\n      }\n\n      export namespace EvalItem {\n        /**\n         * A text output from the model.\n         */\n        export interface OutputText {\n          /**\n           * The text output from the model.\n           */\n          text: string;\n\n          /**\n           * The type of the output text. Always `output_text`.\n           */\n          type: 'output_text';\n        }\n\n        /**\n         * An image input block used within EvalItem content arrays.\n         */\n        export interface InputImage {\n          /**\n           * The URL of the image input.\n           */\n          image_url: string;\n\n          /**\n           * The type of the image input. Always `input_image`.\n           */\n          type: 'input_image';\n\n          /**\n           * The detail level of the image to be sent to the model. One of `high`, `low`, or\n           * `auto`. Defaults to `auto`.\n           */\n          detail?: string;\n        }\n      }\n    }\n\n    export interface ItemReference {\n      /**\n       * A reference to a variable in the `item` namespace. Ie, \"item.name\"\n       */\n      item_reference: string;\n\n      /**\n       * The type of input messages. Always `item_reference`.\n       */\n      type: 'item_reference';\n    }\n\n    export interface SamplingParams {\n      /**\n       * The maximum number of tokens in the generated output.\n       */\n      max_completion_tokens?: number;\n\n      /**\n       * Constrains effort on reasoning for\n       * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n       * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n       * Reducing reasoning effort can result in faster responses and fewer tokens used\n       * on reasoning in a response.\n       *\n       * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n       *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n       *   calls are supported for all reasoning values in gpt-5.1.\n       * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n       *   support `none`.\n       * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n       * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n       */\n      reasoning_effort?: Shared.ReasoningEffort | null;\n\n      /**\n       * A seed value to initialize the randomness, during sampling.\n       */\n      seed?: number;\n\n      /**\n       * A higher temperature increases randomness in the outputs.\n       */\n      temperature?: number;\n\n      /**\n       * Configuration options for a text response from the model. Can be plain text or\n       * structured JSON data. Learn more:\n       *\n       * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n       * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n       */\n      text?: SamplingParams.Text;\n\n      /**\n       * An array of tools the model may call while generating a response. You can\n       * specify which tool to use by setting the `tool_choice` parameter.\n       *\n       * The two categories of tools you can provide the model are:\n       *\n       * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n       *   capabilities, like\n       *   [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n       *   [file search](https://platform.openai.com/docs/guides/tools-file-search).\n       *   Learn more about\n       *   [built-in tools](https://platform.openai.com/docs/guides/tools).\n       * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n       *   the model to call your own code. Learn more about\n       *   [function calling](https://platform.openai.com/docs/guides/function-calling).\n       */\n      tools?: Array<ResponsesAPI.Tool>;\n\n      /**\n       * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n       */\n      top_p?: number;\n    }\n\n    export namespace SamplingParams {\n      /**\n       * Configuration options for a text response from the model. Can be plain text or\n       * structured JSON data. Learn more:\n       *\n       * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n       * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n       */\n      export interface Text {\n        /**\n         * An object specifying the format that the model must output.\n         *\n         * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n         * ensures the model will match your supplied JSON schema. Learn more in the\n         * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n         *\n         * The default format is `{ \"type\": \"text\" }` with no additional options.\n         *\n         * **Not recommended for gpt-4o and newer models:**\n         *\n         * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n         * ensures the message the model generates is valid JSON. Using `json_schema` is\n         * preferred for models that support it.\n         */\n        format?: ResponsesAPI.ResponseFormatTextConfig;\n      }\n    }\n  }\n\n  export interface PerModelUsage {\n    /**\n     * The number of tokens retrieved from cache.\n     */\n    cached_tokens: number;\n\n    /**\n     * The number of completion tokens generated.\n     */\n    completion_tokens: number;\n\n    /**\n     * The number of invocations.\n     */\n    invocation_count: number;\n\n    /**\n     * The name of the model.\n     */\n    model_name: string;\n\n    /**\n     * The number of prompt tokens used.\n     */\n    prompt_tokens: number;\n\n    /**\n     * The total number of tokens used.\n     */\n    total_tokens: number;\n  }\n\n  export interface PerTestingCriteriaResult {\n    /**\n     * Number of tests failed for this criteria.\n     */\n    failed: number;\n\n    /**\n     * Number of tests passed for this criteria.\n     */\n    passed: number;\n\n    /**\n     * A description of the testing criteria.\n     */\n    testing_criteria: string;\n  }\n\n  /**\n   * Counters summarizing the outcomes of the evaluation run.\n   */\n  export interface ResultCounts {\n    /**\n     * Number of output items that resulted in an error.\n     */\n    errored: number;\n\n    /**\n     * Number of output items that failed to pass the evaluation.\n     */\n    failed: number;\n\n    /**\n     * Number of output items that passed the evaluation.\n     */\n    passed: number;\n\n    /**\n     * Total number of executed output items.\n     */\n    total: number;\n  }\n}\n\n/**\n * A schema representing an evaluation run.\n */\nexport interface RunListResponse {\n  /**\n   * Unique identifier for the evaluation run.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the evaluation run was created.\n   */\n  created_at: number;\n\n  /**\n   * Information about the run's data source.\n   */\n  data_source: CreateEvalJSONLRunDataSource | CreateEvalCompletionsRunDataSource | RunListResponse.Responses;\n\n  /**\n   * An object representing an error response from the Eval API.\n   */\n  error: EvalAPIError;\n\n  /**\n   * The identifier of the associated evaluation.\n   */\n  eval_id: string;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The model that is evaluated, if applicable.\n   */\n  model: string;\n\n  /**\n   * The name of the evaluation run.\n   */\n  name: string;\n\n  /**\n   * The type of the object. Always \"eval.run\".\n   */\n  object: 'eval.run';\n\n  /**\n   * Usage statistics for each model during the evaluation run.\n   */\n  per_model_usage: Array<RunListResponse.PerModelUsage>;\n\n  /**\n   * Results per testing criteria applied during the evaluation run.\n   */\n  per_testing_criteria_results: Array<RunListResponse.PerTestingCriteriaResult>;\n\n  /**\n   * The URL to the rendered evaluation run report on the UI dashboard.\n   */\n  report_url: string;\n\n  /**\n   * Counters summarizing the outcomes of the evaluation run.\n   */\n  result_counts: RunListResponse.ResultCounts;\n\n  /**\n   * The status of the evaluation run.\n   */\n  status: string;\n}\n\nexport namespace RunListResponse {\n  /**\n   * A ResponsesRunDataSource object describing a model sampling configuration.\n   */\n  export interface Responses {\n    /**\n     * Determines what populates the `item` namespace in this run's data source.\n     */\n    source: Responses.FileContent | Responses.FileID | Responses.Responses;\n\n    /**\n     * The type of run data source. Always `responses`.\n     */\n    type: 'responses';\n\n    /**\n     * Used when sampling from a model. Dictates the structure of the messages passed\n     * into the model. Can either be a reference to a prebuilt trajectory (ie,\n     * `item.input_trajectory`), or a template with variable references to the `item`\n     * namespace.\n     */\n    input_messages?: Responses.Template | Responses.ItemReference;\n\n    /**\n     * The name of the model to use for generating completions (e.g. \"o3-mini\").\n     */\n    model?: string;\n\n    sampling_params?: Responses.SamplingParams;\n  }\n\n  export namespace Responses {\n    export interface FileContent {\n      /**\n       * The content of the jsonl file.\n       */\n      content: Array<FileContent.Content>;\n\n      /**\n       * The type of jsonl source. Always `file_content`.\n       */\n      type: 'file_content';\n    }\n\n    export namespace FileContent {\n      export interface Content {\n        item: { [key: string]: unknown };\n\n        sample?: { [key: string]: unknown };\n      }\n    }\n\n    export interface FileID {\n      /**\n       * The identifier of the file.\n       */\n      id: string;\n\n      /**\n       * The type of jsonl source. Always `file_id`.\n       */\n      type: 'file_id';\n    }\n\n    /**\n     * A EvalResponsesSource object describing a run data source configuration.\n     */\n    export interface Responses {\n      /**\n       * The type of run data source. Always `responses`.\n       */\n      type: 'responses';\n\n      /**\n       * Only include items created after this timestamp (inclusive). This is a query\n       * parameter used to select responses.\n       */\n      created_after?: number | null;\n\n      /**\n       * Only include items created before this timestamp (inclusive). This is a query\n       * parameter used to select responses.\n       */\n      created_before?: number | null;\n\n      /**\n       * Optional string to search the 'instructions' field. This is a query parameter\n       * used to select responses.\n       */\n      instructions_search?: string | null;\n\n      /**\n       * Metadata filter for the responses. This is a query parameter used to select\n       * responses.\n       */\n      metadata?: unknown | null;\n\n      /**\n       * The name of the model to find responses for. This is a query parameter used to\n       * select responses.\n       */\n      model?: string | null;\n\n      /**\n       * Constrains effort on reasoning for\n       * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n       * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n       * Reducing reasoning effort can result in faster responses and fewer tokens used\n       * on reasoning in a response.\n       *\n       * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n       *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n       *   calls are supported for all reasoning values in gpt-5.1.\n       * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n       *   support `none`.\n       * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n       * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n       */\n      reasoning_effort?: Shared.ReasoningEffort | null;\n\n      /**\n       * Sampling temperature. This is a query parameter used to select responses.\n       */\n      temperature?: number | null;\n\n      /**\n       * List of tool names. This is a query parameter used to select responses.\n       */\n      tools?: Array<string> | null;\n\n      /**\n       * Nucleus sampling parameter. This is a query parameter used to select responses.\n       */\n      top_p?: number | null;\n\n      /**\n       * List of user identifiers. This is a query parameter used to select responses.\n       */\n      users?: Array<string> | null;\n    }\n\n    export interface Template {\n      /**\n       * A list of chat messages forming the prompt or context. May include variable\n       * references to the `item` namespace, ie {{item.name}}.\n       */\n      template: Array<Template.ChatMessage | Template.EvalItem>;\n\n      /**\n       * The type of input messages. Always `template`.\n       */\n      type: 'template';\n    }\n\n    export namespace Template {\n      export interface ChatMessage {\n        /**\n         * The content of the message.\n         */\n        content: string;\n\n        /**\n         * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n         */\n        role: string;\n      }\n\n      /**\n       * A message input to the model with a role indicating instruction following\n       * hierarchy. Instructions given with the `developer` or `system` role take\n       * precedence over instructions given with the `user` role. Messages with the\n       * `assistant` role are presumed to have been generated by the model in previous\n       * interactions.\n       */\n      export interface EvalItem {\n        /**\n         * Inputs to the model - can contain template strings. Supports text, output text,\n         * input images, and input audio, either as a single item or an array of items.\n         */\n        content:\n          | string\n          | ResponsesAPI.ResponseInputText\n          | EvalItem.OutputText\n          | EvalItem.InputImage\n          | ResponsesAPI.ResponseInputAudio\n          | GraderModelsAPI.GraderInputs;\n\n        /**\n         * The role of the message input. One of `user`, `assistant`, `system`, or\n         * `developer`.\n         */\n        role: 'user' | 'assistant' | 'system' | 'developer';\n\n        /**\n         * The type of the message input. Always `message`.\n         */\n        type?: 'message';\n      }\n\n      export namespace EvalItem {\n        /**\n         * A text output from the model.\n         */\n        export interface OutputText {\n          /**\n           * The text output from the model.\n           */\n          text: string;\n\n          /**\n           * The type of the output text. Always `output_text`.\n           */\n          type: 'output_text';\n        }\n\n        /**\n         * An image input block used within EvalItem content arrays.\n         */\n        export interface InputImage {\n          /**\n           * The URL of the image input.\n           */\n          image_url: string;\n\n          /**\n           * The type of the image input. Always `input_image`.\n           */\n          type: 'input_image';\n\n          /**\n           * The detail level of the image to be sent to the model. One of `high`, `low`, or\n           * `auto`. Defaults to `auto`.\n           */\n          detail?: string;\n        }\n      }\n    }\n\n    export interface ItemReference {\n      /**\n       * A reference to a variable in the `item` namespace. Ie, \"item.name\"\n       */\n      item_reference: string;\n\n      /**\n       * The type of input messages. Always `item_reference`.\n       */\n      type: 'item_reference';\n    }\n\n    export interface SamplingParams {\n      /**\n       * The maximum number of tokens in the generated output.\n       */\n      max_completion_tokens?: number;\n\n      /**\n       * Constrains effort on reasoning for\n       * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n       * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n       * Reducing reasoning effort can result in faster responses and fewer tokens used\n       * on reasoning in a response.\n       *\n       * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n       *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n       *   calls are supported for all reasoning values in gpt-5.1.\n       * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n       *   support `none`.\n       * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n       * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n       */\n      reasoning_effort?: Shared.ReasoningEffort | null;\n\n      /**\n       * A seed value to initialize the randomness, during sampling.\n       */\n      seed?: number;\n\n      /**\n       * A higher temperature increases randomness in the outputs.\n       */\n      temperature?: number;\n\n      /**\n       * Configuration options for a text response from the model. Can be plain text or\n       * structured JSON data. Learn more:\n       *\n       * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n       * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n       */\n      text?: SamplingParams.Text;\n\n      /**\n       * An array of tools the model may call while generating a response. You can\n       * specify which tool to use by setting the `tool_choice` parameter.\n       *\n       * The two categories of tools you can provide the model are:\n       *\n       * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n       *   capabilities, like\n       *   [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n       *   [file search](https://platform.openai.com/docs/guides/tools-file-search).\n       *   Learn more about\n       *   [built-in tools](https://platform.openai.com/docs/guides/tools).\n       * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n       *   the model to call your own code. Learn more about\n       *   [function calling](https://platform.openai.com/docs/guides/function-calling).\n       */\n      tools?: Array<ResponsesAPI.Tool>;\n\n      /**\n       * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n       */\n      top_p?: number;\n    }\n\n    export namespace SamplingParams {\n      /**\n       * Configuration options for a text response from the model. Can be plain text or\n       * structured JSON data. Learn more:\n       *\n       * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n       * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n       */\n      export interface Text {\n        /**\n         * An object specifying the format that the model must output.\n         *\n         * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n         * ensures the model will match your supplied JSON schema. Learn more in the\n         * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n         *\n         * The default format is `{ \"type\": \"text\" }` with no additional options.\n         *\n         * **Not recommended for gpt-4o and newer models:**\n         *\n         * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n         * ensures the message the model generates is valid JSON. Using `json_schema` is\n         * preferred for models that support it.\n         */\n        format?: ResponsesAPI.ResponseFormatTextConfig;\n      }\n    }\n  }\n\n  export interface PerModelUsage {\n    /**\n     * The number of tokens retrieved from cache.\n     */\n    cached_tokens: number;\n\n    /**\n     * The number of completion tokens generated.\n     */\n    completion_tokens: number;\n\n    /**\n     * The number of invocations.\n     */\n    invocation_count: number;\n\n    /**\n     * The name of the model.\n     */\n    model_name: string;\n\n    /**\n     * The number of prompt tokens used.\n     */\n    prompt_tokens: number;\n\n    /**\n     * The total number of tokens used.\n     */\n    total_tokens: number;\n  }\n\n  export interface PerTestingCriteriaResult {\n    /**\n     * Number of tests failed for this criteria.\n     */\n    failed: number;\n\n    /**\n     * Number of tests passed for this criteria.\n     */\n    passed: number;\n\n    /**\n     * A description of the testing criteria.\n     */\n    testing_criteria: string;\n  }\n\n  /**\n   * Counters summarizing the outcomes of the evaluation run.\n   */\n  export interface ResultCounts {\n    /**\n     * Number of output items that resulted in an error.\n     */\n    errored: number;\n\n    /**\n     * Number of output items that failed to pass the evaluation.\n     */\n    failed: number;\n\n    /**\n     * Number of output items that passed the evaluation.\n     */\n    passed: number;\n\n    /**\n     * Total number of executed output items.\n     */\n    total: number;\n  }\n}\n\nexport interface RunDeleteResponse {\n  deleted?: boolean;\n\n  object?: string;\n\n  run_id?: string;\n}\n\n/**\n * A schema representing an evaluation run.\n */\nexport interface RunCancelResponse {\n  /**\n   * Unique identifier for the evaluation run.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the evaluation run was created.\n   */\n  created_at: number;\n\n  /**\n   * Information about the run's data source.\n   */\n  data_source:\n    | CreateEvalJSONLRunDataSource\n    | CreateEvalCompletionsRunDataSource\n    | RunCancelResponse.Responses;\n\n  /**\n   * An object representing an error response from the Eval API.\n   */\n  error: EvalAPIError;\n\n  /**\n   * The identifier of the associated evaluation.\n   */\n  eval_id: string;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The model that is evaluated, if applicable.\n   */\n  model: string;\n\n  /**\n   * The name of the evaluation run.\n   */\n  name: string;\n\n  /**\n   * The type of the object. Always \"eval.run\".\n   */\n  object: 'eval.run';\n\n  /**\n   * Usage statistics for each model during the evaluation run.\n   */\n  per_model_usage: Array<RunCancelResponse.PerModelUsage>;\n\n  /**\n   * Results per testing criteria applied during the evaluation run.\n   */\n  per_testing_criteria_results: Array<RunCancelResponse.PerTestingCriteriaResult>;\n\n  /**\n   * The URL to the rendered evaluation run report on the UI dashboard.\n   */\n  report_url: string;\n\n  /**\n   * Counters summarizing the outcomes of the evaluation run.\n   */\n  result_counts: RunCancelResponse.ResultCounts;\n\n  /**\n   * The status of the evaluation run.\n   */\n  status: string;\n}\n\nexport namespace RunCancelResponse {\n  /**\n   * A ResponsesRunDataSource object describing a model sampling configuration.\n   */\n  export interface Responses {\n    /**\n     * Determines what populates the `item` namespace in this run's data source.\n     */\n    source: Responses.FileContent | Responses.FileID | Responses.Responses;\n\n    /**\n     * The type of run data source. Always `responses`.\n     */\n    type: 'responses';\n\n    /**\n     * Used when sampling from a model. Dictates the structure of the messages passed\n     * into the model. Can either be a reference to a prebuilt trajectory (ie,\n     * `item.input_trajectory`), or a template with variable references to the `item`\n     * namespace.\n     */\n    input_messages?: Responses.Template | Responses.ItemReference;\n\n    /**\n     * The name of the model to use for generating completions (e.g. \"o3-mini\").\n     */\n    model?: string;\n\n    sampling_params?: Responses.SamplingParams;\n  }\n\n  export namespace Responses {\n    export interface FileContent {\n      /**\n       * The content of the jsonl file.\n       */\n      content: Array<FileContent.Content>;\n\n      /**\n       * The type of jsonl source. Always `file_content`.\n       */\n      type: 'file_content';\n    }\n\n    export namespace FileContent {\n      export interface Content {\n        item: { [key: string]: unknown };\n\n        sample?: { [key: string]: unknown };\n      }\n    }\n\n    export interface FileID {\n      /**\n       * The identifier of the file.\n       */\n      id: string;\n\n      /**\n       * The type of jsonl source. Always `file_id`.\n       */\n      type: 'file_id';\n    }\n\n    /**\n     * A EvalResponsesSource object describing a run data source configuration.\n     */\n    export interface Responses {\n      /**\n       * The type of run data source. Always `responses`.\n       */\n      type: 'responses';\n\n      /**\n       * Only include items created after this timestamp (inclusive). This is a query\n       * parameter used to select responses.\n       */\n      created_after?: number | null;\n\n      /**\n       * Only include items created before this timestamp (inclusive). This is a query\n       * parameter used to select responses.\n       */\n      created_before?: number | null;\n\n      /**\n       * Optional string to search the 'instructions' field. This is a query parameter\n       * used to select responses.\n       */\n      instructions_search?: string | null;\n\n      /**\n       * Metadata filter for the responses. This is a query parameter used to select\n       * responses.\n       */\n      metadata?: unknown | null;\n\n      /**\n       * The name of the model to find responses for. This is a query parameter used to\n       * select responses.\n       */\n      model?: string | null;\n\n      /**\n       * Constrains effort on reasoning for\n       * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n       * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n       * Reducing reasoning effort can result in faster responses and fewer tokens used\n       * on reasoning in a response.\n       *\n       * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n       *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n       *   calls are supported for all reasoning values in gpt-5.1.\n       * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n       *   support `none`.\n       * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n       * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n       */\n      reasoning_effort?: Shared.ReasoningEffort | null;\n\n      /**\n       * Sampling temperature. This is a query parameter used to select responses.\n       */\n      temperature?: number | null;\n\n      /**\n       * List of tool names. This is a query parameter used to select responses.\n       */\n      tools?: Array<string> | null;\n\n      /**\n       * Nucleus sampling parameter. This is a query parameter used to select responses.\n       */\n      top_p?: number | null;\n\n      /**\n       * List of user identifiers. This is a query parameter used to select responses.\n       */\n      users?: Array<string> | null;\n    }\n\n    export interface Template {\n      /**\n       * A list of chat messages forming the prompt or context. May include variable\n       * references to the `item` namespace, ie {{item.name}}.\n       */\n      template: Array<Template.ChatMessage | Template.EvalItem>;\n\n      /**\n       * The type of input messages. Always `template`.\n       */\n      type: 'template';\n    }\n\n    export namespace Template {\n      export interface ChatMessage {\n        /**\n         * The content of the message.\n         */\n        content: string;\n\n        /**\n         * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n         */\n        role: string;\n      }\n\n      /**\n       * A message input to the model with a role indicating instruction following\n       * hierarchy. Instructions given with the `developer` or `system` role take\n       * precedence over instructions given with the `user` role. Messages with the\n       * `assistant` role are presumed to have been generated by the model in previous\n       * interactions.\n       */\n      export interface EvalItem {\n        /**\n         * Inputs to the model - can contain template strings. Supports text, output text,\n         * input images, and input audio, either as a single item or an array of items.\n         */\n        content:\n          | string\n          | ResponsesAPI.ResponseInputText\n          | EvalItem.OutputText\n          | EvalItem.InputImage\n          | ResponsesAPI.ResponseInputAudio\n          | GraderModelsAPI.GraderInputs;\n\n        /**\n         * The role of the message input. One of `user`, `assistant`, `system`, or\n         * `developer`.\n         */\n        role: 'user' | 'assistant' | 'system' | 'developer';\n\n        /**\n         * The type of the message input. Always `message`.\n         */\n        type?: 'message';\n      }\n\n      export namespace EvalItem {\n        /**\n         * A text output from the model.\n         */\n        export interface OutputText {\n          /**\n           * The text output from the model.\n           */\n          text: string;\n\n          /**\n           * The type of the output text. Always `output_text`.\n           */\n          type: 'output_text';\n        }\n\n        /**\n         * An image input block used within EvalItem content arrays.\n         */\n        export interface InputImage {\n          /**\n           * The URL of the image input.\n           */\n          image_url: string;\n\n          /**\n           * The type of the image input. Always `input_image`.\n           */\n          type: 'input_image';\n\n          /**\n           * The detail level of the image to be sent to the model. One of `high`, `low`, or\n           * `auto`. Defaults to `auto`.\n           */\n          detail?: string;\n        }\n      }\n    }\n\n    export interface ItemReference {\n      /**\n       * A reference to a variable in the `item` namespace. Ie, \"item.name\"\n       */\n      item_reference: string;\n\n      /**\n       * The type of input messages. Always `item_reference`.\n       */\n      type: 'item_reference';\n    }\n\n    export interface SamplingParams {\n      /**\n       * The maximum number of tokens in the generated output.\n       */\n      max_completion_tokens?: number;\n\n      /**\n       * Constrains effort on reasoning for\n       * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n       * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n       * Reducing reasoning effort can result in faster responses and fewer tokens used\n       * on reasoning in a response.\n       *\n       * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n       *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n       *   calls are supported for all reasoning values in gpt-5.1.\n       * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n       *   support `none`.\n       * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n       * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n       */\n      reasoning_effort?: Shared.ReasoningEffort | null;\n\n      /**\n       * A seed value to initialize the randomness, during sampling.\n       */\n      seed?: number;\n\n      /**\n       * A higher temperature increases randomness in the outputs.\n       */\n      temperature?: number;\n\n      /**\n       * Configuration options for a text response from the model. Can be plain text or\n       * structured JSON data. Learn more:\n       *\n       * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n       * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n       */\n      text?: SamplingParams.Text;\n\n      /**\n       * An array of tools the model may call while generating a response. You can\n       * specify which tool to use by setting the `tool_choice` parameter.\n       *\n       * The two categories of tools you can provide the model are:\n       *\n       * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n       *   capabilities, like\n       *   [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n       *   [file search](https://platform.openai.com/docs/guides/tools-file-search).\n       *   Learn more about\n       *   [built-in tools](https://platform.openai.com/docs/guides/tools).\n       * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n       *   the model to call your own code. Learn more about\n       *   [function calling](https://platform.openai.com/docs/guides/function-calling).\n       */\n      tools?: Array<ResponsesAPI.Tool>;\n\n      /**\n       * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n       */\n      top_p?: number;\n    }\n\n    export namespace SamplingParams {\n      /**\n       * Configuration options for a text response from the model. Can be plain text or\n       * structured JSON data. Learn more:\n       *\n       * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n       * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n       */\n      export interface Text {\n        /**\n         * An object specifying the format that the model must output.\n         *\n         * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n         * ensures the model will match your supplied JSON schema. Learn more in the\n         * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n         *\n         * The default format is `{ \"type\": \"text\" }` with no additional options.\n         *\n         * **Not recommended for gpt-4o and newer models:**\n         *\n         * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n         * ensures the message the model generates is valid JSON. Using `json_schema` is\n         * preferred for models that support it.\n         */\n        format?: ResponsesAPI.ResponseFormatTextConfig;\n      }\n    }\n  }\n\n  export interface PerModelUsage {\n    /**\n     * The number of tokens retrieved from cache.\n     */\n    cached_tokens: number;\n\n    /**\n     * The number of completion tokens generated.\n     */\n    completion_tokens: number;\n\n    /**\n     * The number of invocations.\n     */\n    invocation_count: number;\n\n    /**\n     * The name of the model.\n     */\n    model_name: string;\n\n    /**\n     * The number of prompt tokens used.\n     */\n    prompt_tokens: number;\n\n    /**\n     * The total number of tokens used.\n     */\n    total_tokens: number;\n  }\n\n  export interface PerTestingCriteriaResult {\n    /**\n     * Number of tests failed for this criteria.\n     */\n    failed: number;\n\n    /**\n     * Number of tests passed for this criteria.\n     */\n    passed: number;\n\n    /**\n     * A description of the testing criteria.\n     */\n    testing_criteria: string;\n  }\n\n  /**\n   * Counters summarizing the outcomes of the evaluation run.\n   */\n  export interface ResultCounts {\n    /**\n     * Number of output items that resulted in an error.\n     */\n    errored: number;\n\n    /**\n     * Number of output items that failed to pass the evaluation.\n     */\n    failed: number;\n\n    /**\n     * Number of output items that passed the evaluation.\n     */\n    passed: number;\n\n    /**\n     * Total number of executed output items.\n     */\n    total: number;\n  }\n}\n\nexport interface RunCreateParams {\n  /**\n   * Details about the run's data source.\n   */\n  data_source:\n    | CreateEvalJSONLRunDataSource\n    | CreateEvalCompletionsRunDataSource\n    | RunCreateParams.CreateEvalResponsesRunDataSource;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The name of the run.\n   */\n  name?: string;\n}\n\nexport namespace RunCreateParams {\n  /**\n   * A ResponsesRunDataSource object describing a model sampling configuration.\n   */\n  export interface CreateEvalResponsesRunDataSource {\n    /**\n     * Determines what populates the `item` namespace in this run's data source.\n     */\n    source:\n      | CreateEvalResponsesRunDataSource.FileContent\n      | CreateEvalResponsesRunDataSource.FileID\n      | CreateEvalResponsesRunDataSource.Responses;\n\n    /**\n     * The type of run data source. Always `responses`.\n     */\n    type: 'responses';\n\n    /**\n     * Used when sampling from a model. Dictates the structure of the messages passed\n     * into the model. Can either be a reference to a prebuilt trajectory (ie,\n     * `item.input_trajectory`), or a template with variable references to the `item`\n     * namespace.\n     */\n    input_messages?:\n      | CreateEvalResponsesRunDataSource.Template\n      | CreateEvalResponsesRunDataSource.ItemReference;\n\n    /**\n     * The name of the model to use for generating completions (e.g. \"o3-mini\").\n     */\n    model?: string;\n\n    sampling_params?: CreateEvalResponsesRunDataSource.SamplingParams;\n  }\n\n  export namespace CreateEvalResponsesRunDataSource {\n    export interface FileContent {\n      /**\n       * The content of the jsonl file.\n       */\n      content: Array<FileContent.Content>;\n\n      /**\n       * The type of jsonl source. Always `file_content`.\n       */\n      type: 'file_content';\n    }\n\n    export namespace FileContent {\n      export interface Content {\n        item: { [key: string]: unknown };\n\n        sample?: { [key: string]: unknown };\n      }\n    }\n\n    export interface FileID {\n      /**\n       * The identifier of the file.\n       */\n      id: string;\n\n      /**\n       * The type of jsonl source. Always `file_id`.\n       */\n      type: 'file_id';\n    }\n\n    /**\n     * A EvalResponsesSource object describing a run data source configuration.\n     */\n    export interface Responses {\n      /**\n       * The type of run data source. Always `responses`.\n       */\n      type: 'responses';\n\n      /**\n       * Only include items created after this timestamp (inclusive). This is a query\n       * parameter used to select responses.\n       */\n      created_after?: number | null;\n\n      /**\n       * Only include items created before this timestamp (inclusive). This is a query\n       * parameter used to select responses.\n       */\n      created_before?: number | null;\n\n      /**\n       * Optional string to search the 'instructions' field. This is a query parameter\n       * used to select responses.\n       */\n      instructions_search?: string | null;\n\n      /**\n       * Metadata filter for the responses. This is a query parameter used to select\n       * responses.\n       */\n      metadata?: unknown | null;\n\n      /**\n       * The name of the model to find responses for. This is a query parameter used to\n       * select responses.\n       */\n      model?: string | null;\n\n      /**\n       * Constrains effort on reasoning for\n       * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n       * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n       * Reducing reasoning effort can result in faster responses and fewer tokens used\n       * on reasoning in a response.\n       *\n       * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n       *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n       *   calls are supported for all reasoning values in gpt-5.1.\n       * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n       *   support `none`.\n       * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n       * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n       */\n      reasoning_effort?: Shared.ReasoningEffort | null;\n\n      /**\n       * Sampling temperature. This is a query parameter used to select responses.\n       */\n      temperature?: number | null;\n\n      /**\n       * List of tool names. This is a query parameter used to select responses.\n       */\n      tools?: Array<string> | null;\n\n      /**\n       * Nucleus sampling parameter. This is a query parameter used to select responses.\n       */\n      top_p?: number | null;\n\n      /**\n       * List of user identifiers. This is a query parameter used to select responses.\n       */\n      users?: Array<string> | null;\n    }\n\n    export interface Template {\n      /**\n       * A list of chat messages forming the prompt or context. May include variable\n       * references to the `item` namespace, ie {{item.name}}.\n       */\n      template: Array<Template.ChatMessage | Template.EvalItem>;\n\n      /**\n       * The type of input messages. Always `template`.\n       */\n      type: 'template';\n    }\n\n    export namespace Template {\n      export interface ChatMessage {\n        /**\n         * The content of the message.\n         */\n        content: string;\n\n        /**\n         * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n         */\n        role: string;\n      }\n\n      /**\n       * A message input to the model with a role indicating instruction following\n       * hierarchy. Instructions given with the `developer` or `system` role take\n       * precedence over instructions given with the `user` role. Messages with the\n       * `assistant` role are presumed to have been generated by the model in previous\n       * interactions.\n       */\n      export interface EvalItem {\n        /**\n         * Inputs to the model - can contain template strings. Supports text, output text,\n         * input images, and input audio, either as a single item or an array of items.\n         */\n        content:\n          | string\n          | ResponsesAPI.ResponseInputText\n          | EvalItem.OutputText\n          | EvalItem.InputImage\n          | ResponsesAPI.ResponseInputAudio\n          | GraderModelsAPI.GraderInputs;\n\n        /**\n         * The role of the message input. One of `user`, `assistant`, `system`, or\n         * `developer`.\n         */\n        role: 'user' | 'assistant' | 'system' | 'developer';\n\n        /**\n         * The type of the message input. Always `message`.\n         */\n        type?: 'message';\n      }\n\n      export namespace EvalItem {\n        /**\n         * A text output from the model.\n         */\n        export interface OutputText {\n          /**\n           * The text output from the model.\n           */\n          text: string;\n\n          /**\n           * The type of the output text. Always `output_text`.\n           */\n          type: 'output_text';\n        }\n\n        /**\n         * An image input block used within EvalItem content arrays.\n         */\n        export interface InputImage {\n          /**\n           * The URL of the image input.\n           */\n          image_url: string;\n\n          /**\n           * The type of the image input. Always `input_image`.\n           */\n          type: 'input_image';\n\n          /**\n           * The detail level of the image to be sent to the model. One of `high`, `low`, or\n           * `auto`. Defaults to `auto`.\n           */\n          detail?: string;\n        }\n      }\n    }\n\n    export interface ItemReference {\n      /**\n       * A reference to a variable in the `item` namespace. Ie, \"item.name\"\n       */\n      item_reference: string;\n\n      /**\n       * The type of input messages. Always `item_reference`.\n       */\n      type: 'item_reference';\n    }\n\n    export interface SamplingParams {\n      /**\n       * The maximum number of tokens in the generated output.\n       */\n      max_completion_tokens?: number;\n\n      /**\n       * Constrains effort on reasoning for\n       * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n       * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n       * Reducing reasoning effort can result in faster responses and fewer tokens used\n       * on reasoning in a response.\n       *\n       * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n       *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n       *   calls are supported for all reasoning values in gpt-5.1.\n       * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n       *   support `none`.\n       * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n       * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n       */\n      reasoning_effort?: Shared.ReasoningEffort | null;\n\n      /**\n       * A seed value to initialize the randomness, during sampling.\n       */\n      seed?: number;\n\n      /**\n       * A higher temperature increases randomness in the outputs.\n       */\n      temperature?: number;\n\n      /**\n       * Configuration options for a text response from the model. Can be plain text or\n       * structured JSON data. Learn more:\n       *\n       * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n       * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n       */\n      text?: SamplingParams.Text;\n\n      /**\n       * An array of tools the model may call while generating a response. You can\n       * specify which tool to use by setting the `tool_choice` parameter.\n       *\n       * The two categories of tools you can provide the model are:\n       *\n       * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n       *   capabilities, like\n       *   [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n       *   [file search](https://platform.openai.com/docs/guides/tools-file-search).\n       *   Learn more about\n       *   [built-in tools](https://platform.openai.com/docs/guides/tools).\n       * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n       *   the model to call your own code. Learn more about\n       *   [function calling](https://platform.openai.com/docs/guides/function-calling).\n       */\n      tools?: Array<ResponsesAPI.Tool>;\n\n      /**\n       * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n       */\n      top_p?: number;\n    }\n\n    export namespace SamplingParams {\n      /**\n       * Configuration options for a text response from the model. Can be plain text or\n       * structured JSON data. Learn more:\n       *\n       * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n       * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n       */\n      export interface Text {\n        /**\n         * An object specifying the format that the model must output.\n         *\n         * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n         * ensures the model will match your supplied JSON schema. Learn more in the\n         * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n         *\n         * The default format is `{ \"type\": \"text\" }` with no additional options.\n         *\n         * **Not recommended for gpt-4o and newer models:**\n         *\n         * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n         * ensures the message the model generates is valid JSON. Using `json_schema` is\n         * preferred for models that support it.\n         */\n        format?: ResponsesAPI.ResponseFormatTextConfig;\n      }\n    }\n  }\n}\n\nexport interface RunRetrieveParams {\n  /**\n   * The ID of the evaluation to retrieve runs for.\n   */\n  eval_id: string;\n}\n\nexport interface RunListParams extends CursorPageParams {\n  /**\n   * Sort order for runs by timestamp. Use `asc` for ascending order or `desc` for\n   * descending order. Defaults to `asc`.\n   */\n  order?: 'asc' | 'desc';\n\n  /**\n   * Filter runs by status. One of `queued` | `in_progress` | `failed` | `completed`\n   * | `canceled`.\n   */\n  status?: 'queued' | 'in_progress' | 'completed' | 'canceled' | 'failed';\n}\n\nexport interface RunDeleteParams {\n  /**\n   * The ID of the evaluation to delete the run from.\n   */\n  eval_id: string;\n}\n\nexport interface RunCancelParams {\n  /**\n   * The ID of the evaluation whose run you want to cancel.\n   */\n  eval_id: string;\n}\n\nRuns.OutputItems = OutputItems;\n\nexport declare namespace Runs {\n  export {\n    type CreateEvalCompletionsRunDataSource as CreateEvalCompletionsRunDataSource,\n    type CreateEvalJSONLRunDataSource as CreateEvalJSONLRunDataSource,\n    type EvalAPIError as EvalAPIError,\n    type RunCreateResponse as RunCreateResponse,\n    type RunRetrieveResponse as RunRetrieveResponse,\n    type RunListResponse as RunListResponse,\n    type RunDeleteResponse as RunDeleteResponse,\n    type RunCancelResponse as RunCancelResponse,\n    type RunListResponsesPage as RunListResponsesPage,\n    type RunCreateParams as RunCreateParams,\n    type RunRetrieveParams as RunRetrieveParams,\n    type RunListParams as RunListParams,\n    type RunDeleteParams as RunDeleteParams,\n    type RunCancelParams as RunCancelParams,\n  };\n\n  export {\n    OutputItems as OutputItems,\n    type OutputItemRetrieveResponse as OutputItemRetrieveResponse,\n    type OutputItemListResponse as OutputItemListResponse,\n    type OutputItemListResponsesPage as OutputItemListResponsesPage,\n    type OutputItemRetrieveParams as OutputItemRetrieveParams,\n    type OutputItemListParams as OutputItemListParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/evals/runs.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './runs/index';\n"
  },
  {
    "path": "src/resources/evals.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './evals/index';\n"
  },
  {
    "path": "src/resources/files.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport { APIPromise } from '../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../core/pagination';\nimport { type Uploadable } from '../core/uploads';\nimport { buildHeaders } from '../internal/headers';\nimport { RequestOptions } from '../internal/request-options';\nimport { sleep } from '../internal/utils/sleep';\nimport { APIConnectionTimeoutError } from '../error';\nimport { multipartFormRequestOptions } from '../internal/uploads';\nimport { path } from '../internal/utils/path';\n\n/**\n * Files are used to upload documents that can be used with features like Assistants and Fine-tuning.\n */\nexport class Files extends APIResource {\n  /**\n   * Upload a file that can be used across various endpoints. Individual files can be\n   * up to 512 MB, and each project can store up to 2.5 TB of files in total. There\n   * is no organization-wide storage limit.\n   *\n   * - The Assistants API supports files up to 2 million tokens and of specific file\n   *   types. See the\n   *   [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools)\n   *   for details.\n   * - The Fine-tuning API only supports `.jsonl` files. The input also has certain\n   *   required formats for fine-tuning\n   *   [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input)\n   *   or\n   *   [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)\n   *   models.\n   * - The Batch API only supports `.jsonl` files up to 200 MB in size. The input\n   *   also has a specific required\n   *   [format](https://platform.openai.com/docs/api-reference/batch/request-input).\n   *\n   * Please [contact us](https://help.openai.com/) if you need to increase these\n   * storage limits.\n   */\n  create(body: FileCreateParams, options?: RequestOptions): APIPromise<FileObject> {\n    return this._client.post('/files', multipartFormRequestOptions({ body, ...options }, this._client));\n  }\n\n  /**\n   * Returns information about a specific file.\n   */\n  retrieve(fileID: string, options?: RequestOptions): APIPromise<FileObject> {\n    return this._client.get(path`/files/${fileID}`, options);\n  }\n\n  /**\n   * Returns a list of files.\n   */\n  list(\n    query: FileListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<FileObjectsPage, FileObject> {\n    return this._client.getAPIList('/files', CursorPage<FileObject>, { query, ...options });\n  }\n\n  /**\n   * Delete a file and remove it from all vector stores.\n   */\n  delete(fileID: string, options?: RequestOptions): APIPromise<FileDeleted> {\n    return this._client.delete(path`/files/${fileID}`, options);\n  }\n\n  /**\n   * Returns the contents of the specified file.\n   */\n  content(fileID: string, options?: RequestOptions): APIPromise<Response> {\n    return this._client.get(path`/files/${fileID}/content`, {\n      ...options,\n      headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),\n      __binaryResponse: true,\n    });\n  }\n\n  /**\n   * Waits for the given file to be processed, default timeout is 30 mins.\n   */\n  async waitForProcessing(\n    id: string,\n    { pollInterval = 5000, maxWait = 30 * 60 * 1000 }: { pollInterval?: number; maxWait?: number } = {},\n  ): Promise<FileObject> {\n    const TERMINAL_STATES = new Set(['processed', 'error', 'deleted']);\n\n    const start = Date.now();\n    let file = await this.retrieve(id);\n\n    while (!file.status || !TERMINAL_STATES.has(file.status)) {\n      await sleep(pollInterval);\n\n      file = await this.retrieve(id);\n      if (Date.now() - start > maxWait) {\n        throw new APIConnectionTimeoutError({\n          message: `Giving up on waiting for file ${id} to finish processing after ${maxWait} milliseconds.`,\n        });\n      }\n    }\n\n    return file;\n  }\n}\n\nexport type FileObjectsPage = CursorPage<FileObject>;\n\nexport type FileContent = string;\n\nexport interface FileDeleted {\n  id: string;\n\n  deleted: boolean;\n\n  object: 'file';\n}\n\n/**\n * The `File` object represents a document that has been uploaded to OpenAI.\n */\nexport interface FileObject {\n  /**\n   * The file identifier, which can be referenced in the API endpoints.\n   */\n  id: string;\n\n  /**\n   * The size of the file, in bytes.\n   */\n  bytes: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the file was created.\n   */\n  created_at: number;\n\n  /**\n   * The name of the file.\n   */\n  filename: string;\n\n  /**\n   * The object type, which is always `file`.\n   */\n  object: 'file';\n\n  /**\n   * The intended purpose of the file. Supported values are `assistants`,\n   * `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`,\n   * `vision`, and `user_data`.\n   */\n  purpose:\n    | 'assistants'\n    | 'assistants_output'\n    | 'batch'\n    | 'batch_output'\n    | 'fine-tune'\n    | 'fine-tune-results'\n    | 'vision'\n    | 'user_data';\n\n  /**\n   * @deprecated Deprecated. The current status of the file, which can be either\n   * `uploaded`, `processed`, or `error`.\n   */\n  status: 'uploaded' | 'processed' | 'error';\n\n  /**\n   * The Unix timestamp (in seconds) for when the file will expire.\n   */\n  expires_at?: number;\n\n  /**\n   * @deprecated Deprecated. For details on why a fine-tuning training file failed\n   * validation, see the `error` field on `fine_tuning.job`.\n   */\n  status_details?: string;\n}\n\n/**\n * The intended purpose of the uploaded file. One of:\n *\n * - `assistants`: Used in the Assistants API\n * - `batch`: Used in the Batch API\n * - `fine-tune`: Used for fine-tuning\n * - `vision`: Images used for vision fine-tuning\n * - `user_data`: Flexible file type for any purpose\n * - `evals`: Used for eval data sets\n */\nexport type FilePurpose = 'assistants' | 'batch' | 'fine-tune' | 'vision' | 'user_data' | 'evals';\n\nexport interface FileCreateParams {\n  /**\n   * The File object (not file name) to be uploaded.\n   */\n  file: Uploadable;\n\n  /**\n   * The intended purpose of the uploaded file. One of:\n   *\n   * - `assistants`: Used in the Assistants API\n   * - `batch`: Used in the Batch API\n   * - `fine-tune`: Used for fine-tuning\n   * - `vision`: Images used for vision fine-tuning\n   * - `user_data`: Flexible file type for any purpose\n   * - `evals`: Used for eval data sets\n   */\n  purpose: FilePurpose;\n\n  /**\n   * The expiration policy for a file. By default, files with `purpose=batch` expire\n   * after 30 days and all other files are persisted until they are manually deleted.\n   */\n  expires_after?: FileCreateParams.ExpiresAfter;\n}\n\nexport namespace FileCreateParams {\n  /**\n   * The expiration policy for a file. By default, files with `purpose=batch` expire\n   * after 30 days and all other files are persisted until they are manually deleted.\n   */\n  export interface ExpiresAfter {\n    /**\n     * Anchor timestamp after which the expiration policy applies. Supported anchors:\n     * `created_at`.\n     */\n    anchor: 'created_at';\n\n    /**\n     * The number of seconds after the anchor time that the file will expire. Must be\n     * between 3600 (1 hour) and 2592000 (30 days).\n     */\n    seconds: number;\n  }\n}\n\nexport interface FileListParams extends CursorPageParams {\n  /**\n   * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n   * order and `desc` for descending order.\n   */\n  order?: 'asc' | 'desc';\n\n  /**\n   * Only return files with the given purpose.\n   */\n  purpose?: string;\n}\n\nexport declare namespace Files {\n  export {\n    type FileContent as FileContent,\n    type FileDeleted as FileDeleted,\n    type FileObject as FileObject,\n    type FilePurpose as FilePurpose,\n    type FileObjectsPage as FileObjectsPage,\n    type FileCreateParams as FileCreateParams,\n    type FileListParams as FileListParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/fine-tuning/alpha/alpha.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as GradersAPI from './graders';\nimport {\n  GraderRunParams,\n  GraderRunResponse,\n  GraderValidateParams,\n  GraderValidateResponse,\n  Graders,\n} from './graders';\n\nexport class Alpha extends APIResource {\n  graders: GradersAPI.Graders = new GradersAPI.Graders(this._client);\n}\n\nAlpha.Graders = Graders;\n\nexport declare namespace Alpha {\n  export {\n    Graders as Graders,\n    type GraderRunResponse as GraderRunResponse,\n    type GraderValidateResponse as GraderValidateResponse,\n    type GraderRunParams as GraderRunParams,\n    type GraderValidateParams as GraderValidateParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/fine-tuning/alpha/graders.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as GraderModelsAPI from '../../graders/grader-models';\nimport { APIPromise } from '../../../core/api-promise';\nimport { RequestOptions } from '../../../internal/request-options';\n\n/**\n * Manage fine-tuning jobs to tailor a model to your specific training data.\n */\nexport class Graders extends APIResource {\n  /**\n   * Run a grader.\n   *\n   * @example\n   * ```ts\n   * const response = await client.fineTuning.alpha.graders.run({\n   *   grader: {\n   *     input: 'input',\n   *     name: 'name',\n   *     operation: 'eq',\n   *     reference: 'reference',\n   *     type: 'string_check',\n   *   },\n   *   model_sample: 'model_sample',\n   * });\n   * ```\n   */\n  run(body: GraderRunParams, options?: RequestOptions): APIPromise<GraderRunResponse> {\n    return this._client.post('/fine_tuning/alpha/graders/run', { body, ...options });\n  }\n\n  /**\n   * Validate a grader.\n   *\n   * @example\n   * ```ts\n   * const response =\n   *   await client.fineTuning.alpha.graders.validate({\n   *     grader: {\n   *       input: 'input',\n   *       name: 'name',\n   *       operation: 'eq',\n   *       reference: 'reference',\n   *       type: 'string_check',\n   *     },\n   *   });\n   * ```\n   */\n  validate(body: GraderValidateParams, options?: RequestOptions): APIPromise<GraderValidateResponse> {\n    return this._client.post('/fine_tuning/alpha/graders/validate', { body, ...options });\n  }\n}\n\nexport interface GraderRunResponse {\n  metadata: GraderRunResponse.Metadata;\n\n  model_grader_token_usage_per_model: { [key: string]: unknown };\n\n  reward: number;\n\n  sub_rewards: { [key: string]: unknown };\n}\n\nexport namespace GraderRunResponse {\n  export interface Metadata {\n    errors: Metadata.Errors;\n\n    execution_time: number;\n\n    name: string;\n\n    sampled_model_name: string | null;\n\n    scores: { [key: string]: unknown };\n\n    token_usage: number | null;\n\n    type: string;\n  }\n\n  export namespace Metadata {\n    export interface Errors {\n      formula_parse_error: boolean;\n\n      invalid_variable_error: boolean;\n\n      model_grader_parse_error: boolean;\n\n      model_grader_refusal_error: boolean;\n\n      model_grader_server_error: boolean;\n\n      model_grader_server_error_details: string | null;\n\n      other_error: boolean;\n\n      python_grader_runtime_error: boolean;\n\n      python_grader_runtime_error_details: string | null;\n\n      python_grader_server_error: boolean;\n\n      python_grader_server_error_type: string | null;\n\n      sample_parse_error: boolean;\n\n      truncated_observation_error: boolean;\n\n      unresponsive_reward_error: boolean;\n    }\n  }\n}\n\nexport interface GraderValidateResponse {\n  /**\n   * The grader used for the fine-tuning job.\n   */\n  grader?:\n    | GraderModelsAPI.StringCheckGrader\n    | GraderModelsAPI.TextSimilarityGrader\n    | GraderModelsAPI.PythonGrader\n    | GraderModelsAPI.ScoreModelGrader\n    | GraderModelsAPI.MultiGrader;\n}\n\nexport interface GraderRunParams {\n  /**\n   * The grader used for the fine-tuning job.\n   */\n  grader:\n    | GraderModelsAPI.StringCheckGrader\n    | GraderModelsAPI.TextSimilarityGrader\n    | GraderModelsAPI.PythonGrader\n    | GraderModelsAPI.ScoreModelGrader\n    | GraderModelsAPI.MultiGrader;\n\n  /**\n   * The model sample to be evaluated. This value will be used to populate the\n   * `sample` namespace. See\n   * [the guide](https://platform.openai.com/docs/guides/graders) for more details.\n   * The `output_json` variable will be populated if the model sample is a valid JSON\n   * string.\n   */\n  model_sample: string;\n\n  /**\n   * The dataset item provided to the grader. This will be used to populate the\n   * `item` namespace. See\n   * [the guide](https://platform.openai.com/docs/guides/graders) for more details.\n   */\n  item?: unknown;\n}\n\nexport interface GraderValidateParams {\n  /**\n   * The grader used for the fine-tuning job.\n   */\n  grader:\n    | GraderModelsAPI.StringCheckGrader\n    | GraderModelsAPI.TextSimilarityGrader\n    | GraderModelsAPI.PythonGrader\n    | GraderModelsAPI.ScoreModelGrader\n    | GraderModelsAPI.MultiGrader;\n}\n\nexport declare namespace Graders {\n  export {\n    type GraderRunResponse as GraderRunResponse,\n    type GraderValidateResponse as GraderValidateResponse,\n    type GraderRunParams as GraderRunParams,\n    type GraderValidateParams as GraderValidateParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/fine-tuning/alpha/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Alpha } from './alpha';\nexport {\n  Graders,\n  type GraderRunResponse,\n  type GraderValidateResponse,\n  type GraderRunParams,\n  type GraderValidateParams,\n} from './graders';\n"
  },
  {
    "path": "src/resources/fine-tuning/alpha.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './alpha/index';\n"
  },
  {
    "path": "src/resources/fine-tuning/checkpoints/checkpoints.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as PermissionsAPI from './permissions';\nimport {\n  PermissionCreateParams,\n  PermissionCreateResponse,\n  PermissionCreateResponsesPage,\n  PermissionDeleteParams,\n  PermissionDeleteResponse,\n  PermissionListParams,\n  PermissionListResponse,\n  PermissionListResponsesPage,\n  PermissionRetrieveParams,\n  PermissionRetrieveResponse,\n  Permissions,\n} from './permissions';\n\nexport class Checkpoints extends APIResource {\n  permissions: PermissionsAPI.Permissions = new PermissionsAPI.Permissions(this._client);\n}\n\nCheckpoints.Permissions = Permissions;\n\nexport declare namespace Checkpoints {\n  export {\n    Permissions as Permissions,\n    type PermissionCreateResponse as PermissionCreateResponse,\n    type PermissionRetrieveResponse as PermissionRetrieveResponse,\n    type PermissionListResponse as PermissionListResponse,\n    type PermissionDeleteResponse as PermissionDeleteResponse,\n    type PermissionCreateResponsesPage as PermissionCreateResponsesPage,\n    type PermissionListResponsesPage as PermissionListResponsesPage,\n    type PermissionCreateParams as PermissionCreateParams,\n    type PermissionRetrieveParams as PermissionRetrieveParams,\n    type PermissionListParams as PermissionListParams,\n    type PermissionDeleteParams as PermissionDeleteParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/fine-tuning/checkpoints/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Checkpoints } from './checkpoints';\nexport {\n  Permissions,\n  type PermissionCreateResponse,\n  type PermissionRetrieveResponse,\n  type PermissionListResponse,\n  type PermissionDeleteResponse,\n  type PermissionCreateParams,\n  type PermissionRetrieveParams,\n  type PermissionListParams,\n  type PermissionDeleteParams,\n  type PermissionCreateResponsesPage,\n  type PermissionListResponsesPage,\n} from './permissions';\n"
  },
  {
    "path": "src/resources/fine-tuning/checkpoints/permissions.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { APIPromise } from '../../../core/api-promise';\nimport {\n  ConversationCursorPage,\n  type ConversationCursorPageParams,\n  Page,\n  PagePromise,\n} from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Manage fine-tuning jobs to tailor a model to your specific training data.\n */\nexport class Permissions extends APIResource {\n  /**\n   * **NOTE:** Calling this endpoint requires an [admin API key](../admin-api-keys).\n   *\n   * This enables organization owners to share fine-tuned models with other projects\n   * in their organization.\n   *\n   * @example\n   * ```ts\n   * // Automatically fetches more pages as needed.\n   * for await (const permissionCreateResponse of client.fineTuning.checkpoints.permissions.create(\n   *   'ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd',\n   *   { project_ids: ['string'] },\n   * )) {\n   *   // ...\n   * }\n   * ```\n   */\n  create(\n    fineTunedModelCheckpoint: string,\n    body: PermissionCreateParams,\n    options?: RequestOptions,\n  ): PagePromise<PermissionCreateResponsesPage, PermissionCreateResponse> {\n    return this._client.getAPIList(\n      path`/fine_tuning/checkpoints/${fineTunedModelCheckpoint}/permissions`,\n      Page<PermissionCreateResponse>,\n      { body, method: 'post', ...options },\n    );\n  }\n\n  /**\n   * **NOTE:** This endpoint requires an [admin API key](../admin-api-keys).\n   *\n   * Organization owners can use this endpoint to view all permissions for a\n   * fine-tuned model checkpoint.\n   *\n   * @deprecated Retrieve is deprecated. Please swap to the paginated list method instead.\n   */\n  retrieve(\n    fineTunedModelCheckpoint: string,\n    query: PermissionRetrieveParams | null | undefined = {},\n    options?: RequestOptions,\n  ): APIPromise<PermissionRetrieveResponse> {\n    return this._client.get(path`/fine_tuning/checkpoints/${fineTunedModelCheckpoint}/permissions`, {\n      query,\n      ...options,\n    });\n  }\n\n  /**\n   * **NOTE:** This endpoint requires an [admin API key](../admin-api-keys).\n   *\n   * Organization owners can use this endpoint to view all permissions for a\n   * fine-tuned model checkpoint.\n   *\n   * @example\n   * ```ts\n   * // Automatically fetches more pages as needed.\n   * for await (const permissionListResponse of client.fineTuning.checkpoints.permissions.list(\n   *   'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n   * )) {\n   *   // ...\n   * }\n   * ```\n   */\n  list(\n    fineTunedModelCheckpoint: string,\n    query: PermissionListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<PermissionListResponsesPage, PermissionListResponse> {\n    return this._client.getAPIList(\n      path`/fine_tuning/checkpoints/${fineTunedModelCheckpoint}/permissions`,\n      ConversationCursorPage<PermissionListResponse>,\n      { query, ...options },\n    );\n  }\n\n  /**\n   * **NOTE:** This endpoint requires an [admin API key](../admin-api-keys).\n   *\n   * Organization owners can use this endpoint to delete a permission for a\n   * fine-tuned model checkpoint.\n   *\n   * @example\n   * ```ts\n   * const permission =\n   *   await client.fineTuning.checkpoints.permissions.delete(\n   *     'cp_zc4Q7MP6XxulcVzj4MZdwsAB',\n   *     {\n   *       fine_tuned_model_checkpoint:\n   *         'ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd',\n   *     },\n   *   );\n   * ```\n   */\n  delete(\n    permissionID: string,\n    params: PermissionDeleteParams,\n    options?: RequestOptions,\n  ): APIPromise<PermissionDeleteResponse> {\n    const { fine_tuned_model_checkpoint } = params;\n    return this._client.delete(\n      path`/fine_tuning/checkpoints/${fine_tuned_model_checkpoint}/permissions/${permissionID}`,\n      options,\n    );\n  }\n}\n\n// Note: no pagination actually occurs yet, this is for forwards-compatibility.\nexport type PermissionCreateResponsesPage = Page<PermissionCreateResponse>;\n\nexport type PermissionListResponsesPage = ConversationCursorPage<PermissionListResponse>;\n\n/**\n * The `checkpoint.permission` object represents a permission for a fine-tuned\n * model checkpoint.\n */\nexport interface PermissionCreateResponse {\n  /**\n   * The permission identifier, which can be referenced in the API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the permission was created.\n   */\n  created_at: number;\n\n  /**\n   * The object type, which is always \"checkpoint.permission\".\n   */\n  object: 'checkpoint.permission';\n\n  /**\n   * The project identifier that the permission is for.\n   */\n  project_id: string;\n}\n\nexport interface PermissionRetrieveResponse {\n  data: Array<PermissionRetrieveResponse.Data>;\n\n  has_more: boolean;\n\n  object: 'list';\n\n  first_id?: string | null;\n\n  last_id?: string | null;\n}\n\nexport namespace PermissionRetrieveResponse {\n  /**\n   * The `checkpoint.permission` object represents a permission for a fine-tuned\n   * model checkpoint.\n   */\n  export interface Data {\n    /**\n     * The permission identifier, which can be referenced in the API endpoints.\n     */\n    id: string;\n\n    /**\n     * The Unix timestamp (in seconds) for when the permission was created.\n     */\n    created_at: number;\n\n    /**\n     * The object type, which is always \"checkpoint.permission\".\n     */\n    object: 'checkpoint.permission';\n\n    /**\n     * The project identifier that the permission is for.\n     */\n    project_id: string;\n  }\n}\n\n/**\n * The `checkpoint.permission` object represents a permission for a fine-tuned\n * model checkpoint.\n */\nexport interface PermissionListResponse {\n  /**\n   * The permission identifier, which can be referenced in the API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the permission was created.\n   */\n  created_at: number;\n\n  /**\n   * The object type, which is always \"checkpoint.permission\".\n   */\n  object: 'checkpoint.permission';\n\n  /**\n   * The project identifier that the permission is for.\n   */\n  project_id: string;\n}\n\nexport interface PermissionDeleteResponse {\n  /**\n   * The ID of the fine-tuned model checkpoint permission that was deleted.\n   */\n  id: string;\n\n  /**\n   * Whether the fine-tuned model checkpoint permission was successfully deleted.\n   */\n  deleted: boolean;\n\n  /**\n   * The object type, which is always \"checkpoint.permission\".\n   */\n  object: 'checkpoint.permission';\n}\n\nexport interface PermissionCreateParams {\n  /**\n   * The project identifiers to grant access to.\n   */\n  project_ids: Array<string>;\n}\n\nexport interface PermissionRetrieveParams {\n  /**\n   * Identifier for the last permission ID from the previous pagination request.\n   */\n  after?: string;\n\n  /**\n   * Number of permissions to retrieve.\n   */\n  limit?: number;\n\n  /**\n   * The order in which to retrieve permissions.\n   */\n  order?: 'ascending' | 'descending';\n\n  /**\n   * The ID of the project to get permissions for.\n   */\n  project_id?: string;\n}\n\nexport interface PermissionListParams extends ConversationCursorPageParams {\n  /**\n   * The order in which to retrieve permissions.\n   */\n  order?: 'ascending' | 'descending';\n\n  /**\n   * The ID of the project to get permissions for.\n   */\n  project_id?: string;\n}\n\nexport interface PermissionDeleteParams {\n  /**\n   * The ID of the fine-tuned model checkpoint to delete a permission for.\n   */\n  fine_tuned_model_checkpoint: string;\n}\n\nexport declare namespace Permissions {\n  export {\n    type PermissionCreateResponse as PermissionCreateResponse,\n    type PermissionRetrieveResponse as PermissionRetrieveResponse,\n    type PermissionListResponse as PermissionListResponse,\n    type PermissionDeleteResponse as PermissionDeleteResponse,\n    type PermissionCreateResponsesPage as PermissionCreateResponsesPage,\n    type PermissionListResponsesPage as PermissionListResponsesPage,\n    type PermissionCreateParams as PermissionCreateParams,\n    type PermissionRetrieveParams as PermissionRetrieveParams,\n    type PermissionListParams as PermissionListParams,\n    type PermissionDeleteParams as PermissionDeleteParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/fine-tuning/checkpoints.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './checkpoints/index';\n"
  },
  {
    "path": "src/resources/fine-tuning/fine-tuning.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as MethodsAPI from './methods';\nimport {\n  DpoHyperparameters,\n  DpoMethod,\n  Methods,\n  ReinforcementHyperparameters,\n  ReinforcementMethod,\n  SupervisedHyperparameters,\n  SupervisedMethod,\n} from './methods';\nimport * as AlphaAPI from './alpha/alpha';\nimport { Alpha } from './alpha/alpha';\nimport * as CheckpointsAPI from './checkpoints/checkpoints';\nimport { Checkpoints } from './checkpoints/checkpoints';\nimport * as JobsAPI from './jobs/jobs';\nimport {\n  FineTuningJob,\n  FineTuningJobEvent,\n  FineTuningJobEventsPage,\n  FineTuningJobIntegration,\n  FineTuningJobWandbIntegration,\n  FineTuningJobWandbIntegrationObject,\n  FineTuningJobsPage,\n  JobCreateParams,\n  JobListEventsParams,\n  JobListParams,\n  Jobs,\n} from './jobs/jobs';\n\nexport class FineTuning extends APIResource {\n  methods: MethodsAPI.Methods = new MethodsAPI.Methods(this._client);\n  jobs: JobsAPI.Jobs = new JobsAPI.Jobs(this._client);\n  checkpoints: CheckpointsAPI.Checkpoints = new CheckpointsAPI.Checkpoints(this._client);\n  alpha: AlphaAPI.Alpha = new AlphaAPI.Alpha(this._client);\n}\n\nFineTuning.Methods = Methods;\nFineTuning.Jobs = Jobs;\nFineTuning.Checkpoints = Checkpoints;\nFineTuning.Alpha = Alpha;\n\nexport declare namespace FineTuning {\n  export {\n    Methods as Methods,\n    type DpoHyperparameters as DpoHyperparameters,\n    type DpoMethod as DpoMethod,\n    type ReinforcementHyperparameters as ReinforcementHyperparameters,\n    type ReinforcementMethod as ReinforcementMethod,\n    type SupervisedHyperparameters as SupervisedHyperparameters,\n    type SupervisedMethod as SupervisedMethod,\n  };\n\n  export {\n    Jobs as Jobs,\n    type FineTuningJob as FineTuningJob,\n    type FineTuningJobEvent as FineTuningJobEvent,\n    type FineTuningJobWandbIntegration as FineTuningJobWandbIntegration,\n    type FineTuningJobWandbIntegrationObject as FineTuningJobWandbIntegrationObject,\n    type FineTuningJobIntegration as FineTuningJobIntegration,\n    type FineTuningJobsPage as FineTuningJobsPage,\n    type FineTuningJobEventsPage as FineTuningJobEventsPage,\n    type JobCreateParams as JobCreateParams,\n    type JobListParams as JobListParams,\n    type JobListEventsParams as JobListEventsParams,\n  };\n\n  export { Checkpoints as Checkpoints };\n\n  export { Alpha as Alpha };\n}\n"
  },
  {
    "path": "src/resources/fine-tuning/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Alpha } from './alpha/index';\nexport { Checkpoints } from './checkpoints/index';\nexport { FineTuning } from './fine-tuning';\nexport {\n  Jobs,\n  type FineTuningJob,\n  type FineTuningJobEvent,\n  type FineTuningJobWandbIntegration,\n  type FineTuningJobWandbIntegrationObject,\n  type FineTuningJobIntegration,\n  type JobCreateParams,\n  type JobListParams,\n  type JobListEventsParams,\n  type FineTuningJobsPage,\n  type FineTuningJobEventsPage,\n} from './jobs/index';\nexport {\n  Methods,\n  type DpoHyperparameters,\n  type DpoMethod,\n  type ReinforcementHyperparameters,\n  type ReinforcementMethod,\n  type SupervisedHyperparameters,\n  type SupervisedMethod,\n} from './methods';\n"
  },
  {
    "path": "src/resources/fine-tuning/jobs/checkpoints.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Manage fine-tuning jobs to tailor a model to your specific training data.\n */\nexport class Checkpoints extends APIResource {\n  /**\n   * List checkpoints for a fine-tuning job.\n   *\n   * @example\n   * ```ts\n   * // Automatically fetches more pages as needed.\n   * for await (const fineTuningJobCheckpoint of client.fineTuning.jobs.checkpoints.list(\n   *   'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n   * )) {\n   *   // ...\n   * }\n   * ```\n   */\n  list(\n    fineTuningJobID: string,\n    query: CheckpointListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<FineTuningJobCheckpointsPage, FineTuningJobCheckpoint> {\n    return this._client.getAPIList(\n      path`/fine_tuning/jobs/${fineTuningJobID}/checkpoints`,\n      CursorPage<FineTuningJobCheckpoint>,\n      { query, ...options },\n    );\n  }\n}\n\nexport type FineTuningJobCheckpointsPage = CursorPage<FineTuningJobCheckpoint>;\n\n/**\n * The `fine_tuning.job.checkpoint` object represents a model checkpoint for a\n * fine-tuning job that is ready to use.\n */\nexport interface FineTuningJobCheckpoint {\n  /**\n   * The checkpoint identifier, which can be referenced in the API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the checkpoint was created.\n   */\n  created_at: number;\n\n  /**\n   * The name of the fine-tuned checkpoint model that is created.\n   */\n  fine_tuned_model_checkpoint: string;\n\n  /**\n   * The name of the fine-tuning job that this checkpoint was created from.\n   */\n  fine_tuning_job_id: string;\n\n  /**\n   * Metrics at the step number during the fine-tuning job.\n   */\n  metrics: FineTuningJobCheckpoint.Metrics;\n\n  /**\n   * The object type, which is always \"fine_tuning.job.checkpoint\".\n   */\n  object: 'fine_tuning.job.checkpoint';\n\n  /**\n   * The step number that the checkpoint was created at.\n   */\n  step_number: number;\n}\n\nexport namespace FineTuningJobCheckpoint {\n  /**\n   * Metrics at the step number during the fine-tuning job.\n   */\n  export interface Metrics {\n    full_valid_loss?: number;\n\n    full_valid_mean_token_accuracy?: number;\n\n    step?: number;\n\n    train_loss?: number;\n\n    train_mean_token_accuracy?: number;\n\n    valid_loss?: number;\n\n    valid_mean_token_accuracy?: number;\n  }\n}\n\nexport interface CheckpointListParams extends CursorPageParams {}\n\nexport declare namespace Checkpoints {\n  export {\n    type FineTuningJobCheckpoint as FineTuningJobCheckpoint,\n    type FineTuningJobCheckpointsPage as FineTuningJobCheckpointsPage,\n    type CheckpointListParams as CheckpointListParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/fine-tuning/jobs/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport {\n  Checkpoints,\n  type FineTuningJobCheckpoint,\n  type CheckpointListParams,\n  type FineTuningJobCheckpointsPage,\n} from './checkpoints';\nexport {\n  Jobs,\n  type FineTuningJob,\n  type FineTuningJobEvent,\n  type FineTuningJobWandbIntegration,\n  type FineTuningJobWandbIntegrationObject,\n  type FineTuningJobIntegration,\n  type JobCreateParams,\n  type JobListParams,\n  type JobListEventsParams,\n  type FineTuningJobsPage,\n  type FineTuningJobEventsPage,\n} from './jobs';\n"
  },
  {
    "path": "src/resources/fine-tuning/jobs/jobs.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as Shared from '../../shared';\nimport * as MethodsAPI from '../methods';\nimport * as CheckpointsAPI from './checkpoints';\nimport {\n  CheckpointListParams,\n  Checkpoints,\n  FineTuningJobCheckpoint,\n  FineTuningJobCheckpointsPage,\n} from './checkpoints';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Manage fine-tuning jobs to tailor a model to your specific training data.\n */\nexport class Jobs extends APIResource {\n  checkpoints: CheckpointsAPI.Checkpoints = new CheckpointsAPI.Checkpoints(this._client);\n\n  /**\n   * Creates a fine-tuning job which begins the process of creating a new model from\n   * a given dataset.\n   *\n   * Response includes details of the enqueued job including job status and the name\n   * of the fine-tuned models once complete.\n   *\n   * [Learn more about fine-tuning](https://platform.openai.com/docs/guides/model-optimization)\n   *\n   * @example\n   * ```ts\n   * const fineTuningJob = await client.fineTuning.jobs.create({\n   *   model: 'gpt-4o-mini',\n   *   training_file: 'file-abc123',\n   * });\n   * ```\n   */\n  create(body: JobCreateParams, options?: RequestOptions): APIPromise<FineTuningJob> {\n    return this._client.post('/fine_tuning/jobs', { body, ...options });\n  }\n\n  /**\n   * Get info about a fine-tuning job.\n   *\n   * [Learn more about fine-tuning](https://platform.openai.com/docs/guides/model-optimization)\n   *\n   * @example\n   * ```ts\n   * const fineTuningJob = await client.fineTuning.jobs.retrieve(\n   *   'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n   * );\n   * ```\n   */\n  retrieve(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob> {\n    return this._client.get(path`/fine_tuning/jobs/${fineTuningJobID}`, options);\n  }\n\n  /**\n   * List your organization's fine-tuning jobs\n   *\n   * @example\n   * ```ts\n   * // Automatically fetches more pages as needed.\n   * for await (const fineTuningJob of client.fineTuning.jobs.list()) {\n   *   // ...\n   * }\n   * ```\n   */\n  list(\n    query: JobListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<FineTuningJobsPage, FineTuningJob> {\n    return this._client.getAPIList('/fine_tuning/jobs', CursorPage<FineTuningJob>, { query, ...options });\n  }\n\n  /**\n   * Immediately cancel a fine-tune job.\n   *\n   * @example\n   * ```ts\n   * const fineTuningJob = await client.fineTuning.jobs.cancel(\n   *   'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n   * );\n   * ```\n   */\n  cancel(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob> {\n    return this._client.post(path`/fine_tuning/jobs/${fineTuningJobID}/cancel`, options);\n  }\n\n  /**\n   * Get status updates for a fine-tuning job.\n   *\n   * @example\n   * ```ts\n   * // Automatically fetches more pages as needed.\n   * for await (const fineTuningJobEvent of client.fineTuning.jobs.listEvents(\n   *   'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n   * )) {\n   *   // ...\n   * }\n   * ```\n   */\n  listEvents(\n    fineTuningJobID: string,\n    query: JobListEventsParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<FineTuningJobEventsPage, FineTuningJobEvent> {\n    return this._client.getAPIList(\n      path`/fine_tuning/jobs/${fineTuningJobID}/events`,\n      CursorPage<FineTuningJobEvent>,\n      { query, ...options },\n    );\n  }\n\n  /**\n   * Pause a fine-tune job.\n   *\n   * @example\n   * ```ts\n   * const fineTuningJob = await client.fineTuning.jobs.pause(\n   *   'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n   * );\n   * ```\n   */\n  pause(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob> {\n    return this._client.post(path`/fine_tuning/jobs/${fineTuningJobID}/pause`, options);\n  }\n\n  /**\n   * Resume a fine-tune job.\n   *\n   * @example\n   * ```ts\n   * const fineTuningJob = await client.fineTuning.jobs.resume(\n   *   'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n   * );\n   * ```\n   */\n  resume(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob> {\n    return this._client.post(path`/fine_tuning/jobs/${fineTuningJobID}/resume`, options);\n  }\n}\n\nexport type FineTuningJobsPage = CursorPage<FineTuningJob>;\n\nexport type FineTuningJobEventsPage = CursorPage<FineTuningJobEvent>;\n\n/**\n * The `fine_tuning.job` object represents a fine-tuning job that has been created\n * through the API.\n */\nexport interface FineTuningJob {\n  /**\n   * The object identifier, which can be referenced in the API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the fine-tuning job was created.\n   */\n  created_at: number;\n\n  /**\n   * For fine-tuning jobs that have `failed`, this will contain more information on\n   * the cause of the failure.\n   */\n  error: FineTuningJob.Error | null;\n\n  /**\n   * The name of the fine-tuned model that is being created. The value will be null\n   * if the fine-tuning job is still running.\n   */\n  fine_tuned_model: string | null;\n\n  /**\n   * The Unix timestamp (in seconds) for when the fine-tuning job was finished. The\n   * value will be null if the fine-tuning job is still running.\n   */\n  finished_at: number | null;\n\n  /**\n   * The hyperparameters used for the fine-tuning job. This value will only be\n   * returned when running `supervised` jobs.\n   */\n  hyperparameters: FineTuningJob.Hyperparameters;\n\n  /**\n   * The base model that is being fine-tuned.\n   */\n  model: string;\n\n  /**\n   * The object type, which is always \"fine_tuning.job\".\n   */\n  object: 'fine_tuning.job';\n\n  /**\n   * The organization that owns the fine-tuning job.\n   */\n  organization_id: string;\n\n  /**\n   * The compiled results file ID(s) for the fine-tuning job. You can retrieve the\n   * results with the\n   * [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).\n   */\n  result_files: Array<string>;\n\n  /**\n   * The seed used for the fine-tuning job.\n   */\n  seed: number;\n\n  /**\n   * The current status of the fine-tuning job, which can be either\n   * `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`.\n   */\n  status: 'validating_files' | 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled';\n\n  /**\n   * The total number of billable tokens processed by this fine-tuning job. The value\n   * will be null if the fine-tuning job is still running.\n   */\n  trained_tokens: number | null;\n\n  /**\n   * The file ID used for training. You can retrieve the training data with the\n   * [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).\n   */\n  training_file: string;\n\n  /**\n   * The file ID used for validation. You can retrieve the validation results with\n   * the\n   * [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).\n   */\n  validation_file: string | null;\n\n  /**\n   * The Unix timestamp (in seconds) for when the fine-tuning job is estimated to\n   * finish. The value will be null if the fine-tuning job is not running.\n   */\n  estimated_finish?: number | null;\n\n  /**\n   * A list of integrations to enable for this fine-tuning job.\n   */\n  integrations?: Array<FineTuningJobWandbIntegrationObject> | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The method used for fine-tuning.\n   */\n  method?: FineTuningJob.Method;\n}\n\nexport namespace FineTuningJob {\n  /**\n   * For fine-tuning jobs that have `failed`, this will contain more information on\n   * the cause of the failure.\n   */\n  export interface Error {\n    /**\n     * A machine-readable error code.\n     */\n    code: string;\n\n    /**\n     * A human-readable error message.\n     */\n    message: string;\n\n    /**\n     * The parameter that was invalid, usually `training_file` or `validation_file`.\n     * This field will be null if the failure was not parameter-specific.\n     */\n    param: string | null;\n  }\n\n  /**\n   * The hyperparameters used for the fine-tuning job. This value will only be\n   * returned when running `supervised` jobs.\n   */\n  export interface Hyperparameters {\n    /**\n     * Number of examples in each batch. A larger batch size means that model\n     * parameters are updated less frequently, but with lower variance.\n     */\n    batch_size?: 'auto' | number | null;\n\n    /**\n     * Scaling factor for the learning rate. A smaller learning rate may be useful to\n     * avoid overfitting.\n     */\n    learning_rate_multiplier?: 'auto' | number;\n\n    /**\n     * The number of epochs to train the model for. An epoch refers to one full cycle\n     * through the training dataset.\n     */\n    n_epochs?: 'auto' | number;\n  }\n\n  /**\n   * The method used for fine-tuning.\n   */\n  export interface Method {\n    /**\n     * The type of method. Is either `supervised`, `dpo`, or `reinforcement`.\n     */\n    type: 'supervised' | 'dpo' | 'reinforcement';\n\n    /**\n     * Configuration for the DPO fine-tuning method.\n     */\n    dpo?: MethodsAPI.DpoMethod;\n\n    /**\n     * Configuration for the reinforcement fine-tuning method.\n     */\n    reinforcement?: MethodsAPI.ReinforcementMethod;\n\n    /**\n     * Configuration for the supervised fine-tuning method.\n     */\n    supervised?: MethodsAPI.SupervisedMethod;\n  }\n}\n\n/**\n * Fine-tuning job event object\n */\nexport interface FineTuningJobEvent {\n  /**\n   * The object identifier.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the fine-tuning job was created.\n   */\n  created_at: number;\n\n  /**\n   * The log level of the event.\n   */\n  level: 'info' | 'warn' | 'error';\n\n  /**\n   * The message of the event.\n   */\n  message: string;\n\n  /**\n   * The object type, which is always \"fine_tuning.job.event\".\n   */\n  object: 'fine_tuning.job.event';\n\n  /**\n   * The data associated with the event.\n   */\n  data?: unknown;\n\n  /**\n   * The type of event.\n   */\n  type?: 'message' | 'metrics';\n}\n\n/**\n * The settings for your integration with Weights and Biases. This payload\n * specifies the project that metrics will be sent to. Optionally, you can set an\n * explicit display name for your run, add tags to your run, and set a default\n * entity (team, username, etc) to be associated with your run.\n */\nexport interface FineTuningJobWandbIntegration {\n  /**\n   * The name of the project that the new run will be created under.\n   */\n  project: string;\n\n  /**\n   * The entity to use for the run. This allows you to set the team or username of\n   * the WandB user that you would like associated with the run. If not set, the\n   * default entity for the registered WandB API key is used.\n   */\n  entity?: string | null;\n\n  /**\n   * A display name to set for the run. If not set, we will use the Job ID as the\n   * name.\n   */\n  name?: string | null;\n\n  /**\n   * A list of tags to be attached to the newly created run. These tags are passed\n   * through directly to WandB. Some default tags are generated by OpenAI:\n   * \"openai/finetune\", \"openai/{base-model}\", \"openai/{ftjob-abcdef}\".\n   */\n  tags?: Array<string>;\n}\n\nexport interface FineTuningJobWandbIntegrationObject {\n  /**\n   * The type of the integration being enabled for the fine-tuning job\n   */\n  type: 'wandb';\n\n  /**\n   * The settings for your integration with Weights and Biases. This payload\n   * specifies the project that metrics will be sent to. Optionally, you can set an\n   * explicit display name for your run, add tags to your run, and set a default\n   * entity (team, username, etc) to be associated with your run.\n   */\n  wandb: FineTuningJobWandbIntegration;\n}\n\nexport type FineTuningJobIntegration = FineTuningJobWandbIntegrationObject;\n\nexport interface JobCreateParams {\n  /**\n   * The name of the model to fine-tune. You can select one of the\n   * [supported models](https://platform.openai.com/docs/guides/fine-tuning#which-models-can-be-fine-tuned).\n   */\n  model: (string & {}) | 'babbage-002' | 'davinci-002' | 'gpt-3.5-turbo' | 'gpt-4o-mini';\n\n  /**\n   * The ID of an uploaded file that contains training data.\n   *\n   * See [upload file](https://platform.openai.com/docs/api-reference/files/create)\n   * for how to upload a file.\n   *\n   * Your dataset must be formatted as a JSONL file. Additionally, you must upload\n   * your file with the purpose `fine-tune`.\n   *\n   * The contents of the file should differ depending on if the model uses the\n   * [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input),\n   * [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)\n   * format, or if the fine-tuning method uses the\n   * [preference](https://platform.openai.com/docs/api-reference/fine-tuning/preference-input)\n   * format.\n   *\n   * See the\n   * [fine-tuning guide](https://platform.openai.com/docs/guides/model-optimization)\n   * for more details.\n   */\n  training_file: string;\n\n  /**\n   * @deprecated The hyperparameters used for the fine-tuning job. This value is now\n   * deprecated in favor of `method`, and should be passed in under the `method`\n   * parameter.\n   */\n  hyperparameters?: JobCreateParams.Hyperparameters;\n\n  /**\n   * A list of integrations to enable for your fine-tuning job.\n   */\n  integrations?: Array<JobCreateParams.Integration> | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The method used for fine-tuning.\n   */\n  method?: JobCreateParams.Method;\n\n  /**\n   * The seed controls the reproducibility of the job. Passing in the same seed and\n   * job parameters should produce the same results, but may differ in rare cases. If\n   * a seed is not specified, one will be generated for you.\n   */\n  seed?: number | null;\n\n  /**\n   * A string of up to 64 characters that will be added to your fine-tuned model\n   * name.\n   *\n   * For example, a `suffix` of \"custom-model-name\" would produce a model name like\n   * `ft:gpt-4o-mini:openai:custom-model-name:7p4lURel`.\n   */\n  suffix?: string | null;\n\n  /**\n   * The ID of an uploaded file that contains validation data.\n   *\n   * If you provide this file, the data is used to generate validation metrics\n   * periodically during fine-tuning. These metrics can be viewed in the fine-tuning\n   * results file. The same data should not be present in both train and validation\n   * files.\n   *\n   * Your dataset must be formatted as a JSONL file. You must upload your file with\n   * the purpose `fine-tune`.\n   *\n   * See the\n   * [fine-tuning guide](https://platform.openai.com/docs/guides/model-optimization)\n   * for more details.\n   */\n  validation_file?: string | null;\n}\n\nexport namespace JobCreateParams {\n  /**\n   * @deprecated The hyperparameters used for the fine-tuning job. This value is now\n   * deprecated in favor of `method`, and should be passed in under the `method`\n   * parameter.\n   */\n  export interface Hyperparameters {\n    /**\n     * Number of examples in each batch. A larger batch size means that model\n     * parameters are updated less frequently, but with lower variance.\n     */\n    batch_size?: 'auto' | number;\n\n    /**\n     * Scaling factor for the learning rate. A smaller learning rate may be useful to\n     * avoid overfitting.\n     */\n    learning_rate_multiplier?: 'auto' | number;\n\n    /**\n     * The number of epochs to train the model for. An epoch refers to one full cycle\n     * through the training dataset.\n     */\n    n_epochs?: 'auto' | number;\n  }\n\n  export interface Integration {\n    /**\n     * The type of integration to enable. Currently, only \"wandb\" (Weights and Biases)\n     * is supported.\n     */\n    type: 'wandb';\n\n    /**\n     * The settings for your integration with Weights and Biases. This payload\n     * specifies the project that metrics will be sent to. Optionally, you can set an\n     * explicit display name for your run, add tags to your run, and set a default\n     * entity (team, username, etc) to be associated with your run.\n     */\n    wandb: Integration.Wandb;\n  }\n\n  export namespace Integration {\n    /**\n     * The settings for your integration with Weights and Biases. This payload\n     * specifies the project that metrics will be sent to. Optionally, you can set an\n     * explicit display name for your run, add tags to your run, and set a default\n     * entity (team, username, etc) to be associated with your run.\n     */\n    export interface Wandb {\n      /**\n       * The name of the project that the new run will be created under.\n       */\n      project: string;\n\n      /**\n       * The entity to use for the run. This allows you to set the team or username of\n       * the WandB user that you would like associated with the run. If not set, the\n       * default entity for the registered WandB API key is used.\n       */\n      entity?: string | null;\n\n      /**\n       * A display name to set for the run. If not set, we will use the Job ID as the\n       * name.\n       */\n      name?: string | null;\n\n      /**\n       * A list of tags to be attached to the newly created run. These tags are passed\n       * through directly to WandB. Some default tags are generated by OpenAI:\n       * \"openai/finetune\", \"openai/{base-model}\", \"openai/{ftjob-abcdef}\".\n       */\n      tags?: Array<string>;\n    }\n  }\n\n  /**\n   * The method used for fine-tuning.\n   */\n  export interface Method {\n    /**\n     * The type of method. Is either `supervised`, `dpo`, or `reinforcement`.\n     */\n    type: 'supervised' | 'dpo' | 'reinforcement';\n\n    /**\n     * Configuration for the DPO fine-tuning method.\n     */\n    dpo?: MethodsAPI.DpoMethod;\n\n    /**\n     * Configuration for the reinforcement fine-tuning method.\n     */\n    reinforcement?: MethodsAPI.ReinforcementMethod;\n\n    /**\n     * Configuration for the supervised fine-tuning method.\n     */\n    supervised?: MethodsAPI.SupervisedMethod;\n  }\n}\n\nexport interface JobListParams extends CursorPageParams {\n  /**\n   * Optional metadata filter. To filter, use the syntax `metadata[k]=v`.\n   * Alternatively, set `metadata=null` to indicate no metadata.\n   */\n  metadata?: { [key: string]: string } | null;\n}\n\nexport interface JobListEventsParams extends CursorPageParams {}\n\nJobs.Checkpoints = Checkpoints;\n\nexport declare namespace Jobs {\n  export {\n    type FineTuningJob as FineTuningJob,\n    type FineTuningJobEvent as FineTuningJobEvent,\n    type FineTuningJobWandbIntegration as FineTuningJobWandbIntegration,\n    type FineTuningJobWandbIntegrationObject as FineTuningJobWandbIntegrationObject,\n    type FineTuningJobIntegration as FineTuningJobIntegration,\n    type FineTuningJobsPage as FineTuningJobsPage,\n    type FineTuningJobEventsPage as FineTuningJobEventsPage,\n    type JobCreateParams as JobCreateParams,\n    type JobListParams as JobListParams,\n    type JobListEventsParams as JobListEventsParams,\n  };\n\n  export {\n    Checkpoints as Checkpoints,\n    type FineTuningJobCheckpoint as FineTuningJobCheckpoint,\n    type FineTuningJobCheckpointsPage as FineTuningJobCheckpointsPage,\n    type CheckpointListParams as CheckpointListParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/fine-tuning/jobs.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './jobs/index';\n"
  },
  {
    "path": "src/resources/fine-tuning/methods.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as GraderModelsAPI from '../graders/grader-models';\n\nexport class Methods extends APIResource {}\n\n/**\n * The hyperparameters used for the DPO fine-tuning job.\n */\nexport interface DpoHyperparameters {\n  /**\n   * Number of examples in each batch. A larger batch size means that model\n   * parameters are updated less frequently, but with lower variance.\n   */\n  batch_size?: 'auto' | number;\n\n  /**\n   * The beta value for the DPO method. A higher beta value will increase the weight\n   * of the penalty between the policy and reference model.\n   */\n  beta?: 'auto' | number;\n\n  /**\n   * Scaling factor for the learning rate. A smaller learning rate may be useful to\n   * avoid overfitting.\n   */\n  learning_rate_multiplier?: 'auto' | number;\n\n  /**\n   * The number of epochs to train the model for. An epoch refers to one full cycle\n   * through the training dataset.\n   */\n  n_epochs?: 'auto' | number;\n}\n\n/**\n * Configuration for the DPO fine-tuning method.\n */\nexport interface DpoMethod {\n  /**\n   * The hyperparameters used for the DPO fine-tuning job.\n   */\n  hyperparameters?: DpoHyperparameters;\n}\n\n/**\n * The hyperparameters used for the reinforcement fine-tuning job.\n */\nexport interface ReinforcementHyperparameters {\n  /**\n   * Number of examples in each batch. A larger batch size means that model\n   * parameters are updated less frequently, but with lower variance.\n   */\n  batch_size?: 'auto' | number;\n\n  /**\n   * Multiplier on amount of compute used for exploring search space during training.\n   */\n  compute_multiplier?: 'auto' | number;\n\n  /**\n   * The number of training steps between evaluation runs.\n   */\n  eval_interval?: 'auto' | number;\n\n  /**\n   * Number of evaluation samples to generate per training step.\n   */\n  eval_samples?: 'auto' | number;\n\n  /**\n   * Scaling factor for the learning rate. A smaller learning rate may be useful to\n   * avoid overfitting.\n   */\n  learning_rate_multiplier?: 'auto' | number;\n\n  /**\n   * The number of epochs to train the model for. An epoch refers to one full cycle\n   * through the training dataset.\n   */\n  n_epochs?: 'auto' | number;\n\n  /**\n   * Level of reasoning effort.\n   */\n  reasoning_effort?: 'default' | 'low' | 'medium' | 'high';\n}\n\n/**\n * Configuration for the reinforcement fine-tuning method.\n */\nexport interface ReinforcementMethod {\n  /**\n   * The grader used for the fine-tuning job.\n   */\n  grader:\n    | GraderModelsAPI.StringCheckGrader\n    | GraderModelsAPI.TextSimilarityGrader\n    | GraderModelsAPI.PythonGrader\n    | GraderModelsAPI.ScoreModelGrader\n    | GraderModelsAPI.MultiGrader;\n\n  /**\n   * The hyperparameters used for the reinforcement fine-tuning job.\n   */\n  hyperparameters?: ReinforcementHyperparameters;\n}\n\n/**\n * The hyperparameters used for the fine-tuning job.\n */\nexport interface SupervisedHyperparameters {\n  /**\n   * Number of examples in each batch. A larger batch size means that model\n   * parameters are updated less frequently, but with lower variance.\n   */\n  batch_size?: 'auto' | number;\n\n  /**\n   * Scaling factor for the learning rate. A smaller learning rate may be useful to\n   * avoid overfitting.\n   */\n  learning_rate_multiplier?: 'auto' | number;\n\n  /**\n   * The number of epochs to train the model for. An epoch refers to one full cycle\n   * through the training dataset.\n   */\n  n_epochs?: 'auto' | number;\n}\n\n/**\n * Configuration for the supervised fine-tuning method.\n */\nexport interface SupervisedMethod {\n  /**\n   * The hyperparameters used for the fine-tuning job.\n   */\n  hyperparameters?: SupervisedHyperparameters;\n}\n\nexport declare namespace Methods {\n  export {\n    type DpoHyperparameters as DpoHyperparameters,\n    type DpoMethod as DpoMethod,\n    type ReinforcementHyperparameters as ReinforcementHyperparameters,\n    type ReinforcementMethod as ReinforcementMethod,\n    type SupervisedHyperparameters as SupervisedHyperparameters,\n    type SupervisedMethod as SupervisedMethod,\n  };\n}\n"
  },
  {
    "path": "src/resources/fine-tuning.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './fine-tuning/index';\n"
  },
  {
    "path": "src/resources/graders/grader-models.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as GraderModelsAPI from './grader-models';\nimport * as Shared from '../shared';\nimport * as ResponsesAPI from '../responses/responses';\n\nexport class GraderModels extends APIResource {}\n\n/**\n * A list of inputs, each of which may be either an input text, output text, input\n * image, or input audio object.\n */\nexport type GraderInputs = Array<\n  | string\n  | ResponsesAPI.ResponseInputText\n  | GraderInputs.OutputText\n  | GraderInputs.InputImage\n  | ResponsesAPI.ResponseInputAudio\n>;\n\nexport namespace GraderInputs {\n  /**\n   * A text output from the model.\n   */\n  export interface OutputText {\n    /**\n     * The text output from the model.\n     */\n    text: string;\n\n    /**\n     * The type of the output text. Always `output_text`.\n     */\n    type: 'output_text';\n  }\n\n  /**\n   * An image input block used within EvalItem content arrays.\n   */\n  export interface InputImage {\n    /**\n     * The URL of the image input.\n     */\n    image_url: string;\n\n    /**\n     * The type of the image input. Always `input_image`.\n     */\n    type: 'input_image';\n\n    /**\n     * The detail level of the image to be sent to the model. One of `high`, `low`, or\n     * `auto`. Defaults to `auto`.\n     */\n    detail?: string;\n  }\n}\n\n/**\n * A LabelModelGrader object which uses a model to assign labels to each item in\n * the evaluation.\n */\nexport interface LabelModelGrader {\n  input: Array<LabelModelGrader.Input>;\n\n  /**\n   * The labels to assign to each item in the evaluation.\n   */\n  labels: Array<string>;\n\n  /**\n   * The model to use for the evaluation. Must support structured outputs.\n   */\n  model: string;\n\n  /**\n   * The name of the grader.\n   */\n  name: string;\n\n  /**\n   * The labels that indicate a passing result. Must be a subset of labels.\n   */\n  passing_labels: Array<string>;\n\n  /**\n   * The object type, which is always `label_model`.\n   */\n  type: 'label_model';\n}\n\nexport namespace LabelModelGrader {\n  /**\n   * A message input to the model with a role indicating instruction following\n   * hierarchy. Instructions given with the `developer` or `system` role take\n   * precedence over instructions given with the `user` role. Messages with the\n   * `assistant` role are presumed to have been generated by the model in previous\n   * interactions.\n   */\n  export interface Input {\n    /**\n     * Inputs to the model - can contain template strings. Supports text, output text,\n     * input images, and input audio, either as a single item or an array of items.\n     */\n    content:\n      | string\n      | ResponsesAPI.ResponseInputText\n      | Input.OutputText\n      | Input.InputImage\n      | ResponsesAPI.ResponseInputAudio\n      | GraderModelsAPI.GraderInputs;\n\n    /**\n     * The role of the message input. One of `user`, `assistant`, `system`, or\n     * `developer`.\n     */\n    role: 'user' | 'assistant' | 'system' | 'developer';\n\n    /**\n     * The type of the message input. Always `message`.\n     */\n    type?: 'message';\n  }\n\n  export namespace Input {\n    /**\n     * A text output from the model.\n     */\n    export interface OutputText {\n      /**\n       * The text output from the model.\n       */\n      text: string;\n\n      /**\n       * The type of the output text. Always `output_text`.\n       */\n      type: 'output_text';\n    }\n\n    /**\n     * An image input block used within EvalItem content arrays.\n     */\n    export interface InputImage {\n      /**\n       * The URL of the image input.\n       */\n      image_url: string;\n\n      /**\n       * The type of the image input. Always `input_image`.\n       */\n      type: 'input_image';\n\n      /**\n       * The detail level of the image to be sent to the model. One of `high`, `low`, or\n       * `auto`. Defaults to `auto`.\n       */\n      detail?: string;\n    }\n  }\n}\n\n/**\n * A MultiGrader object combines the output of multiple graders to produce a single\n * score.\n */\nexport interface MultiGrader {\n  /**\n   * A formula to calculate the output based on grader results.\n   */\n  calculate_output: string;\n\n  /**\n   * A StringCheckGrader object that performs a string comparison between input and\n   * reference using a specified operation.\n   */\n  graders: StringCheckGrader | TextSimilarityGrader | PythonGrader | ScoreModelGrader | LabelModelGrader;\n\n  /**\n   * The name of the grader.\n   */\n  name: string;\n\n  /**\n   * The object type, which is always `multi`.\n   */\n  type: 'multi';\n}\n\n/**\n * A PythonGrader object that runs a python script on the input.\n */\nexport interface PythonGrader {\n  /**\n   * The name of the grader.\n   */\n  name: string;\n\n  /**\n   * The source code of the python script.\n   */\n  source: string;\n\n  /**\n   * The object type, which is always `python`.\n   */\n  type: 'python';\n\n  /**\n   * The image tag to use for the python script.\n   */\n  image_tag?: string;\n}\n\n/**\n * A ScoreModelGrader object that uses a model to assign a score to the input.\n */\nexport interface ScoreModelGrader {\n  /**\n   * The input messages evaluated by the grader. Supports text, output text, input\n   * image, and input audio content blocks, and may include template strings.\n   */\n  input: Array<ScoreModelGrader.Input>;\n\n  /**\n   * The model to use for the evaluation.\n   */\n  model: string;\n\n  /**\n   * The name of the grader.\n   */\n  name: string;\n\n  /**\n   * The object type, which is always `score_model`.\n   */\n  type: 'score_model';\n\n  /**\n   * The range of the score. Defaults to `[0, 1]`.\n   */\n  range?: Array<number>;\n\n  /**\n   * The sampling parameters for the model.\n   */\n  sampling_params?: ScoreModelGrader.SamplingParams;\n}\n\nexport namespace ScoreModelGrader {\n  /**\n   * A message input to the model with a role indicating instruction following\n   * hierarchy. Instructions given with the `developer` or `system` role take\n   * precedence over instructions given with the `user` role. Messages with the\n   * `assistant` role are presumed to have been generated by the model in previous\n   * interactions.\n   */\n  export interface Input {\n    /**\n     * Inputs to the model - can contain template strings. Supports text, output text,\n     * input images, and input audio, either as a single item or an array of items.\n     */\n    content:\n      | string\n      | ResponsesAPI.ResponseInputText\n      | Input.OutputText\n      | Input.InputImage\n      | ResponsesAPI.ResponseInputAudio\n      | GraderModelsAPI.GraderInputs;\n\n    /**\n     * The role of the message input. One of `user`, `assistant`, `system`, or\n     * `developer`.\n     */\n    role: 'user' | 'assistant' | 'system' | 'developer';\n\n    /**\n     * The type of the message input. Always `message`.\n     */\n    type?: 'message';\n  }\n\n  export namespace Input {\n    /**\n     * A text output from the model.\n     */\n    export interface OutputText {\n      /**\n       * The text output from the model.\n       */\n      text: string;\n\n      /**\n       * The type of the output text. Always `output_text`.\n       */\n      type: 'output_text';\n    }\n\n    /**\n     * An image input block used within EvalItem content arrays.\n     */\n    export interface InputImage {\n      /**\n       * The URL of the image input.\n       */\n      image_url: string;\n\n      /**\n       * The type of the image input. Always `input_image`.\n       */\n      type: 'input_image';\n\n      /**\n       * The detail level of the image to be sent to the model. One of `high`, `low`, or\n       * `auto`. Defaults to `auto`.\n       */\n      detail?: string;\n    }\n  }\n\n  /**\n   * The sampling parameters for the model.\n   */\n  export interface SamplingParams {\n    /**\n     * The maximum number of tokens the grader model may generate in its response.\n     */\n    max_completions_tokens?: number | null;\n\n    /**\n     * Constrains effort on reasoning for\n     * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n     * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n     * Reducing reasoning effort can result in faster responses and fewer tokens used\n     * on reasoning in a response.\n     *\n     * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n     *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n     *   calls are supported for all reasoning values in gpt-5.1.\n     * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n     *   support `none`.\n     * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n     * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n     */\n    reasoning_effort?: Shared.ReasoningEffort | null;\n\n    /**\n     * A seed value to initialize the randomness, during sampling.\n     */\n    seed?: number | null;\n\n    /**\n     * A higher temperature increases randomness in the outputs.\n     */\n    temperature?: number | null;\n\n    /**\n     * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n     */\n    top_p?: number | null;\n  }\n}\n\n/**\n * A StringCheckGrader object that performs a string comparison between input and\n * reference using a specified operation.\n */\nexport interface StringCheckGrader {\n  /**\n   * The input text. This may include template strings.\n   */\n  input: string;\n\n  /**\n   * The name of the grader.\n   */\n  name: string;\n\n  /**\n   * The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`.\n   */\n  operation: 'eq' | 'ne' | 'like' | 'ilike';\n\n  /**\n   * The reference text. This may include template strings.\n   */\n  reference: string;\n\n  /**\n   * The object type, which is always `string_check`.\n   */\n  type: 'string_check';\n}\n\n/**\n * A TextSimilarityGrader object which grades text based on similarity metrics.\n */\nexport interface TextSimilarityGrader {\n  /**\n   * The evaluation metric to use. One of `cosine`, `fuzzy_match`, `bleu`, `gleu`,\n   * `meteor`, `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`.\n   */\n  evaluation_metric:\n    | 'cosine'\n    | 'fuzzy_match'\n    | 'bleu'\n    | 'gleu'\n    | 'meteor'\n    | 'rouge_1'\n    | 'rouge_2'\n    | 'rouge_3'\n    | 'rouge_4'\n    | 'rouge_5'\n    | 'rouge_l';\n\n  /**\n   * The text being graded.\n   */\n  input: string;\n\n  /**\n   * The name of the grader.\n   */\n  name: string;\n\n  /**\n   * The text being graded against.\n   */\n  reference: string;\n\n  /**\n   * The type of grader.\n   */\n  type: 'text_similarity';\n}\n\nexport declare namespace GraderModels {\n  export {\n    type GraderInputs as GraderInputs,\n    type LabelModelGrader as LabelModelGrader,\n    type MultiGrader as MultiGrader,\n    type PythonGrader as PythonGrader,\n    type ScoreModelGrader as ScoreModelGrader,\n    type StringCheckGrader as StringCheckGrader,\n    type TextSimilarityGrader as TextSimilarityGrader,\n  };\n}\n"
  },
  {
    "path": "src/resources/graders/graders.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as GraderModelsAPI from './grader-models';\nimport {\n  GraderInputs,\n  GraderModels,\n  LabelModelGrader,\n  MultiGrader,\n  PythonGrader,\n  ScoreModelGrader,\n  StringCheckGrader,\n  TextSimilarityGrader,\n} from './grader-models';\n\nexport class Graders extends APIResource {\n  graderModels: GraderModelsAPI.GraderModels = new GraderModelsAPI.GraderModels(this._client);\n}\n\nGraders.GraderModels = GraderModels;\n\nexport declare namespace Graders {\n  export {\n    GraderModels as GraderModels,\n    type GraderInputs as GraderInputs,\n    type LabelModelGrader as LabelModelGrader,\n    type MultiGrader as MultiGrader,\n    type PythonGrader as PythonGrader,\n    type ScoreModelGrader as ScoreModelGrader,\n    type StringCheckGrader as StringCheckGrader,\n    type TextSimilarityGrader as TextSimilarityGrader,\n  };\n}\n"
  },
  {
    "path": "src/resources/graders/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport {\n  GraderModels,\n  type GraderInputs,\n  type LabelModelGrader,\n  type MultiGrader,\n  type PythonGrader,\n  type ScoreModelGrader,\n  type StringCheckGrader,\n  type TextSimilarityGrader,\n} from './grader-models';\nexport { Graders } from './graders';\n"
  },
  {
    "path": "src/resources/graders.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './graders/index';\n"
  },
  {
    "path": "src/resources/images.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport * as ImagesAPI from './images';\nimport { APIPromise } from '../core/api-promise';\nimport { Stream } from '../core/streaming';\nimport { type Uploadable } from '../core/uploads';\nimport { RequestOptions } from '../internal/request-options';\nimport { multipartFormRequestOptions } from '../internal/uploads';\n\n/**\n * Given a prompt and/or an input image, the model will generate a new image.\n */\nexport class Images extends APIResource {\n  /**\n   * Creates a variation of a given image. This endpoint only supports `dall-e-2`.\n   *\n   * @example\n   * ```ts\n   * const imagesResponse = await client.images.createVariation({\n   *   image: fs.createReadStream('otter.png'),\n   * });\n   * ```\n   */\n  createVariation(body: ImageCreateVariationParams, options?: RequestOptions): APIPromise<ImagesResponse> {\n    return this._client.post(\n      '/images/variations',\n      multipartFormRequestOptions({ body, ...options }, this._client),\n    );\n  }\n\n  /**\n   * Creates an edited or extended image given one or more source images and a\n   * prompt. This endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`,\n   * `gpt-image-1-mini`, and `chatgpt-image-latest`) and `dall-e-2`.\n   *\n   * @example\n   * ```ts\n   * const imagesResponse = await client.images.edit({\n   *   image: fs.createReadStream('path/to/file'),\n   *   prompt: 'A cute baby sea otter wearing a beret',\n   * });\n   * ```\n   */\n  edit(body: ImageEditParamsNonStreaming, options?: RequestOptions): APIPromise<ImagesResponse>;\n  edit(body: ImageEditParamsStreaming, options?: RequestOptions): APIPromise<Stream<ImageEditStreamEvent>>;\n  edit(\n    body: ImageEditParamsBase,\n    options?: RequestOptions,\n  ): APIPromise<Stream<ImageEditStreamEvent> | ImagesResponse>;\n  edit(\n    body: ImageEditParams,\n    options?: RequestOptions,\n  ): APIPromise<ImagesResponse> | APIPromise<Stream<ImageEditStreamEvent>> {\n    return this._client.post(\n      '/images/edits',\n      multipartFormRequestOptions({ body, ...options, stream: body.stream ?? false }, this._client),\n    ) as APIPromise<ImagesResponse> | APIPromise<Stream<ImageEditStreamEvent>>;\n  }\n\n  /**\n   * Creates an image given a prompt.\n   * [Learn more](https://platform.openai.com/docs/guides/images).\n   *\n   * @example\n   * ```ts\n   * const imagesResponse = await client.images.generate({\n   *   prompt: 'A cute baby sea otter',\n   * });\n   * ```\n   */\n  generate(body: ImageGenerateParamsNonStreaming, options?: RequestOptions): APIPromise<ImagesResponse>;\n  generate(\n    body: ImageGenerateParamsStreaming,\n    options?: RequestOptions,\n  ): APIPromise<Stream<ImageGenStreamEvent>>;\n  generate(\n    body: ImageGenerateParamsBase,\n    options?: RequestOptions,\n  ): APIPromise<Stream<ImageGenStreamEvent> | ImagesResponse>;\n  generate(\n    body: ImageGenerateParams,\n    options?: RequestOptions,\n  ): APIPromise<ImagesResponse> | APIPromise<Stream<ImageGenStreamEvent>> {\n    return this._client.post('/images/generations', { body, ...options, stream: body.stream ?? false }) as\n      | APIPromise<ImagesResponse>\n      | APIPromise<Stream<ImageGenStreamEvent>>;\n  }\n}\n\n/**\n * Represents the content or the URL of an image generated by the OpenAI API.\n */\nexport interface Image {\n  /**\n   * The base64-encoded JSON of the generated image. Returned by default for the GPT\n   * image models, and only present if `response_format` is set to `b64_json` for\n   * `dall-e-2` and `dall-e-3`.\n   */\n  b64_json?: string;\n\n  /**\n   * For `dall-e-3` only, the revised prompt that was used to generate the image.\n   */\n  revised_prompt?: string;\n\n  /**\n   * When using `dall-e-2` or `dall-e-3`, the URL of the generated image if\n   * `response_format` is set to `url` (default value). Unsupported for the GPT image\n   * models.\n   */\n  url?: string;\n}\n\n/**\n * Emitted when image editing has completed and the final image is available.\n */\nexport interface ImageEditCompletedEvent {\n  /**\n   * Base64-encoded final edited image data, suitable for rendering as an image.\n   */\n  b64_json: string;\n\n  /**\n   * The background setting for the edited image.\n   */\n  background: 'transparent' | 'opaque' | 'auto';\n\n  /**\n   * The Unix timestamp when the event was created.\n   */\n  created_at: number;\n\n  /**\n   * The output format for the edited image.\n   */\n  output_format: 'png' | 'webp' | 'jpeg';\n\n  /**\n   * The quality setting for the edited image.\n   */\n  quality: 'low' | 'medium' | 'high' | 'auto';\n\n  /**\n   * The size of the edited image.\n   */\n  size: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';\n\n  /**\n   * The type of the event. Always `image_edit.completed`.\n   */\n  type: 'image_edit.completed';\n\n  /**\n   * For the GPT image models only, the token usage information for the image\n   * generation.\n   */\n  usage: ImageEditCompletedEvent.Usage;\n}\n\nexport namespace ImageEditCompletedEvent {\n  /**\n   * For the GPT image models only, the token usage information for the image\n   * generation.\n   */\n  export interface Usage {\n    /**\n     * The number of tokens (images and text) in the input prompt.\n     */\n    input_tokens: number;\n\n    /**\n     * The input tokens detailed information for the image generation.\n     */\n    input_tokens_details: Usage.InputTokensDetails;\n\n    /**\n     * The number of image tokens in the output image.\n     */\n    output_tokens: number;\n\n    /**\n     * The total number of tokens (images and text) used for the image generation.\n     */\n    total_tokens: number;\n  }\n\n  export namespace Usage {\n    /**\n     * The input tokens detailed information for the image generation.\n     */\n    export interface InputTokensDetails {\n      /**\n       * The number of image tokens in the input prompt.\n       */\n      image_tokens: number;\n\n      /**\n       * The number of text tokens in the input prompt.\n       */\n      text_tokens: number;\n    }\n  }\n}\n\n/**\n * Emitted when a partial image is available during image editing streaming.\n */\nexport interface ImageEditPartialImageEvent {\n  /**\n   * Base64-encoded partial image data, suitable for rendering as an image.\n   */\n  b64_json: string;\n\n  /**\n   * The background setting for the requested edited image.\n   */\n  background: 'transparent' | 'opaque' | 'auto';\n\n  /**\n   * The Unix timestamp when the event was created.\n   */\n  created_at: number;\n\n  /**\n   * The output format for the requested edited image.\n   */\n  output_format: 'png' | 'webp' | 'jpeg';\n\n  /**\n   * 0-based index for the partial image (streaming).\n   */\n  partial_image_index: number;\n\n  /**\n   * The quality setting for the requested edited image.\n   */\n  quality: 'low' | 'medium' | 'high' | 'auto';\n\n  /**\n   * The size of the requested edited image.\n   */\n  size: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';\n\n  /**\n   * The type of the event. Always `image_edit.partial_image`.\n   */\n  type: 'image_edit.partial_image';\n}\n\n/**\n * Emitted when a partial image is available during image editing streaming.\n */\nexport type ImageEditStreamEvent = ImageEditPartialImageEvent | ImageEditCompletedEvent;\n\n/**\n * Emitted when image generation has completed and the final image is available.\n */\nexport interface ImageGenCompletedEvent {\n  /**\n   * Base64-encoded image data, suitable for rendering as an image.\n   */\n  b64_json: string;\n\n  /**\n   * The background setting for the generated image.\n   */\n  background: 'transparent' | 'opaque' | 'auto';\n\n  /**\n   * The Unix timestamp when the event was created.\n   */\n  created_at: number;\n\n  /**\n   * The output format for the generated image.\n   */\n  output_format: 'png' | 'webp' | 'jpeg';\n\n  /**\n   * The quality setting for the generated image.\n   */\n  quality: 'low' | 'medium' | 'high' | 'auto';\n\n  /**\n   * The size of the generated image.\n   */\n  size: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';\n\n  /**\n   * The type of the event. Always `image_generation.completed`.\n   */\n  type: 'image_generation.completed';\n\n  /**\n   * For the GPT image models only, the token usage information for the image\n   * generation.\n   */\n  usage: ImageGenCompletedEvent.Usage;\n}\n\nexport namespace ImageGenCompletedEvent {\n  /**\n   * For the GPT image models only, the token usage information for the image\n   * generation.\n   */\n  export interface Usage {\n    /**\n     * The number of tokens (images and text) in the input prompt.\n     */\n    input_tokens: number;\n\n    /**\n     * The input tokens detailed information for the image generation.\n     */\n    input_tokens_details: Usage.InputTokensDetails;\n\n    /**\n     * The number of image tokens in the output image.\n     */\n    output_tokens: number;\n\n    /**\n     * The total number of tokens (images and text) used for the image generation.\n     */\n    total_tokens: number;\n  }\n\n  export namespace Usage {\n    /**\n     * The input tokens detailed information for the image generation.\n     */\n    export interface InputTokensDetails {\n      /**\n       * The number of image tokens in the input prompt.\n       */\n      image_tokens: number;\n\n      /**\n       * The number of text tokens in the input prompt.\n       */\n      text_tokens: number;\n    }\n  }\n}\n\n/**\n * Emitted when a partial image is available during image generation streaming.\n */\nexport interface ImageGenPartialImageEvent {\n  /**\n   * Base64-encoded partial image data, suitable for rendering as an image.\n   */\n  b64_json: string;\n\n  /**\n   * The background setting for the requested image.\n   */\n  background: 'transparent' | 'opaque' | 'auto';\n\n  /**\n   * The Unix timestamp when the event was created.\n   */\n  created_at: number;\n\n  /**\n   * The output format for the requested image.\n   */\n  output_format: 'png' | 'webp' | 'jpeg';\n\n  /**\n   * 0-based index for the partial image (streaming).\n   */\n  partial_image_index: number;\n\n  /**\n   * The quality setting for the requested image.\n   */\n  quality: 'low' | 'medium' | 'high' | 'auto';\n\n  /**\n   * The size of the requested image.\n   */\n  size: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';\n\n  /**\n   * The type of the event. Always `image_generation.partial_image`.\n   */\n  type: 'image_generation.partial_image';\n}\n\n/**\n * Emitted when a partial image is available during image generation streaming.\n */\nexport type ImageGenStreamEvent = ImageGenPartialImageEvent | ImageGenCompletedEvent;\n\nexport type ImageModel = 'gpt-image-1.5' | 'dall-e-2' | 'dall-e-3' | 'gpt-image-1' | 'gpt-image-1-mini';\n\n/**\n * The response from the image generation endpoint.\n */\nexport interface ImagesResponse {\n  /**\n   * The Unix timestamp (in seconds) of when the image was created.\n   */\n  created: number;\n\n  /**\n   * The background parameter used for the image generation. Either `transparent` or\n   * `opaque`.\n   */\n  background?: 'transparent' | 'opaque';\n\n  /**\n   * The list of generated images.\n   */\n  data?: Array<Image>;\n\n  /**\n   * The output format of the image generation. Either `png`, `webp`, or `jpeg`.\n   */\n  output_format?: 'png' | 'webp' | 'jpeg';\n\n  /**\n   * The quality of the image generated. Either `low`, `medium`, or `high`.\n   */\n  quality?: 'low' | 'medium' | 'high';\n\n  /**\n   * The size of the image generated. Either `1024x1024`, `1024x1536`, or\n   * `1536x1024`.\n   */\n  size?: '1024x1024' | '1024x1536' | '1536x1024';\n\n  /**\n   * For `gpt-image-1` only, the token usage information for the image generation.\n   */\n  usage?: ImagesResponse.Usage;\n}\n\nexport namespace ImagesResponse {\n  /**\n   * For `gpt-image-1` only, the token usage information for the image generation.\n   */\n  export interface Usage {\n    /**\n     * The number of tokens (images and text) in the input prompt.\n     */\n    input_tokens: number;\n\n    /**\n     * The input tokens detailed information for the image generation.\n     */\n    input_tokens_details: Usage.InputTokensDetails;\n\n    /**\n     * The number of output tokens generated by the model.\n     */\n    output_tokens: number;\n\n    /**\n     * The total number of tokens (images and text) used for the image generation.\n     */\n    total_tokens: number;\n\n    /**\n     * The output token details for the image generation.\n     */\n    output_tokens_details?: Usage.OutputTokensDetails;\n  }\n\n  export namespace Usage {\n    /**\n     * The input tokens detailed information for the image generation.\n     */\n    export interface InputTokensDetails {\n      /**\n       * The number of image tokens in the input prompt.\n       */\n      image_tokens: number;\n\n      /**\n       * The number of text tokens in the input prompt.\n       */\n      text_tokens: number;\n    }\n\n    /**\n     * The output token details for the image generation.\n     */\n    export interface OutputTokensDetails {\n      /**\n       * The number of image output tokens generated by the model.\n       */\n      image_tokens: number;\n\n      /**\n       * The number of text output tokens generated by the model.\n       */\n      text_tokens: number;\n    }\n  }\n}\n\nexport interface ImageCreateVariationParams {\n  /**\n   * The image to use as the basis for the variation(s). Must be a valid PNG file,\n   * less than 4MB, and square.\n   */\n  image: Uploadable;\n\n  /**\n   * The model to use for image generation. Only `dall-e-2` is supported at this\n   * time.\n   */\n  model?: (string & {}) | ImageModel | null;\n\n  /**\n   * The number of images to generate. Must be between 1 and 10.\n   */\n  n?: number | null;\n\n  /**\n   * The format in which the generated images are returned. Must be one of `url` or\n   * `b64_json`. URLs are only valid for 60 minutes after the image has been\n   * generated.\n   */\n  response_format?: 'url' | 'b64_json' | null;\n\n  /**\n   * The size of the generated images. Must be one of `256x256`, `512x512`, or\n   * `1024x1024`.\n   */\n  size?: '256x256' | '512x512' | '1024x1024' | null;\n\n  /**\n   * A unique identifier representing your end-user, which can help OpenAI to monitor\n   * and detect abuse.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).\n   */\n  user?: string;\n}\n\nexport type ImageEditParams = ImageEditParamsNonStreaming | ImageEditParamsStreaming;\n\nexport interface ImageEditParamsBase {\n  /**\n   * The image(s) to edit. Must be a supported image file or an array of images.\n   *\n   * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and\n   * `gpt-image-1.5`), each image should be a `png`, `webp`, or `jpg` file less than\n   * 50MB. You can provide up to 16 images. `chatgpt-image-latest` follows the same\n   * input constraints as GPT image models.\n   *\n   * For `dall-e-2`, you can only provide one image, and it should be a square `png`\n   * file less than 4MB.\n   */\n  image: Uploadable | Array<Uploadable>;\n\n  /**\n   * A text description of the desired image(s). The maximum length is 1000\n   * characters for `dall-e-2`, and 32000 characters for the GPT image models.\n   */\n  prompt: string;\n\n  /**\n   * Allows to set transparency for the background of the generated image(s). This\n   * parameter is only supported for the GPT image models. Must be one of\n   * `transparent`, `opaque` or `auto` (default value). When `auto` is used, the\n   * model will automatically determine the best background for the image.\n   *\n   * If `transparent`, the output format needs to support transparency, so it should\n   * be set to either `png` (default value) or `webp`.\n   */\n  background?: 'transparent' | 'opaque' | 'auto' | null;\n\n  /**\n   * Control how much effort the model will exert to match the style and features,\n   * especially facial features, of input images. This parameter is only supported\n   * for `gpt-image-1` and `gpt-image-1.5` and later models, unsupported for\n   * `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`.\n   */\n  input_fidelity?: 'high' | 'low' | null;\n\n  /**\n   * An additional image whose fully transparent areas (e.g. where alpha is zero)\n   * indicate where `image` should be edited. If there are multiple images provided,\n   * the mask will be applied on the first image. Must be a valid PNG file, less than\n   * 4MB, and have the same dimensions as `image`.\n   */\n  mask?: Uploadable;\n\n  /**\n   * The model to use for image generation. Defaults to `gpt-image-1.5`.\n   */\n  model?: (string & {}) | ImageModel | null;\n\n  /**\n   * The number of images to generate. Must be between 1 and 10.\n   */\n  n?: number | null;\n\n  /**\n   * The compression level (0-100%) for the generated images. This parameter is only\n   * supported for the GPT image models with the `webp` or `jpeg` output formats, and\n   * defaults to 100.\n   */\n  output_compression?: number | null;\n\n  /**\n   * The format in which the generated images are returned. This parameter is only\n   * supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`. The\n   * default value is `png`.\n   */\n  output_format?: 'png' | 'jpeg' | 'webp' | null;\n\n  /**\n   * The number of partial images to generate. This parameter is used for streaming\n   * responses that return partial images. Value must be between 0 and 3. When set to\n   * 0, the response will be a single image sent in one streaming event.\n   *\n   * Note that the final image may be sent before the full number of partial images\n   * are generated if the full image is generated more quickly.\n   */\n  partial_images?: number | null;\n\n  /**\n   * The quality of the image that will be generated for GPT image models. Defaults\n   * to `auto`.\n   */\n  quality?: 'standard' | 'low' | 'medium' | 'high' | 'auto' | null;\n\n  /**\n   * The format in which the generated images are returned. Must be one of `url` or\n   * `b64_json`. URLs are only valid for 60 minutes after the image has been\n   * generated. This parameter is only supported for `dall-e-2` (default is `url` for\n   * `dall-e-2`), as GPT image models always return base64-encoded images.\n   */\n  response_format?: 'url' | 'b64_json' | null;\n\n  /**\n   * The size of the generated images. Must be one of `1024x1024`, `1536x1024`\n   * (landscape), `1024x1536` (portrait), or `auto` (default value) for the GPT image\n   * models, and one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`.\n   */\n  size?: '256x256' | '512x512' | '1024x1024' | '1536x1024' | '1024x1536' | 'auto' | null;\n\n  /**\n   * Edit the image in streaming mode. Defaults to `false`. See the\n   * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n   * for more information.\n   */\n  stream?: boolean | null;\n\n  /**\n   * A unique identifier representing your end-user, which can help OpenAI to monitor\n   * and detect abuse.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).\n   */\n  user?: string;\n}\n\nexport namespace ImageEditParams {\n  export type ImageEditParamsNonStreaming = ImagesAPI.ImageEditParamsNonStreaming;\n  export type ImageEditParamsStreaming = ImagesAPI.ImageEditParamsStreaming;\n}\n\nexport interface ImageEditParamsNonStreaming extends ImageEditParamsBase {\n  /**\n   * Edit the image in streaming mode. Defaults to `false`. See the\n   * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n   * for more information.\n   */\n  stream?: false | null;\n}\n\nexport interface ImageEditParamsStreaming extends ImageEditParamsBase {\n  /**\n   * Edit the image in streaming mode. Defaults to `false`. See the\n   * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n   * for more information.\n   */\n  stream: true;\n}\n\nexport type ImageGenerateParams = ImageGenerateParamsNonStreaming | ImageGenerateParamsStreaming;\n\nexport interface ImageGenerateParamsBase {\n  /**\n   * A text description of the desired image(s). The maximum length is 32000\n   * characters for the GPT image models, 1000 characters for `dall-e-2` and 4000\n   * characters for `dall-e-3`.\n   */\n  prompt: string;\n\n  /**\n   * Allows to set transparency for the background of the generated image(s). This\n   * parameter is only supported for the GPT image models. Must be one of\n   * `transparent`, `opaque` or `auto` (default value). When `auto` is used, the\n   * model will automatically determine the best background for the image.\n   *\n   * If `transparent`, the output format needs to support transparency, so it should\n   * be set to either `png` (default value) or `webp`.\n   */\n  background?: 'transparent' | 'opaque' | 'auto' | null;\n\n  /**\n   * The model to use for image generation. One of `dall-e-2`, `dall-e-3`, or a GPT\n   * image model (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`). Defaults to\n   * `dall-e-2` unless a parameter specific to the GPT image models is used.\n   */\n  model?: (string & {}) | ImageModel | null;\n\n  /**\n   * Control the content-moderation level for images generated by the GPT image\n   * models. Must be either `low` for less restrictive filtering or `auto` (default\n   * value).\n   */\n  moderation?: 'low' | 'auto' | null;\n\n  /**\n   * The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only\n   * `n=1` is supported.\n   */\n  n?: number | null;\n\n  /**\n   * The compression level (0-100%) for the generated images. This parameter is only\n   * supported for the GPT image models with the `webp` or `jpeg` output formats, and\n   * defaults to 100.\n   */\n  output_compression?: number | null;\n\n  /**\n   * The format in which the generated images are returned. This parameter is only\n   * supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.\n   */\n  output_format?: 'png' | 'jpeg' | 'webp' | null;\n\n  /**\n   * The number of partial images to generate. This parameter is used for streaming\n   * responses that return partial images. Value must be between 0 and 3. When set to\n   * 0, the response will be a single image sent in one streaming event.\n   *\n   * Note that the final image may be sent before the full number of partial images\n   * are generated if the full image is generated more quickly.\n   */\n  partial_images?: number | null;\n\n  /**\n   * The quality of the image that will be generated.\n   *\n   * - `auto` (default value) will automatically select the best quality for the\n   *   given model.\n   * - `high`, `medium` and `low` are supported for the GPT image models.\n   * - `hd` and `standard` are supported for `dall-e-3`.\n   * - `standard` is the only option for `dall-e-2`.\n   */\n  quality?: 'standard' | 'hd' | 'low' | 'medium' | 'high' | 'auto' | null;\n\n  /**\n   * The format in which generated images with `dall-e-2` and `dall-e-3` are\n   * returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes\n   * after the image has been generated. This parameter isn't supported for the GPT\n   * image models, which always return base64-encoded images.\n   */\n  response_format?: 'url' | 'b64_json' | null;\n\n  /**\n   * The size of the generated images. Must be one of `1024x1024`, `1536x1024`\n   * (landscape), `1024x1536` (portrait), or `auto` (default value) for the GPT image\n   * models, one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`, and one of\n   * `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3`.\n   */\n  size?:\n    | 'auto'\n    | '1024x1024'\n    | '1536x1024'\n    | '1024x1536'\n    | '256x256'\n    | '512x512'\n    | '1792x1024'\n    | '1024x1792'\n    | null;\n\n  /**\n   * Generate the image in streaming mode. Defaults to `false`. See the\n   * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n   * for more information. This parameter is only supported for the GPT image models.\n   */\n  stream?: boolean | null;\n\n  /**\n   * The style of the generated images. This parameter is only supported for\n   * `dall-e-3`. Must be one of `vivid` or `natural`. Vivid causes the model to lean\n   * towards generating hyper-real and dramatic images. Natural causes the model to\n   * produce more natural, less hyper-real looking images.\n   */\n  style?: 'vivid' | 'natural' | null;\n\n  /**\n   * A unique identifier representing your end-user, which can help OpenAI to monitor\n   * and detect abuse.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).\n   */\n  user?: string;\n}\n\nexport namespace ImageGenerateParams {\n  export type ImageGenerateParamsNonStreaming = ImagesAPI.ImageGenerateParamsNonStreaming;\n  export type ImageGenerateParamsStreaming = ImagesAPI.ImageGenerateParamsStreaming;\n}\n\nexport interface ImageGenerateParamsNonStreaming extends ImageGenerateParamsBase {\n  /**\n   * Generate the image in streaming mode. Defaults to `false`. See the\n   * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n   * for more information. This parameter is only supported for the GPT image models.\n   */\n  stream?: false | null;\n}\n\nexport interface ImageGenerateParamsStreaming extends ImageGenerateParamsBase {\n  /**\n   * Generate the image in streaming mode. Defaults to `false`. See the\n   * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n   * for more information. This parameter is only supported for the GPT image models.\n   */\n  stream: true;\n}\n\nexport declare namespace Images {\n  export {\n    type Image as Image,\n    type ImageEditCompletedEvent as ImageEditCompletedEvent,\n    type ImageEditPartialImageEvent as ImageEditPartialImageEvent,\n    type ImageEditStreamEvent as ImageEditStreamEvent,\n    type ImageGenCompletedEvent as ImageGenCompletedEvent,\n    type ImageGenPartialImageEvent as ImageGenPartialImageEvent,\n    type ImageGenStreamEvent as ImageGenStreamEvent,\n    type ImageModel as ImageModel,\n    type ImagesResponse as ImagesResponse,\n    type ImageCreateVariationParams as ImageCreateVariationParams,\n    type ImageEditParams as ImageEditParams,\n    type ImageEditParamsNonStreaming as ImageEditParamsNonStreaming,\n    type ImageEditParamsStreaming as ImageEditParamsStreaming,\n    type ImageGenerateParams as ImageGenerateParams,\n    type ImageGenerateParamsNonStreaming as ImageGenerateParamsNonStreaming,\n    type ImageGenerateParamsStreaming as ImageGenerateParamsStreaming,\n  };\n}\n"
  },
  {
    "path": "src/resources/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './chat/index';\nexport * from './shared';\nexport { Audio, type AudioModel, type AudioResponseFormat } from './audio/audio';\nexport {\n  Batches,\n  type Batch,\n  type BatchError,\n  type BatchRequestCounts,\n  type BatchUsage,\n  type BatchCreateParams,\n  type BatchListParams,\n  type BatchesPage,\n} from './batches';\nexport { Beta } from './beta/beta';\nexport {\n  Completions,\n  type Completion,\n  type CompletionChoice,\n  type CompletionUsage,\n  type CompletionCreateParams,\n  type CompletionCreateParamsNonStreaming,\n  type CompletionCreateParamsStreaming,\n} from './completions';\nexport {\n  Containers,\n  type ContainerCreateResponse,\n  type ContainerRetrieveResponse,\n  type ContainerListResponse,\n  type ContainerCreateParams,\n  type ContainerListParams,\n  type ContainerListResponsesPage,\n} from './containers/containers';\nexport { Conversations } from './conversations/conversations';\nexport {\n  Embeddings,\n  type CreateEmbeddingResponse,\n  type Embedding,\n  type EmbeddingModel,\n  type EmbeddingCreateParams,\n} from './embeddings';\nexport {\n  Evals,\n  type EvalCustomDataSourceConfig,\n  type EvalStoredCompletionsDataSourceConfig,\n  type EvalCreateResponse,\n  type EvalRetrieveResponse,\n  type EvalUpdateResponse,\n  type EvalListResponse,\n  type EvalDeleteResponse,\n  type EvalCreateParams,\n  type EvalUpdateParams,\n  type EvalListParams,\n  type EvalListResponsesPage,\n} from './evals/evals';\nexport {\n  Files,\n  type FileContent,\n  type FileDeleted,\n  type FileObject,\n  type FilePurpose,\n  type FileCreateParams,\n  type FileListParams,\n  type FileObjectsPage,\n} from './files';\nexport { FineTuning } from './fine-tuning/fine-tuning';\nexport { Graders } from './graders/graders';\nexport {\n  Images,\n  type Image,\n  type ImageEditCompletedEvent,\n  type ImageEditPartialImageEvent,\n  type ImageEditStreamEvent,\n  type ImageGenCompletedEvent,\n  type ImageGenPartialImageEvent,\n  type ImageGenStreamEvent,\n  type ImageModel,\n  type ImagesResponse,\n  type ImageCreateVariationParams,\n  type ImageEditParams,\n  type ImageEditParamsNonStreaming,\n  type ImageEditParamsStreaming,\n  type ImageGenerateParams,\n  type ImageGenerateParamsNonStreaming,\n  type ImageGenerateParamsStreaming,\n} from './images';\nexport { Models, type Model, type ModelDeleted, type ModelsPage } from './models';\nexport {\n  Moderations,\n  type Moderation,\n  type ModerationImageURLInput,\n  type ModerationModel,\n  type ModerationMultiModalInput,\n  type ModerationTextInput,\n  type ModerationCreateResponse,\n  type ModerationCreateParams,\n} from './moderations';\nexport { Realtime } from './realtime/realtime';\nexport { Responses } from './responses/responses';\nexport {\n  Skills,\n  type DeletedSkill,\n  type Skill,\n  type SkillList,\n  type SkillCreateParams,\n  type SkillUpdateParams,\n  type SkillListParams,\n  type SkillsPage,\n} from './skills/skills';\nexport { Uploads, type Upload, type UploadCreateParams, type UploadCompleteParams } from './uploads/uploads';\nexport {\n  VectorStores,\n  type AutoFileChunkingStrategyParam,\n  type FileChunkingStrategy,\n  type FileChunkingStrategyParam,\n  type OtherFileChunkingStrategyObject,\n  type StaticFileChunkingStrategy,\n  type StaticFileChunkingStrategyObject,\n  type StaticFileChunkingStrategyObjectParam,\n  type VectorStore,\n  type VectorStoreDeleted,\n  type VectorStoreSearchResponse,\n  type VectorStoreCreateParams,\n  type VectorStoreUpdateParams,\n  type VectorStoreListParams,\n  type VectorStoreSearchParams,\n  type VectorStoresPage,\n  type VectorStoreSearchResponsesPage,\n} from './vector-stores/vector-stores';\nexport {\n  Videos,\n  type ImageInputReferenceParam,\n  type Video,\n  type VideoCreateError,\n  type VideoModel,\n  type VideoSeconds,\n  type VideoSize,\n  type VideoDeleteResponse,\n  type VideoCreateCharacterResponse,\n  type VideoGetCharacterResponse,\n  type VideoCreateParams,\n  type VideoListParams,\n  type VideoCreateCharacterParams,\n  type VideoDownloadContentParams,\n  type VideoEditParams,\n  type VideoExtendParams,\n  type VideoRemixParams,\n  type VideosPage,\n} from './videos';\nexport { Webhooks } from './webhooks';\n"
  },
  {
    "path": "src/resources/models.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport { APIPromise } from '../core/api-promise';\nimport { Page, PagePromise } from '../core/pagination';\nimport { RequestOptions } from '../internal/request-options';\nimport { path } from '../internal/utils/path';\n\n/**\n * List and describe the various models available in the API.\n */\nexport class Models extends APIResource {\n  /**\n   * Retrieves a model instance, providing basic information about the model such as\n   * the owner and permissioning.\n   */\n  retrieve(model: string, options?: RequestOptions): APIPromise<Model> {\n    return this._client.get(path`/models/${model}`, options);\n  }\n\n  /**\n   * Lists the currently available models, and provides basic information about each\n   * one such as the owner and availability.\n   */\n  list(options?: RequestOptions): PagePromise<ModelsPage, Model> {\n    return this._client.getAPIList('/models', Page<Model>, options);\n  }\n\n  /**\n   * Delete a fine-tuned model. You must have the Owner role in your organization to\n   * delete a model.\n   */\n  delete(model: string, options?: RequestOptions): APIPromise<ModelDeleted> {\n    return this._client.delete(path`/models/${model}`, options);\n  }\n}\n\n// Note: no pagination actually occurs yet, this is for forwards-compatibility.\nexport type ModelsPage = Page<Model>;\n\n/**\n * Describes an OpenAI model offering that can be used with the API.\n */\nexport interface Model {\n  /**\n   * The model identifier, which can be referenced in the API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) when the model was created.\n   */\n  created: number;\n\n  /**\n   * The object type, which is always \"model\".\n   */\n  object: 'model';\n\n  /**\n   * The organization that owns the model.\n   */\n  owned_by: string;\n}\n\nexport interface ModelDeleted {\n  id: string;\n\n  deleted: boolean;\n\n  object: string;\n}\n\nexport declare namespace Models {\n  export { type Model as Model, type ModelDeleted as ModelDeleted, type ModelsPage as ModelsPage };\n}\n"
  },
  {
    "path": "src/resources/moderations.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport { APIPromise } from '../core/api-promise';\nimport { RequestOptions } from '../internal/request-options';\n\n/**\n * Given text and/or image inputs, classifies if those inputs are potentially harmful.\n */\nexport class Moderations extends APIResource {\n  /**\n   * Classifies if text and/or image inputs are potentially harmful. Learn more in\n   * the [moderation guide](https://platform.openai.com/docs/guides/moderation).\n   */\n  create(body: ModerationCreateParams, options?: RequestOptions): APIPromise<ModerationCreateResponse> {\n    return this._client.post('/moderations', { body, ...options });\n  }\n}\n\nexport interface Moderation {\n  /**\n   * A list of the categories, and whether they are flagged or not.\n   */\n  categories: Moderation.Categories;\n\n  /**\n   * A list of the categories along with the input type(s) that the score applies to.\n   */\n  category_applied_input_types: Moderation.CategoryAppliedInputTypes;\n\n  /**\n   * A list of the categories along with their scores as predicted by model.\n   */\n  category_scores: Moderation.CategoryScores;\n\n  /**\n   * Whether any of the below categories are flagged.\n   */\n  flagged: boolean;\n}\n\nexport namespace Moderation {\n  /**\n   * A list of the categories, and whether they are flagged or not.\n   */\n  export interface Categories {\n    /**\n     * Content that expresses, incites, or promotes harassing language towards any\n     * target.\n     */\n    harassment: boolean;\n\n    /**\n     * Harassment content that also includes violence or serious harm towards any\n     * target.\n     */\n    'harassment/threatening': boolean;\n\n    /**\n     * Content that expresses, incites, or promotes hate based on race, gender,\n     * ethnicity, religion, nationality, sexual orientation, disability status, or\n     * caste. Hateful content aimed at non-protected groups (e.g., chess players) is\n     * harassment.\n     */\n    hate: boolean;\n\n    /**\n     * Hateful content that also includes violence or serious harm towards the targeted\n     * group based on race, gender, ethnicity, religion, nationality, sexual\n     * orientation, disability status, or caste.\n     */\n    'hate/threatening': boolean;\n\n    /**\n     * Content that includes instructions or advice that facilitate the planning or\n     * execution of wrongdoing, or that gives advice or instruction on how to commit\n     * illicit acts. For example, \"how to shoplift\" would fit this category.\n     */\n    illicit: boolean | null;\n\n    /**\n     * Content that includes instructions or advice that facilitate the planning or\n     * execution of wrongdoing that also includes violence, or that gives advice or\n     * instruction on the procurement of any weapon.\n     */\n    'illicit/violent': boolean | null;\n\n    /**\n     * Content that promotes, encourages, or depicts acts of self-harm, such as\n     * suicide, cutting, and eating disorders.\n     */\n    'self-harm': boolean;\n\n    /**\n     * Content that encourages performing acts of self-harm, such as suicide, cutting,\n     * and eating disorders, or that gives instructions or advice on how to commit such\n     * acts.\n     */\n    'self-harm/instructions': boolean;\n\n    /**\n     * Content where the speaker expresses that they are engaging or intend to engage\n     * in acts of self-harm, such as suicide, cutting, and eating disorders.\n     */\n    'self-harm/intent': boolean;\n\n    /**\n     * Content meant to arouse sexual excitement, such as the description of sexual\n     * activity, or that promotes sexual services (excluding sex education and\n     * wellness).\n     */\n    sexual: boolean;\n\n    /**\n     * Sexual content that includes an individual who is under 18 years old.\n     */\n    'sexual/minors': boolean;\n\n    /**\n     * Content that depicts death, violence, or physical injury.\n     */\n    violence: boolean;\n\n    /**\n     * Content that depicts death, violence, or physical injury in graphic detail.\n     */\n    'violence/graphic': boolean;\n  }\n\n  /**\n   * A list of the categories along with the input type(s) that the score applies to.\n   */\n  export interface CategoryAppliedInputTypes {\n    /**\n     * The applied input type(s) for the category 'harassment'.\n     */\n    harassment: Array<'text'>;\n\n    /**\n     * The applied input type(s) for the category 'harassment/threatening'.\n     */\n    'harassment/threatening': Array<'text'>;\n\n    /**\n     * The applied input type(s) for the category 'hate'.\n     */\n    hate: Array<'text'>;\n\n    /**\n     * The applied input type(s) for the category 'hate/threatening'.\n     */\n    'hate/threatening': Array<'text'>;\n\n    /**\n     * The applied input type(s) for the category 'illicit'.\n     */\n    illicit: Array<'text'>;\n\n    /**\n     * The applied input type(s) for the category 'illicit/violent'.\n     */\n    'illicit/violent': Array<'text'>;\n\n    /**\n     * The applied input type(s) for the category 'self-harm'.\n     */\n    'self-harm': Array<'text' | 'image'>;\n\n    /**\n     * The applied input type(s) for the category 'self-harm/instructions'.\n     */\n    'self-harm/instructions': Array<'text' | 'image'>;\n\n    /**\n     * The applied input type(s) for the category 'self-harm/intent'.\n     */\n    'self-harm/intent': Array<'text' | 'image'>;\n\n    /**\n     * The applied input type(s) for the category 'sexual'.\n     */\n    sexual: Array<'text' | 'image'>;\n\n    /**\n     * The applied input type(s) for the category 'sexual/minors'.\n     */\n    'sexual/minors': Array<'text'>;\n\n    /**\n     * The applied input type(s) for the category 'violence'.\n     */\n    violence: Array<'text' | 'image'>;\n\n    /**\n     * The applied input type(s) for the category 'violence/graphic'.\n     */\n    'violence/graphic': Array<'text' | 'image'>;\n  }\n\n  /**\n   * A list of the categories along with their scores as predicted by model.\n   */\n  export interface CategoryScores {\n    /**\n     * The score for the category 'harassment'.\n     */\n    harassment: number;\n\n    /**\n     * The score for the category 'harassment/threatening'.\n     */\n    'harassment/threatening': number;\n\n    /**\n     * The score for the category 'hate'.\n     */\n    hate: number;\n\n    /**\n     * The score for the category 'hate/threatening'.\n     */\n    'hate/threatening': number;\n\n    /**\n     * The score for the category 'illicit'.\n     */\n    illicit: number;\n\n    /**\n     * The score for the category 'illicit/violent'.\n     */\n    'illicit/violent': number;\n\n    /**\n     * The score for the category 'self-harm'.\n     */\n    'self-harm': number;\n\n    /**\n     * The score for the category 'self-harm/instructions'.\n     */\n    'self-harm/instructions': number;\n\n    /**\n     * The score for the category 'self-harm/intent'.\n     */\n    'self-harm/intent': number;\n\n    /**\n     * The score for the category 'sexual'.\n     */\n    sexual: number;\n\n    /**\n     * The score for the category 'sexual/minors'.\n     */\n    'sexual/minors': number;\n\n    /**\n     * The score for the category 'violence'.\n     */\n    violence: number;\n\n    /**\n     * The score for the category 'violence/graphic'.\n     */\n    'violence/graphic': number;\n  }\n}\n\n/**\n * An object describing an image to classify.\n */\nexport interface ModerationImageURLInput {\n  /**\n   * Contains either an image URL or a data URL for a base64 encoded image.\n   */\n  image_url: ModerationImageURLInput.ImageURL;\n\n  /**\n   * Always `image_url`.\n   */\n  type: 'image_url';\n}\n\nexport namespace ModerationImageURLInput {\n  /**\n   * Contains either an image URL or a data URL for a base64 encoded image.\n   */\n  export interface ImageURL {\n    /**\n     * Either a URL of the image or the base64 encoded image data.\n     */\n    url: string;\n  }\n}\n\nexport type ModerationModel =\n  | 'omni-moderation-latest'\n  | 'omni-moderation-2024-09-26'\n  | 'text-moderation-latest'\n  | 'text-moderation-stable';\n\n/**\n * An object describing an image to classify.\n */\nexport type ModerationMultiModalInput = ModerationImageURLInput | ModerationTextInput;\n\n/**\n * An object describing text to classify.\n */\nexport interface ModerationTextInput {\n  /**\n   * A string of text to classify.\n   */\n  text: string;\n\n  /**\n   * Always `text`.\n   */\n  type: 'text';\n}\n\n/**\n * Represents if a given text input is potentially harmful.\n */\nexport interface ModerationCreateResponse {\n  /**\n   * The unique identifier for the moderation request.\n   */\n  id: string;\n\n  /**\n   * The model used to generate the moderation results.\n   */\n  model: string;\n\n  /**\n   * A list of moderation objects.\n   */\n  results: Array<Moderation>;\n}\n\nexport interface ModerationCreateParams {\n  /**\n   * Input (or inputs) to classify. Can be a single string, an array of strings, or\n   * an array of multi-modal input objects similar to other models.\n   */\n  input: string | Array<string> | Array<ModerationMultiModalInput>;\n\n  /**\n   * The content moderation model you would like to use. Learn more in\n   * [the moderation guide](https://platform.openai.com/docs/guides/moderation), and\n   * learn about available models\n   * [here](https://platform.openai.com/docs/models#moderation).\n   */\n  model?: (string & {}) | ModerationModel;\n}\n\nexport declare namespace Moderations {\n  export {\n    type Moderation as Moderation,\n    type ModerationImageURLInput as ModerationImageURLInput,\n    type ModerationModel as ModerationModel,\n    type ModerationMultiModalInput as ModerationMultiModalInput,\n    type ModerationTextInput as ModerationTextInput,\n    type ModerationCreateResponse as ModerationCreateResponse,\n    type ModerationCreateParams as ModerationCreateParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/realtime/api.md",
    "content": "# Realtime\n\nTypes:\n\n- <code><a href=\"./src/resources/realtime/realtime.ts\">AudioTranscription</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationCreatedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItem</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemAdded</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemCreateEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemCreatedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemDeleteEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemDeletedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemDone</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemInputAudioTranscriptionCompletedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemInputAudioTranscriptionDeltaEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemInputAudioTranscriptionFailedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemInputAudioTranscriptionSegment</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemRetrieveEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemTruncateEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemTruncatedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ConversationItemWithReference</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">InputAudioBufferAppendEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">InputAudioBufferClearEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">InputAudioBufferClearedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">InputAudioBufferCommitEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">InputAudioBufferCommittedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">InputAudioBufferDtmfEventReceivedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">InputAudioBufferSpeechStartedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">InputAudioBufferSpeechStoppedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">InputAudioBufferTimeoutTriggered</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">LogProbProperties</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">McpListToolsCompleted</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">McpListToolsFailed</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">McpListToolsInProgress</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">NoiseReductionType</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">OutputAudioBufferClearEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RateLimitsUpdatedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeAudioConfig</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeAudioConfigInput</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeAudioConfigOutput</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeAudioFormats</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeAudioInputTurnDetection</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeClientEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeConversationItemAssistantMessage</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeConversationItemFunctionCall</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeConversationItemFunctionCallOutput</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeConversationItemSystemMessage</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeConversationItemUserMessage</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeError</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeErrorEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeFunctionTool</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeMcpApprovalRequest</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeMcpApprovalResponse</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeMcpListTools</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeMcpProtocolError</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeMcpToolCall</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeMcpToolExecutionError</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeMcphttpError</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeResponse</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeResponseCreateAudioOutput</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeResponseCreateMcpTool</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeResponseCreateParams</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeResponseStatus</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeResponseUsage</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeResponseUsageInputTokenDetails</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeResponseUsageOutputTokenDetails</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeServerEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeSession</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeSessionCreateRequest</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeToolChoiceConfig</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeToolsConfig</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeToolsConfigUnion</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeTracingConfig</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeTranscriptionSessionAudio</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeTranscriptionSessionAudioInput</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeTranscriptionSessionAudioInputTurnDetection</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeTranscriptionSessionCreateRequest</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeTruncation</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">RealtimeTruncationRetentionRatio</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseAudioDeltaEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseAudioDoneEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseAudioTranscriptDeltaEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseAudioTranscriptDoneEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseCancelEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseContentPartAddedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseContentPartDoneEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseCreateEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseCreatedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseDoneEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseFunctionCallArgumentsDeltaEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseFunctionCallArgumentsDoneEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseMcpCallArgumentsDelta</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseMcpCallArgumentsDone</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseMcpCallCompleted</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseMcpCallFailed</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseMcpCallInProgress</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseOutputItemAddedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseOutputItemDoneEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseTextDeltaEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">ResponseTextDoneEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">SessionCreatedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">SessionUpdateEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">SessionUpdatedEvent</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">TranscriptionSessionUpdate</a></code>\n- <code><a href=\"./src/resources/realtime/realtime.ts\">TranscriptionSessionUpdatedEvent</a></code>\n\n## ClientSecrets\n\nTypes:\n\n- <code><a href=\"./src/resources/realtime/client-secrets.ts\">RealtimeSessionClientSecret</a></code>\n- <code><a href=\"./src/resources/realtime/client-secrets.ts\">RealtimeSessionCreateResponse</a></code>\n- <code><a href=\"./src/resources/realtime/client-secrets.ts\">RealtimeTranscriptionSessionCreateResponse</a></code>\n- <code><a href=\"./src/resources/realtime/client-secrets.ts\">RealtimeTranscriptionSessionTurnDetection</a></code>\n- <code><a href=\"./src/resources/realtime/client-secrets.ts\">ClientSecretCreateResponse</a></code>\n\nMethods:\n\n- <code title=\"post /realtime/client_secrets\">client.realtime.clientSecrets.<a href=\"./src/resources/realtime/client-secrets.ts\">create</a>({ ...params }) -> ClientSecretCreateResponse</code>\n\n## Calls\n\nMethods:\n\n- <code title=\"post /realtime/calls/{call_id}/accept\">client.realtime.calls.<a href=\"./src/resources/realtime/calls.ts\">accept</a>(callID, { ...params }) -> void</code>\n- <code title=\"post /realtime/calls/{call_id}/hangup\">client.realtime.calls.<a href=\"./src/resources/realtime/calls.ts\">hangup</a>(callID) -> void</code>\n- <code title=\"post /realtime/calls/{call_id}/refer\">client.realtime.calls.<a href=\"./src/resources/realtime/calls.ts\">refer</a>(callID, { ...params }) -> void</code>\n- <code title=\"post /realtime/calls/{call_id}/reject\">client.realtime.calls.<a href=\"./src/resources/realtime/calls.ts\">reject</a>(callID, { ...params }) -> void</code>\n"
  },
  {
    "path": "src/resources/realtime/calls.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as RealtimeAPI from './realtime';\nimport * as ResponsesAPI from '../responses/responses';\nimport { APIPromise } from '../../core/api-promise';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport class Calls extends APIResource {\n  /**\n   * Accept an incoming SIP call and configure the realtime session that will handle\n   * it.\n   *\n   * @example\n   * ```ts\n   * await client.realtime.calls.accept('call_id', {\n   *   type: 'realtime',\n   * });\n   * ```\n   */\n  accept(callID: string, body: CallAcceptParams, options?: RequestOptions): APIPromise<void> {\n    return this._client.post(path`/realtime/calls/${callID}/accept`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n    });\n  }\n\n  /**\n   * End an active Realtime API call, whether it was initiated over SIP or WebRTC.\n   *\n   * @example\n   * ```ts\n   * await client.realtime.calls.hangup('call_id');\n   * ```\n   */\n  hangup(callID: string, options?: RequestOptions): APIPromise<void> {\n    return this._client.post(path`/realtime/calls/${callID}/hangup`, {\n      ...options,\n      headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Transfer an active SIP call to a new destination using the SIP REFER verb.\n   *\n   * @example\n   * ```ts\n   * await client.realtime.calls.refer('call_id', {\n   *   target_uri: 'tel:+14155550123',\n   * });\n   * ```\n   */\n  refer(callID: string, body: CallReferParams, options?: RequestOptions): APIPromise<void> {\n    return this._client.post(path`/realtime/calls/${callID}/refer`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Decline an incoming SIP call by returning a SIP status code to the caller.\n   *\n   * @example\n   * ```ts\n   * await client.realtime.calls.reject('call_id');\n   * ```\n   */\n  reject(\n    callID: string,\n    body: CallRejectParams | null | undefined = {},\n    options?: RequestOptions,\n  ): APIPromise<void> {\n    return this._client.post(path`/realtime/calls/${callID}/reject`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n    });\n  }\n}\n\nexport interface CallAcceptParams {\n  /**\n   * The type of session to create. Always `realtime` for the Realtime API.\n   */\n  type: 'realtime';\n\n  /**\n   * Configuration for input and output audio.\n   */\n  audio?: RealtimeAPI.RealtimeAudioConfig;\n\n  /**\n   * Additional fields to include in server outputs.\n   *\n   * `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n   * transcription.\n   */\n  include?: Array<'item.input_audio_transcription.logprobs'>;\n\n  /**\n   * The default system instructions (i.e. system message) prepended to model calls.\n   * This field allows the client to guide the model on desired responses. The model\n   * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n   * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n   * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n   * instructions are not guaranteed to be followed by the model, but they provide\n   * guidance to the model on the desired behavior.\n   *\n   * Note that the server sets default instructions which will be used if this field\n   * is not set and are visible in the `session.created` event at the start of the\n   * session.\n   */\n  instructions?: string;\n\n  /**\n   * Maximum number of output tokens for a single assistant response, inclusive of\n   * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n   * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n   */\n  max_output_tokens?: number | 'inf';\n\n  /**\n   * The Realtime model used for this session.\n   */\n  model?:\n    | (string & {})\n    | 'gpt-realtime'\n    | 'gpt-realtime-1.5'\n    | 'gpt-realtime-2025-08-28'\n    | 'gpt-4o-realtime-preview'\n    | 'gpt-4o-realtime-preview-2024-10-01'\n    | 'gpt-4o-realtime-preview-2024-12-17'\n    | 'gpt-4o-realtime-preview-2025-06-03'\n    | 'gpt-4o-mini-realtime-preview'\n    | 'gpt-4o-mini-realtime-preview-2024-12-17'\n    | 'gpt-realtime-mini'\n    | 'gpt-realtime-mini-2025-10-06'\n    | 'gpt-realtime-mini-2025-12-15'\n    | 'gpt-audio-1.5'\n    | 'gpt-audio-mini'\n    | 'gpt-audio-mini-2025-10-06'\n    | 'gpt-audio-mini-2025-12-15';\n\n  /**\n   * The set of modalities the model can respond with. It defaults to `[\"audio\"]`,\n   * indicating that the model will respond with audio plus a transcript. `[\"text\"]`\n   * can be used to make the model respond with text only. It is not possible to\n   * request both `text` and `audio` at the same time.\n   */\n  output_modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * Reference to a prompt template and its variables.\n   * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n   */\n  prompt?: ResponsesAPI.ResponsePrompt | null;\n\n  /**\n   * How the model chooses tools. Provide one of the string modes or force a specific\n   * function/MCP tool.\n   */\n  tool_choice?: RealtimeAPI.RealtimeToolChoiceConfig;\n\n  /**\n   * Tools available to the model.\n   */\n  tools?: RealtimeAPI.RealtimeToolsConfig;\n\n  /**\n   * Realtime API can write session traces to the\n   * [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once\n   * tracing is enabled for a session, the configuration cannot be modified.\n   *\n   * `auto` will create a trace for the session with default values for the workflow\n   * name, group id, and metadata.\n   */\n  tracing?: RealtimeAPI.RealtimeTracingConfig | null;\n\n  /**\n   * When the number of tokens in a conversation exceeds the model's input token\n   * limit, the conversation be truncated, meaning messages (starting from the\n   * oldest) will not be included in the model's context. A 32k context model with\n   * 4,096 max output tokens can only include 28,224 tokens in the context before\n   * truncation occurs.\n   *\n   * Clients can configure truncation behavior to truncate with a lower max token\n   * limit, which is an effective way to control token usage and cost.\n   *\n   * Truncation will reduce the number of cached tokens on the next turn (busting the\n   * cache), since messages are dropped from the beginning of the context. However,\n   * clients can also configure truncation to retain messages up to a fraction of the\n   * maximum context size, which will reduce the need for future truncations and thus\n   * improve the cache rate.\n   *\n   * Truncation can be disabled entirely, which means the server will never truncate\n   * but would instead return an error if the conversation exceeds the model's input\n   * token limit.\n   */\n  truncation?: RealtimeAPI.RealtimeTruncation;\n}\n\nexport interface CallReferParams {\n  /**\n   * URI that should appear in the SIP Refer-To header. Supports values like\n   * `tel:+14155550123` or `sip:agent@example.com`.\n   */\n  target_uri: string;\n}\n\nexport interface CallRejectParams {\n  /**\n   * SIP response code to send back to the caller. Defaults to `603` (Decline) when\n   * omitted.\n   */\n  status_code?: number;\n}\n\nexport declare namespace Calls {\n  export {\n    type CallAcceptParams as CallAcceptParams,\n    type CallReferParams as CallReferParams,\n    type CallRejectParams as CallRejectParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/realtime/client-secrets.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as ClientSecretsAPI from './client-secrets';\nimport * as RealtimeAPI from './realtime';\nimport * as ResponsesAPI from '../responses/responses';\nimport { APIPromise } from '../../core/api-promise';\nimport { RequestOptions } from '../../internal/request-options';\n\nexport class ClientSecrets extends APIResource {\n  /**\n   * Create a Realtime client secret with an associated session configuration.\n   *\n   * Client secrets are short-lived tokens that can be passed to a client app, such\n   * as a web frontend or mobile client, which grants access to the Realtime API\n   * without leaking your main API key. You can configure a custom TTL for each\n   * client secret.\n   *\n   * You can also attach session configuration options to the client secret, which\n   * will be applied to any sessions created using that client secret, but these can\n   * also be overridden by the client connection.\n   *\n   * [Learn more about authentication with client secrets over WebRTC](https://platform.openai.com/docs/guides/realtime-webrtc).\n   *\n   * Returns the created client secret and the effective session object. The client\n   * secret is a string that looks like `ek_1234`.\n   *\n   * @example\n   * ```ts\n   * const clientSecret =\n   *   await client.realtime.clientSecrets.create();\n   * ```\n   */\n  create(body: ClientSecretCreateParams, options?: RequestOptions): APIPromise<ClientSecretCreateResponse> {\n    return this._client.post('/realtime/client_secrets', { body, ...options });\n  }\n}\n\n/**\n * Ephemeral key returned by the API.\n */\nexport interface RealtimeSessionClientSecret {\n  /**\n   * Timestamp for when the token expires. Currently, all tokens expire after one\n   * minute.\n   */\n  expires_at: number;\n\n  /**\n   * Ephemeral key usable in client environments to authenticate connections to the\n   * Realtime API. Use this in client-side environments rather than a standard API\n   * token, which should only be used server-side.\n   */\n  value: string;\n}\n\n/**\n * A new Realtime session configuration, with an ephemeral key. Default TTL for\n * keys is one minute.\n */\nexport interface RealtimeSessionCreateResponse {\n  /**\n   * Ephemeral key returned by the API.\n   */\n  client_secret: RealtimeSessionClientSecret;\n\n  /**\n   * The type of session to create. Always `realtime` for the Realtime API.\n   */\n  type: 'realtime';\n\n  /**\n   * Configuration for input and output audio.\n   */\n  audio?: RealtimeSessionCreateResponse.Audio;\n\n  /**\n   * Additional fields to include in server outputs.\n   *\n   * `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n   * transcription.\n   */\n  include?: Array<'item.input_audio_transcription.logprobs'>;\n\n  /**\n   * The default system instructions (i.e. system message) prepended to model calls.\n   * This field allows the client to guide the model on desired responses. The model\n   * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n   * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n   * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n   * instructions are not guaranteed to be followed by the model, but they provide\n   * guidance to the model on the desired behavior.\n   *\n   * Note that the server sets default instructions which will be used if this field\n   * is not set and are visible in the `session.created` event at the start of the\n   * session.\n   */\n  instructions?: string;\n\n  /**\n   * Maximum number of output tokens for a single assistant response, inclusive of\n   * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n   * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n   */\n  max_output_tokens?: number | 'inf';\n\n  /**\n   * The Realtime model used for this session.\n   */\n  model?:\n    | (string & {})\n    | 'gpt-realtime'\n    | 'gpt-realtime-1.5'\n    | 'gpt-realtime-2025-08-28'\n    | 'gpt-4o-realtime-preview'\n    | 'gpt-4o-realtime-preview-2024-10-01'\n    | 'gpt-4o-realtime-preview-2024-12-17'\n    | 'gpt-4o-realtime-preview-2025-06-03'\n    | 'gpt-4o-mini-realtime-preview'\n    | 'gpt-4o-mini-realtime-preview-2024-12-17'\n    | 'gpt-realtime-mini'\n    | 'gpt-realtime-mini-2025-10-06'\n    | 'gpt-realtime-mini-2025-12-15'\n    | 'gpt-audio-1.5'\n    | 'gpt-audio-mini'\n    | 'gpt-audio-mini-2025-10-06'\n    | 'gpt-audio-mini-2025-12-15';\n\n  /**\n   * The set of modalities the model can respond with. It defaults to `[\"audio\"]`,\n   * indicating that the model will respond with audio plus a transcript. `[\"text\"]`\n   * can be used to make the model respond with text only. It is not possible to\n   * request both `text` and `audio` at the same time.\n   */\n  output_modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * Reference to a prompt template and its variables.\n   * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n   */\n  prompt?: ResponsesAPI.ResponsePrompt | null;\n\n  /**\n   * How the model chooses tools. Provide one of the string modes or force a specific\n   * function/MCP tool.\n   */\n  tool_choice?: ResponsesAPI.ToolChoiceOptions | ResponsesAPI.ToolChoiceFunction | ResponsesAPI.ToolChoiceMcp;\n\n  /**\n   * Tools available to the model.\n   */\n  tools?: Array<RealtimeAPI.RealtimeFunctionTool | RealtimeSessionCreateResponse.McpTool>;\n\n  /**\n   * Realtime API can write session traces to the\n   * [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once\n   * tracing is enabled for a session, the configuration cannot be modified.\n   *\n   * `auto` will create a trace for the session with default values for the workflow\n   * name, group id, and metadata.\n   */\n  tracing?: 'auto' | RealtimeSessionCreateResponse.TracingConfiguration | null;\n\n  /**\n   * When the number of tokens in a conversation exceeds the model's input token\n   * limit, the conversation be truncated, meaning messages (starting from the\n   * oldest) will not be included in the model's context. A 32k context model with\n   * 4,096 max output tokens can only include 28,224 tokens in the context before\n   * truncation occurs.\n   *\n   * Clients can configure truncation behavior to truncate with a lower max token\n   * limit, which is an effective way to control token usage and cost.\n   *\n   * Truncation will reduce the number of cached tokens on the next turn (busting the\n   * cache), since messages are dropped from the beginning of the context. However,\n   * clients can also configure truncation to retain messages up to a fraction of the\n   * maximum context size, which will reduce the need for future truncations and thus\n   * improve the cache rate.\n   *\n   * Truncation can be disabled entirely, which means the server will never truncate\n   * but would instead return an error if the conversation exceeds the model's input\n   * token limit.\n   */\n  truncation?: RealtimeAPI.RealtimeTruncation;\n}\n\nexport namespace RealtimeSessionCreateResponse {\n  /**\n   * Configuration for input and output audio.\n   */\n  export interface Audio {\n    input?: Audio.Input;\n\n    output?: Audio.Output;\n  }\n\n  export namespace Audio {\n    export interface Input {\n      /**\n       * The format of the input audio.\n       */\n      format?: RealtimeAPI.RealtimeAudioFormats;\n\n      /**\n       * Configuration for input audio noise reduction. This can be set to `null` to turn\n       * off. Noise reduction filters audio added to the input audio buffer before it is\n       * sent to VAD and the model. Filtering the audio can improve VAD and turn\n       * detection accuracy (reducing false positives) and model performance by improving\n       * perception of the input audio.\n       */\n      noise_reduction?: Input.NoiseReduction;\n\n      /**\n       * Configuration for input audio transcription, defaults to off and can be set to\n       * `null` to turn off once on. Input audio transcription is not native to the\n       * model, since the model consumes audio directly. Transcription runs\n       * asynchronously through\n       * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n       * and should be treated as guidance of input audio content rather than precisely\n       * what the model heard. The client can optionally set the language and prompt for\n       * transcription, these offer additional guidance to the transcription service.\n       */\n      transcription?: RealtimeAPI.AudioTranscription;\n\n      /**\n       * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n       * set to `null` to turn off, in which case the client must manually trigger model\n       * response.\n       *\n       * Server VAD means that the model will detect the start and end of speech based on\n       * audio volume and respond at the end of user speech.\n       *\n       * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n       * with VAD) to semantically estimate whether the user has finished speaking, then\n       * dynamically sets a timeout based on this probability. For example, if user audio\n       * trails off with \"uhhm\", the model will score a low probability of turn end and\n       * wait longer for the user to continue speaking. This can be useful for more\n       * natural conversations, but may have a higher latency.\n       */\n      turn_detection?: Input.ServerVad | Input.SemanticVad | null;\n    }\n\n    export namespace Input {\n      /**\n       * Configuration for input audio noise reduction. This can be set to `null` to turn\n       * off. Noise reduction filters audio added to the input audio buffer before it is\n       * sent to VAD and the model. Filtering the audio can improve VAD and turn\n       * detection accuracy (reducing false positives) and model performance by improving\n       * perception of the input audio.\n       */\n      export interface NoiseReduction {\n        /**\n         * Type of noise reduction. `near_field` is for close-talking microphones such as\n         * headphones, `far_field` is for far-field microphones such as laptop or\n         * conference room microphones.\n         */\n        type?: RealtimeAPI.NoiseReductionType;\n      }\n\n      /**\n       * Server-side voice activity detection (VAD) which flips on when user speech is\n       * detected and off after a period of silence.\n       */\n      export interface ServerVad {\n        /**\n         * Type of turn detection, `server_vad` to turn on simple Server VAD.\n         */\n        type: 'server_vad';\n\n        /**\n         * Whether or not to automatically generate a response when a VAD stop event\n         * occurs. If `interrupt_response` is set to `false` this may fail to create a\n         * response if the model is already responding.\n         *\n         * If both `create_response` and `interrupt_response` are set to `false`, the model\n         * will never respond automatically but VAD events will still be emitted.\n         */\n        create_response?: boolean;\n\n        /**\n         * Optional timeout after which a model response will be triggered automatically.\n         * This is useful for situations in which a long pause from the user is unexpected,\n         * such as a phone call. The model will effectively prompt the user to continue the\n         * conversation based on the current context.\n         *\n         * The timeout value will be applied after the last model response's audio has\n         * finished playing, i.e. it's set to the `response.done` time plus audio playback\n         * duration.\n         *\n         * An `input_audio_buffer.timeout_triggered` event (plus events associated with the\n         * Response) will be emitted when the timeout is reached. Idle timeout is currently\n         * only supported for `server_vad` mode.\n         */\n        idle_timeout_ms?: number | null;\n\n        /**\n         * Whether or not to automatically interrupt (cancel) any ongoing response with\n         * output to the default conversation (i.e. `conversation` of `auto`) when a VAD\n         * start event occurs. If `true` then the response will be cancelled, otherwise it\n         * will continue until complete.\n         *\n         * If both `create_response` and `interrupt_response` are set to `false`, the model\n         * will never respond automatically but VAD events will still be emitted.\n         */\n        interrupt_response?: boolean;\n\n        /**\n         * Used only for `server_vad` mode. Amount of audio to include before the VAD\n         * detected speech (in milliseconds). Defaults to 300ms.\n         */\n        prefix_padding_ms?: number;\n\n        /**\n         * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n         * milliseconds). Defaults to 500ms. With shorter values the model will respond\n         * more quickly, but may jump in on short pauses from the user.\n         */\n        silence_duration_ms?: number;\n\n        /**\n         * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n         * defaults to 0.5. A higher threshold will require louder audio to activate the\n         * model, and thus might perform better in noisy environments.\n         */\n        threshold?: number;\n      }\n\n      /**\n       * Server-side semantic turn detection which uses a model to determine when the\n       * user has finished speaking.\n       */\n      export interface SemanticVad {\n        /**\n         * Type of turn detection, `semantic_vad` to turn on Semantic VAD.\n         */\n        type: 'semantic_vad';\n\n        /**\n         * Whether or not to automatically generate a response when a VAD stop event\n         * occurs.\n         */\n        create_response?: boolean;\n\n        /**\n         * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n         * will wait longer for the user to continue speaking, `high` will respond more\n         * quickly. `auto` is the default and is equivalent to `medium`. `low`, `medium`,\n         * and `high` have max timeouts of 8s, 4s, and 2s respectively.\n         */\n        eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n        /**\n         * Whether or not to automatically interrupt any ongoing response with output to\n         * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n         * occurs.\n         */\n        interrupt_response?: boolean;\n      }\n    }\n\n    export interface Output {\n      /**\n       * The format of the output audio.\n       */\n      format?: RealtimeAPI.RealtimeAudioFormats;\n\n      /**\n       * The speed of the model's spoken response as a multiple of the original speed.\n       * 1.0 is the default speed. 0.25 is the minimum speed. 1.5 is the maximum speed.\n       * This value can only be changed in between model turns, not while a response is\n       * in progress.\n       *\n       * This parameter is a post-processing adjustment to the audio after it is\n       * generated, it's also possible to prompt the model to speak faster or slower.\n       */\n      speed?: number;\n\n      /**\n       * The voice the model uses to respond. Voice cannot be changed during the session\n       * once the model has responded with audio at least once. Current voice options are\n       * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, `verse`, `marin`,\n       * and `cedar`. We recommend `marin` and `cedar` for best quality.\n       */\n      voice?:\n        | (string & {})\n        | 'alloy'\n        | 'ash'\n        | 'ballad'\n        | 'coral'\n        | 'echo'\n        | 'sage'\n        | 'shimmer'\n        | 'verse'\n        | 'marin'\n        | 'cedar';\n    }\n  }\n\n  /**\n   * Give the model access to additional tools via remote Model Context Protocol\n   * (MCP) servers.\n   * [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).\n   */\n  export interface McpTool {\n    /**\n     * A label for this MCP server, used to identify it in tool calls.\n     */\n    server_label: string;\n\n    /**\n     * The type of the MCP tool. Always `mcp`.\n     */\n    type: 'mcp';\n\n    /**\n     * List of allowed tool names or a filter object.\n     */\n    allowed_tools?: Array<string> | McpTool.McpToolFilter | null;\n\n    /**\n     * An OAuth access token that can be used with a remote MCP server, either with a\n     * custom MCP server URL or a service connector. Your application must handle the\n     * OAuth authorization flow and provide the token here.\n     */\n    authorization?: string;\n\n    /**\n     * Identifier for service connectors, like those available in ChatGPT. One of\n     * `server_url` or `connector_id` must be provided. Learn more about service\n     * connectors\n     * [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).\n     *\n     * Currently supported `connector_id` values are:\n     *\n     * - Dropbox: `connector_dropbox`\n     * - Gmail: `connector_gmail`\n     * - Google Calendar: `connector_googlecalendar`\n     * - Google Drive: `connector_googledrive`\n     * - Microsoft Teams: `connector_microsoftteams`\n     * - Outlook Calendar: `connector_outlookcalendar`\n     * - Outlook Email: `connector_outlookemail`\n     * - SharePoint: `connector_sharepoint`\n     */\n    connector_id?:\n      | 'connector_dropbox'\n      | 'connector_gmail'\n      | 'connector_googlecalendar'\n      | 'connector_googledrive'\n      | 'connector_microsoftteams'\n      | 'connector_outlookcalendar'\n      | 'connector_outlookemail'\n      | 'connector_sharepoint';\n\n    /**\n     * Whether this MCP tool is deferred and discovered via tool search.\n     */\n    defer_loading?: boolean;\n\n    /**\n     * Optional HTTP headers to send to the MCP server. Use for authentication or other\n     * purposes.\n     */\n    headers?: { [key: string]: string } | null;\n\n    /**\n     * Specify which of the MCP server's tools require approval.\n     */\n    require_approval?: McpTool.McpToolApprovalFilter | 'always' | 'never' | null;\n\n    /**\n     * Optional description of the MCP server, used to provide more context.\n     */\n    server_description?: string;\n\n    /**\n     * The URL for the MCP server. One of `server_url` or `connector_id` must be\n     * provided.\n     */\n    server_url?: string;\n  }\n\n  export namespace McpTool {\n    /**\n     * A filter object to specify which tools are allowed.\n     */\n    export interface McpToolFilter {\n      /**\n       * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n       * is\n       * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n       * it will match this filter.\n       */\n      read_only?: boolean;\n\n      /**\n       * List of allowed tool names.\n       */\n      tool_names?: Array<string>;\n    }\n\n    /**\n     * Specify which of the MCP server's tools require approval. Can be `always`,\n     * `never`, or a filter object associated with tools that require approval.\n     */\n    export interface McpToolApprovalFilter {\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      always?: McpToolApprovalFilter.Always;\n\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      never?: McpToolApprovalFilter.Never;\n    }\n\n    export namespace McpToolApprovalFilter {\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      export interface Always {\n        /**\n         * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n         * is\n         * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n         * it will match this filter.\n         */\n        read_only?: boolean;\n\n        /**\n         * List of allowed tool names.\n         */\n        tool_names?: Array<string>;\n      }\n\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      export interface Never {\n        /**\n         * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n         * is\n         * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n         * it will match this filter.\n         */\n        read_only?: boolean;\n\n        /**\n         * List of allowed tool names.\n         */\n        tool_names?: Array<string>;\n      }\n    }\n  }\n\n  /**\n   * Granular configuration for tracing.\n   */\n  export interface TracingConfiguration {\n    /**\n     * The group id to attach to this trace to enable filtering and grouping in the\n     * Traces Dashboard.\n     */\n    group_id?: string;\n\n    /**\n     * The arbitrary metadata to attach to this trace to enable filtering in the Traces\n     * Dashboard.\n     */\n    metadata?: unknown;\n\n    /**\n     * The name of the workflow to attach to this trace. This is used to name the trace\n     * in the Traces Dashboard.\n     */\n    workflow_name?: string;\n  }\n}\n\n/**\n * A Realtime transcription session configuration object.\n */\nexport interface RealtimeTranscriptionSessionCreateResponse {\n  /**\n   * Unique identifier for the session that looks like `sess_1234567890abcdef`.\n   */\n  id: string;\n\n  /**\n   * The object type. Always `realtime.transcription_session`.\n   */\n  object: string;\n\n  /**\n   * The type of session. Always `transcription` for transcription sessions.\n   */\n  type: 'transcription';\n\n  /**\n   * Configuration for input audio for the session.\n   */\n  audio?: RealtimeTranscriptionSessionCreateResponse.Audio;\n\n  /**\n   * Expiration timestamp for the session, in seconds since epoch.\n   */\n  expires_at?: number;\n\n  /**\n   * Additional fields to include in server outputs.\n   *\n   * - `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n   *   transcription.\n   */\n  include?: Array<'item.input_audio_transcription.logprobs'>;\n}\n\nexport namespace RealtimeTranscriptionSessionCreateResponse {\n  /**\n   * Configuration for input audio for the session.\n   */\n  export interface Audio {\n    input?: Audio.Input;\n  }\n\n  export namespace Audio {\n    export interface Input {\n      /**\n       * The PCM audio format. Only a 24kHz sample rate is supported.\n       */\n      format?: RealtimeAPI.RealtimeAudioFormats;\n\n      /**\n       * Configuration for input audio noise reduction.\n       */\n      noise_reduction?: Input.NoiseReduction;\n\n      /**\n       * Configuration of the transcription model.\n       */\n      transcription?: RealtimeAPI.AudioTranscription;\n\n      /**\n       * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n       * means that the model will detect the start and end of speech based on audio\n       * volume and respond at the end of user speech.\n       */\n      turn_detection?: ClientSecretsAPI.RealtimeTranscriptionSessionTurnDetection;\n    }\n\n    export namespace Input {\n      /**\n       * Configuration for input audio noise reduction.\n       */\n      export interface NoiseReduction {\n        /**\n         * Type of noise reduction. `near_field` is for close-talking microphones such as\n         * headphones, `far_field` is for far-field microphones such as laptop or\n         * conference room microphones.\n         */\n        type?: RealtimeAPI.NoiseReductionType;\n      }\n    }\n  }\n}\n\n/**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\nexport interface RealtimeTranscriptionSessionTurnDetection {\n  /**\n   * Amount of audio to include before the VAD detected speech (in milliseconds).\n   * Defaults to 300ms.\n   */\n  prefix_padding_ms?: number;\n\n  /**\n   * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.\n   * With shorter values the model will respond more quickly, but may jump in on\n   * short pauses from the user.\n   */\n  silence_duration_ms?: number;\n\n  /**\n   * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher\n   * threshold will require louder audio to activate the model, and thus might\n   * perform better in noisy environments.\n   */\n  threshold?: number;\n\n  /**\n   * Type of turn detection, only `server_vad` is currently supported.\n   */\n  type?: string;\n}\n\n/**\n * Response from creating a session and client secret for the Realtime API.\n */\nexport interface ClientSecretCreateResponse {\n  /**\n   * Expiration timestamp for the client secret, in seconds since epoch.\n   */\n  expires_at: number;\n\n  /**\n   * The session configuration for either a realtime or transcription session.\n   */\n  session: RealtimeSessionCreateResponse | RealtimeTranscriptionSessionCreateResponse;\n\n  /**\n   * The generated client secret value.\n   */\n  value: string;\n}\n\nexport interface ClientSecretCreateParams {\n  /**\n   * Configuration for the client secret expiration. Expiration refers to the time\n   * after which a client secret will no longer be valid for creating sessions. The\n   * session itself may continue after that time once started. A secret can be used\n   * to create multiple sessions until it expires.\n   */\n  expires_after?: ClientSecretCreateParams.ExpiresAfter;\n\n  /**\n   * Session configuration to use for the client secret. Choose either a realtime\n   * session or a transcription session.\n   */\n  session?: RealtimeAPI.RealtimeSessionCreateRequest | RealtimeAPI.RealtimeTranscriptionSessionCreateRequest;\n}\n\nexport namespace ClientSecretCreateParams {\n  /**\n   * Configuration for the client secret expiration. Expiration refers to the time\n   * after which a client secret will no longer be valid for creating sessions. The\n   * session itself may continue after that time once started. A secret can be used\n   * to create multiple sessions until it expires.\n   */\n  export interface ExpiresAfter {\n    /**\n     * The anchor point for the client secret expiration, meaning that `seconds` will\n     * be added to the `created_at` time of the client secret to produce an expiration\n     * timestamp. Only `created_at` is currently supported.\n     */\n    anchor?: 'created_at';\n\n    /**\n     * The number of seconds from the anchor point to the expiration. Select a value\n     * between `10` and `7200` (2 hours). This default to 600 seconds (10 minutes) if\n     * not specified.\n     */\n    seconds?: number;\n  }\n}\n\nexport declare namespace ClientSecrets {\n  export {\n    type RealtimeSessionClientSecret as RealtimeSessionClientSecret,\n    type RealtimeSessionCreateResponse as RealtimeSessionCreateResponse,\n    type RealtimeTranscriptionSessionCreateResponse as RealtimeTranscriptionSessionCreateResponse,\n    type RealtimeTranscriptionSessionTurnDetection as RealtimeTranscriptionSessionTurnDetection,\n    type ClientSecretCreateResponse as ClientSecretCreateResponse,\n    type ClientSecretCreateParams as ClientSecretCreateParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/realtime/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Calls, type CallAcceptParams, type CallReferParams, type CallRejectParams } from './calls';\nexport {\n  ClientSecrets,\n  type RealtimeSessionClientSecret,\n  type RealtimeSessionCreateResponse,\n  type RealtimeTranscriptionSessionCreateResponse,\n  type RealtimeTranscriptionSessionTurnDetection,\n  type ClientSecretCreateResponse,\n  type ClientSecretCreateParams,\n} from './client-secrets';\nexport { Realtime } from './realtime';\n"
  },
  {
    "path": "src/resources/realtime/realtime.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as RealtimeAPI from './realtime';\nimport * as Shared from '../shared';\nimport * as CallsAPI from './calls';\nimport { CallAcceptParams, CallReferParams, CallRejectParams, Calls } from './calls';\nimport * as ClientSecretsAPI from './client-secrets';\nimport {\n  ClientSecretCreateParams,\n  ClientSecretCreateResponse,\n  ClientSecrets,\n  RealtimeSessionClientSecret,\n  RealtimeSessionCreateResponse,\n  RealtimeTranscriptionSessionCreateResponse,\n  RealtimeTranscriptionSessionTurnDetection,\n} from './client-secrets';\nimport * as ResponsesAPI from '../responses/responses';\n\nexport class Realtime extends APIResource {\n  clientSecrets: ClientSecretsAPI.ClientSecrets = new ClientSecretsAPI.ClientSecrets(this._client);\n  calls: CallsAPI.Calls = new CallsAPI.Calls(this._client);\n}\n\nexport interface AudioTranscription {\n  /**\n   * The language of the input audio. Supplying the input language in\n   * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n   * format will improve accuracy and latency.\n   */\n  language?: string;\n\n  /**\n   * The model to use for transcription. Current options are `whisper-1`,\n   * `gpt-4o-mini-transcribe`, `gpt-4o-mini-transcribe-2025-12-15`,\n   * `gpt-4o-transcribe`, and `gpt-4o-transcribe-diarize`. Use\n   * `gpt-4o-transcribe-diarize` when you need diarization with speaker labels.\n   */\n  model?:\n    | (string & {})\n    | 'whisper-1'\n    | 'gpt-4o-mini-transcribe'\n    | 'gpt-4o-mini-transcribe-2025-12-15'\n    | 'gpt-4o-transcribe'\n    | 'gpt-4o-transcribe-diarize';\n\n  /**\n   * An optional text to guide the model's style or continue a previous audio\n   * segment. For `whisper-1`, the\n   * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n   * For `gpt-4o-transcribe` models (excluding `gpt-4o-transcribe-diarize`), the\n   * prompt is a free text string, for example \"expect words related to technology\".\n   */\n  prompt?: string;\n}\n\n/**\n * Returned when a conversation is created. Emitted right after session creation.\n */\nexport interface ConversationCreatedEvent {\n  /**\n   * The conversation resource.\n   */\n  conversation: ConversationCreatedEvent.Conversation;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The event type, must be `conversation.created`.\n   */\n  type: 'conversation.created';\n}\n\nexport namespace ConversationCreatedEvent {\n  /**\n   * The conversation resource.\n   */\n  export interface Conversation {\n    /**\n     * The unique ID of the conversation.\n     */\n    id?: string;\n\n    /**\n     * The object type, must be `realtime.conversation`.\n     */\n    object?: 'realtime.conversation';\n  }\n}\n\n/**\n * A single item within a Realtime conversation.\n */\nexport type ConversationItem =\n  | RealtimeConversationItemSystemMessage\n  | RealtimeConversationItemUserMessage\n  | RealtimeConversationItemAssistantMessage\n  | RealtimeConversationItemFunctionCall\n  | RealtimeConversationItemFunctionCallOutput\n  | RealtimeMcpApprovalResponse\n  | RealtimeMcpListTools\n  | RealtimeMcpToolCall\n  | RealtimeMcpApprovalRequest;\n\n/**\n * Sent by the server when an Item is added to the default Conversation. This can\n * happen in several cases:\n *\n * - When the client sends a `conversation.item.create` event.\n * - When the input audio buffer is committed. In this case the item will be a user\n *   message containing the audio from the buffer.\n * - When the model is generating a Response. In this case the\n *   `conversation.item.added` event will be sent when the model starts generating\n *   a specific Item, and thus it will not yet have any content (and `status` will\n *   be `in_progress`).\n *\n * The event will include the full content of the Item (except when model is\n * generating a Response) except for audio data, which can be retrieved separately\n * with a `conversation.item.retrieve` event if necessary.\n */\nexport interface ConversationItemAdded {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * A single item within a Realtime conversation.\n   */\n  item: ConversationItem;\n\n  /**\n   * The event type, must be `conversation.item.added`.\n   */\n  type: 'conversation.item.added';\n\n  /**\n   * The ID of the item that precedes this one, if any. This is used to maintain\n   * ordering when items are inserted.\n   */\n  previous_item_id?: string | null;\n}\n\n/**\n * Add a new Item to the Conversation's context, including messages, function\n * calls, and function call responses. This event can be used both to populate a\n * \"history\" of the conversation and to add new items mid-stream, but has the\n * current limitation that it cannot populate assistant audio messages.\n *\n * If successful, the server will respond with a `conversation.item.created` event,\n * otherwise an `error` event will be sent.\n */\nexport interface ConversationItemCreateEvent {\n  /**\n   * A single item within a Realtime conversation.\n   */\n  item: ConversationItem;\n\n  /**\n   * The event type, must be `conversation.item.create`.\n   */\n  type: 'conversation.item.create';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n\n  /**\n   * The ID of the preceding item after which the new item will be inserted. If not\n   * set, the new item will be appended to the end of the conversation.\n   *\n   * If set to `root`, the new item will be added to the beginning of the\n   * conversation.\n   *\n   * If set to an existing ID, it allows an item to be inserted mid-conversation. If\n   * the ID cannot be found, an error will be returned and the item will not be\n   * added.\n   */\n  previous_item_id?: string;\n}\n\n/**\n * Returned when a conversation item is created. There are several scenarios that\n * produce this event:\n *\n * - The server is generating a Response, which if successful will produce either\n *   one or two Items, which will be of type `message` (role `assistant`) or type\n *   `function_call`.\n * - The input audio buffer has been committed, either by the client or the server\n *   (in `server_vad` mode). The server will take the content of the input audio\n *   buffer and add it to a new user message Item.\n * - The client has sent a `conversation.item.create` event to add a new Item to\n *   the Conversation.\n */\nexport interface ConversationItemCreatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * A single item within a Realtime conversation.\n   */\n  item: ConversationItem;\n\n  /**\n   * The event type, must be `conversation.item.created`.\n   */\n  type: 'conversation.item.created';\n\n  /**\n   * The ID of the preceding item in the Conversation context, allows the client to\n   * understand the order of the conversation. Can be `null` if the item has no\n   * predecessor.\n   */\n  previous_item_id?: string | null;\n}\n\n/**\n * Send this event when you want to remove any item from the conversation history.\n * The server will respond with a `conversation.item.deleted` event, unless the\n * item does not exist in the conversation history, in which case the server will\n * respond with an error.\n */\nexport interface ConversationItemDeleteEvent {\n  /**\n   * The ID of the item to delete.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.delete`.\n   */\n  type: 'conversation.item.delete';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Returned when an item in the conversation is deleted by the client with a\n * `conversation.item.delete` event. This event is used to synchronize the server's\n * understanding of the conversation history with the client's view.\n */\nexport interface ConversationItemDeletedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item that was deleted.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.deleted`.\n   */\n  type: 'conversation.item.deleted';\n}\n\n/**\n * Returned when a conversation item is finalized.\n *\n * The event will include the full content of the Item except for audio data, which\n * can be retrieved separately with a `conversation.item.retrieve` event if needed.\n */\nexport interface ConversationItemDone {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * A single item within a Realtime conversation.\n   */\n  item: ConversationItem;\n\n  /**\n   * The event type, must be `conversation.item.done`.\n   */\n  type: 'conversation.item.done';\n\n  /**\n   * The ID of the item that precedes this one, if any. This is used to maintain\n   * ordering when items are inserted.\n   */\n  previous_item_id?: string | null;\n}\n\n/**\n * This event is the output of audio transcription for user audio written to the\n * user audio buffer. Transcription begins when the input audio buffer is committed\n * by the client or server (when VAD is enabled). Transcription runs asynchronously\n * with Response creation, so this event may come before or after the Response\n * events.\n *\n * Realtime API models accept audio natively, and thus input transcription is a\n * separate process run on a separate ASR (Automatic Speech Recognition) model. The\n * transcript may diverge somewhat from the model's interpretation, and should be\n * treated as a rough guide.\n */\nexport interface ConversationItemInputAudioTranscriptionCompletedEvent {\n  /**\n   * The index of the content part containing the audio.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item containing the audio that is being transcribed.\n   */\n  item_id: string;\n\n  /**\n   * The transcribed text.\n   */\n  transcript: string;\n\n  /**\n   * The event type, must be `conversation.item.input_audio_transcription.completed`.\n   */\n  type: 'conversation.item.input_audio_transcription.completed';\n\n  /**\n   * Usage statistics for the transcription, this is billed according to the ASR\n   * model's pricing rather than the realtime model's pricing.\n   */\n  usage:\n    | ConversationItemInputAudioTranscriptionCompletedEvent.TranscriptTextUsageTokens\n    | ConversationItemInputAudioTranscriptionCompletedEvent.TranscriptTextUsageDuration;\n\n  /**\n   * The log probabilities of the transcription.\n   */\n  logprobs?: Array<LogProbProperties> | null;\n}\n\nexport namespace ConversationItemInputAudioTranscriptionCompletedEvent {\n  /**\n   * Usage statistics for models billed by token usage.\n   */\n  export interface TranscriptTextUsageTokens {\n    /**\n     * Number of input tokens billed for this request.\n     */\n    input_tokens: number;\n\n    /**\n     * Number of output tokens generated.\n     */\n    output_tokens: number;\n\n    /**\n     * Total number of tokens used (input + output).\n     */\n    total_tokens: number;\n\n    /**\n     * The type of the usage object. Always `tokens` for this variant.\n     */\n    type: 'tokens';\n\n    /**\n     * Details about the input tokens billed for this request.\n     */\n    input_token_details?: TranscriptTextUsageTokens.InputTokenDetails;\n  }\n\n  export namespace TranscriptTextUsageTokens {\n    /**\n     * Details about the input tokens billed for this request.\n     */\n    export interface InputTokenDetails {\n      /**\n       * Number of audio tokens billed for this request.\n       */\n      audio_tokens?: number;\n\n      /**\n       * Number of text tokens billed for this request.\n       */\n      text_tokens?: number;\n    }\n  }\n\n  /**\n   * Usage statistics for models billed by audio input duration.\n   */\n  export interface TranscriptTextUsageDuration {\n    /**\n     * Duration of the input audio in seconds.\n     */\n    seconds: number;\n\n    /**\n     * The type of the usage object. Always `duration` for this variant.\n     */\n    type: 'duration';\n  }\n}\n\n/**\n * Returned when the text value of an input audio transcription content part is\n * updated with incremental transcription results.\n */\nexport interface ConversationItemInputAudioTranscriptionDeltaEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item containing the audio that is being transcribed.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.input_audio_transcription.delta`.\n   */\n  type: 'conversation.item.input_audio_transcription.delta';\n\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index?: number;\n\n  /**\n   * The text delta.\n   */\n  delta?: string;\n\n  /**\n   * The log probabilities of the transcription. These can be enabled by\n   * configurating the session with\n   * `\"include\": [\"item.input_audio_transcription.logprobs\"]`. Each entry in the\n   * array corresponds a log probability of which token would be selected for this\n   * chunk of transcription. This can help to identify if it was possible there were\n   * multiple valid options for a given chunk of transcription.\n   */\n  logprobs?: Array<LogProbProperties> | null;\n}\n\n/**\n * Returned when input audio transcription is configured, and a transcription\n * request for a user message failed. These events are separate from other `error`\n * events so that the client can identify the related Item.\n */\nexport interface ConversationItemInputAudioTranscriptionFailedEvent {\n  /**\n   * The index of the content part containing the audio.\n   */\n  content_index: number;\n\n  /**\n   * Details of the transcription error.\n   */\n  error: ConversationItemInputAudioTranscriptionFailedEvent.Error;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the user message item.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.input_audio_transcription.failed`.\n   */\n  type: 'conversation.item.input_audio_transcription.failed';\n}\n\nexport namespace ConversationItemInputAudioTranscriptionFailedEvent {\n  /**\n   * Details of the transcription error.\n   */\n  export interface Error {\n    /**\n     * Error code, if any.\n     */\n    code?: string;\n\n    /**\n     * A human-readable error message.\n     */\n    message?: string;\n\n    /**\n     * Parameter related to the error, if any.\n     */\n    param?: string;\n\n    /**\n     * The type of error.\n     */\n    type?: string;\n  }\n}\n\n/**\n * Returned when an input audio transcription segment is identified for an item.\n */\nexport interface ConversationItemInputAudioTranscriptionSegment {\n  /**\n   * The segment identifier.\n   */\n  id: string;\n\n  /**\n   * The index of the input audio content part within the item.\n   */\n  content_index: number;\n\n  /**\n   * End time of the segment in seconds.\n   */\n  end: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item containing the input audio content.\n   */\n  item_id: string;\n\n  /**\n   * The detected speaker label for this segment.\n   */\n  speaker: string;\n\n  /**\n   * Start time of the segment in seconds.\n   */\n  start: number;\n\n  /**\n   * The text for this segment.\n   */\n  text: string;\n\n  /**\n   * The event type, must be `conversation.item.input_audio_transcription.segment`.\n   */\n  type: 'conversation.item.input_audio_transcription.segment';\n}\n\n/**\n * Send this event when you want to retrieve the server's representation of a\n * specific item in the conversation history. This is useful, for example, to\n * inspect user audio after noise cancellation and VAD. The server will respond\n * with a `conversation.item.retrieved` event, unless the item does not exist in\n * the conversation history, in which case the server will respond with an error.\n */\nexport interface ConversationItemRetrieveEvent {\n  /**\n   * The ID of the item to retrieve.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.retrieve`.\n   */\n  type: 'conversation.item.retrieve';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Send this event to truncate a previous assistant message’s audio. The server\n * will produce audio faster than realtime, so this event is useful when the user\n * interrupts to truncate audio that has already been sent to the client but not\n * yet played. This will synchronize the server's understanding of the audio with\n * the client's playback.\n *\n * Truncating audio will delete the server-side text transcript to ensure there is\n * not text in the context that hasn't been heard by the user.\n *\n * If successful, the server will respond with a `conversation.item.truncated`\n * event.\n */\nexport interface ConversationItemTruncateEvent {\n  /**\n   * Inclusive duration up to which audio is truncated, in milliseconds. If the\n   * audio_end_ms is greater than the actual audio duration, the server will respond\n   * with an error.\n   */\n  audio_end_ms: number;\n\n  /**\n   * The index of the content part to truncate. Set this to `0`.\n   */\n  content_index: number;\n\n  /**\n   * The ID of the assistant message item to truncate. Only assistant message items\n   * can be truncated.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.truncate`.\n   */\n  type: 'conversation.item.truncate';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Returned when an earlier assistant audio message item is truncated by the client\n * with a `conversation.item.truncate` event. This event is used to synchronize the\n * server's understanding of the audio with the client's playback.\n *\n * This action will truncate the audio and remove the server-side text transcript\n * to ensure there is no text in the context that hasn't been heard by the user.\n */\nexport interface ConversationItemTruncatedEvent {\n  /**\n   * The duration up to which the audio was truncated, in milliseconds.\n   */\n  audio_end_ms: number;\n\n  /**\n   * The index of the content part that was truncated.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the assistant message item that was truncated.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `conversation.item.truncated`.\n   */\n  type: 'conversation.item.truncated';\n}\n\n/**\n * The item to add to the conversation.\n */\nexport interface ConversationItemWithReference {\n  /**\n   * For an item of type (`message` | `function_call` | `function_call_output`) this\n   * field allows the client to assign the unique ID of the item. It is not required\n   * because the server will generate one if not provided.\n   *\n   * For an item of type `item_reference`, this field is required and is a reference\n   * to any item that has previously existed in the conversation.\n   */\n  id?: string;\n\n  /**\n   * The arguments of the function call (for `function_call` items).\n   */\n  arguments?: string;\n\n  /**\n   * The ID of the function call (for `function_call` and `function_call_output`\n   * items). If passed on a `function_call_output` item, the server will check that a\n   * `function_call` item with the same ID exists in the conversation history.\n   */\n  call_id?: string;\n\n  /**\n   * The content of the message, applicable for `message` items.\n   *\n   * - Message items of role `system` support only `input_text` content\n   * - Message items of role `user` support `input_text` and `input_audio` content\n   * - Message items of role `assistant` support `text` content.\n   */\n  content?: Array<ConversationItemWithReference.Content>;\n\n  /**\n   * The name of the function being called (for `function_call` items).\n   */\n  name?: string;\n\n  /**\n   * Identifier for the API object being returned - always `realtime.item`.\n   */\n  object?: 'realtime.item';\n\n  /**\n   * The output of the function call (for `function_call_output` items).\n   */\n  output?: string;\n\n  /**\n   * The role of the message sender (`user`, `assistant`, `system`), only applicable\n   * for `message` items.\n   */\n  role?: 'user' | 'assistant' | 'system';\n\n  /**\n   * The status of the item (`completed`, `incomplete`, `in_progress`). These have no\n   * effect on the conversation, but are accepted for consistency with the\n   * `conversation.item.created` event.\n   */\n  status?: 'completed' | 'incomplete' | 'in_progress';\n\n  /**\n   * The type of the item (`message`, `function_call`, `function_call_output`,\n   * `item_reference`).\n   */\n  type?: 'message' | 'function_call' | 'function_call_output' | 'item_reference';\n}\n\nexport namespace ConversationItemWithReference {\n  export interface Content {\n    /**\n     * ID of a previous conversation item to reference (for `item_reference` content\n     * types in `response.create` events). These can reference both client and server\n     * created items.\n     */\n    id?: string;\n\n    /**\n     * Base64-encoded audio bytes, used for `input_audio` content type.\n     */\n    audio?: string;\n\n    /**\n     * The text content, used for `input_text` and `text` content types.\n     */\n    text?: string;\n\n    /**\n     * The transcript of the audio, used for `input_audio` content type.\n     */\n    transcript?: string;\n\n    /**\n     * The content type (`input_text`, `input_audio`, `item_reference`, `text`).\n     */\n    type?: 'input_text' | 'input_audio' | 'item_reference' | 'text';\n  }\n}\n\n/**\n * Send this event to append audio bytes to the input audio buffer. The audio\n * buffer is temporary storage you can write to and later commit. A \"commit\" will\n * create a new user message item in the conversation history from the buffer\n * content and clear the buffer. Input audio transcription (if enabled) will be\n * generated when the buffer is committed.\n *\n * If VAD is enabled the audio buffer is used to detect speech and the server will\n * decide when to commit. When Server VAD is disabled, you must commit the audio\n * buffer manually. Input audio noise reduction operates on writes to the audio\n * buffer.\n *\n * The client may choose how much audio to place in each event up to a maximum of\n * 15 MiB, for example streaming smaller chunks from the client may allow the VAD\n * to be more responsive. Unlike most other client events, the server will not send\n * a confirmation response to this event.\n */\nexport interface InputAudioBufferAppendEvent {\n  /**\n   * Base64-encoded audio bytes. This must be in the format specified by the\n   * `input_audio_format` field in the session configuration.\n   */\n  audio: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.append`.\n   */\n  type: 'input_audio_buffer.append';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Send this event to clear the audio bytes in the buffer. The server will respond\n * with an `input_audio_buffer.cleared` event.\n */\nexport interface InputAudioBufferClearEvent {\n  /**\n   * The event type, must be `input_audio_buffer.clear`.\n   */\n  type: 'input_audio_buffer.clear';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Returned when the input audio buffer is cleared by the client with a\n * `input_audio_buffer.clear` event.\n */\nexport interface InputAudioBufferClearedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.cleared`.\n   */\n  type: 'input_audio_buffer.cleared';\n}\n\n/**\n * Send this event to commit the user input audio buffer, which will create a new\n * user message item in the conversation. This event will produce an error if the\n * input audio buffer is empty. When in Server VAD mode, the client does not need\n * to send this event, the server will commit the audio buffer automatically.\n *\n * Committing the input audio buffer will trigger input audio transcription (if\n * enabled in session configuration), but it will not create a response from the\n * model. The server will respond with an `input_audio_buffer.committed` event.\n */\nexport interface InputAudioBufferCommitEvent {\n  /**\n   * The event type, must be `input_audio_buffer.commit`.\n   */\n  type: 'input_audio_buffer.commit';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\n/**\n * Returned when an input audio buffer is committed, either by the client or\n * automatically in server VAD mode. The `item_id` property is the ID of the user\n * message item that will be created, thus a `conversation.item.created` event will\n * also be sent to the client.\n */\nexport interface InputAudioBufferCommittedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the user message item that will be created.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.committed`.\n   */\n  type: 'input_audio_buffer.committed';\n\n  /**\n   * The ID of the preceding item after which the new item will be inserted. Can be\n   * `null` if the item has no predecessor.\n   */\n  previous_item_id?: string | null;\n}\n\n/**\n * **SIP Only:** Returned when an DTMF event is received. A DTMF event is a message\n * that represents a telephone keypad press (0–9, \\*, #, A–D). The `event` property\n * is the keypad that the user press. The `received_at` is the UTC Unix Timestamp\n * that the server received the event.\n */\nexport interface InputAudioBufferDtmfEventReceivedEvent {\n  /**\n   * The telephone keypad that was pressed by the user.\n   */\n  event: string;\n\n  /**\n   * UTC Unix Timestamp when DTMF Event was received by server.\n   */\n  received_at: number;\n\n  /**\n   * The event type, must be `input_audio_buffer.dtmf_event_received`.\n   */\n  type: 'input_audio_buffer.dtmf_event_received';\n}\n\n/**\n * Sent by the server when in `server_vad` mode to indicate that speech has been\n * detected in the audio buffer. This can happen any time audio is added to the\n * buffer (unless speech is already detected). The client may want to use this\n * event to interrupt audio playback or provide visual feedback to the user.\n *\n * The client should expect to receive a `input_audio_buffer.speech_stopped` event\n * when speech stops. The `item_id` property is the ID of the user message item\n * that will be created when speech stops and will also be included in the\n * `input_audio_buffer.speech_stopped` event (unless the client manually commits\n * the audio buffer during VAD activation).\n */\nexport interface InputAudioBufferSpeechStartedEvent {\n  /**\n   * Milliseconds from the start of all audio written to the buffer during the\n   * session when speech was first detected. This will correspond to the beginning of\n   * audio sent to the model, and thus includes the `prefix_padding_ms` configured in\n   * the Session.\n   */\n  audio_start_ms: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the user message item that will be created when speech stops.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.speech_started`.\n   */\n  type: 'input_audio_buffer.speech_started';\n}\n\n/**\n * Returned in `server_vad` mode when the server detects the end of speech in the\n * audio buffer. The server will also send an `conversation.item.created` event\n * with the user message item that is created from the audio buffer.\n */\nexport interface InputAudioBufferSpeechStoppedEvent {\n  /**\n   * Milliseconds since the session started when speech stopped. This will correspond\n   * to the end of audio sent to the model, and thus includes the\n   * `min_silence_duration_ms` configured in the Session.\n   */\n  audio_end_ms: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the user message item that will be created.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.speech_stopped`.\n   */\n  type: 'input_audio_buffer.speech_stopped';\n}\n\n/**\n * Returned when the Server VAD timeout is triggered for the input audio buffer.\n * This is configured with `idle_timeout_ms` in the `turn_detection` settings of\n * the session, and it indicates that there hasn't been any speech detected for the\n * configured duration.\n *\n * The `audio_start_ms` and `audio_end_ms` fields indicate the segment of audio\n * after the last model response up to the triggering time, as an offset from the\n * beginning of audio written to the input audio buffer. This means it demarcates\n * the segment of audio that was silent and the difference between the start and\n * end values will roughly match the configured timeout.\n *\n * The empty audio will be committed to the conversation as an `input_audio` item\n * (there will be a `input_audio_buffer.committed` event) and a model response will\n * be generated. There may be speech that didn't trigger VAD but is still detected\n * by the model, so the model may respond with something relevant to the\n * conversation or a prompt to continue speaking.\n */\nexport interface InputAudioBufferTimeoutTriggered {\n  /**\n   * Millisecond offset of audio written to the input audio buffer at the time the\n   * timeout was triggered.\n   */\n  audio_end_ms: number;\n\n  /**\n   * Millisecond offset of audio written to the input audio buffer that was after the\n   * playback time of the last model response.\n   */\n  audio_start_ms: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item associated with this segment.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `input_audio_buffer.timeout_triggered`.\n   */\n  type: 'input_audio_buffer.timeout_triggered';\n}\n\n/**\n * A log probability object.\n */\nexport interface LogProbProperties {\n  /**\n   * The token that was used to generate the log probability.\n   */\n  token: string;\n\n  /**\n   * The bytes that were used to generate the log probability.\n   */\n  bytes: Array<number>;\n\n  /**\n   * The log probability of the token.\n   */\n  logprob: number;\n}\n\n/**\n * Returned when listing MCP tools has completed for an item.\n */\nexport interface McpListToolsCompleted {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the MCP list tools item.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `mcp_list_tools.completed`.\n   */\n  type: 'mcp_list_tools.completed';\n}\n\n/**\n * Returned when listing MCP tools has failed for an item.\n */\nexport interface McpListToolsFailed {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the MCP list tools item.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `mcp_list_tools.failed`.\n   */\n  type: 'mcp_list_tools.failed';\n}\n\n/**\n * Returned when listing MCP tools is in progress for an item.\n */\nexport interface McpListToolsInProgress {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the MCP list tools item.\n   */\n  item_id: string;\n\n  /**\n   * The event type, must be `mcp_list_tools.in_progress`.\n   */\n  type: 'mcp_list_tools.in_progress';\n}\n\n/**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\nexport type NoiseReductionType = 'near_field' | 'far_field';\n\n/**\n * **WebRTC/SIP Only:** Emit to cut off the current audio response. This will\n * trigger the server to stop generating audio and emit a\n * `output_audio_buffer.cleared` event. This event should be preceded by a\n * `response.cancel` client event to stop the generation of the current response.\n * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n */\nexport interface OutputAudioBufferClearEvent {\n  /**\n   * The event type, must be `output_audio_buffer.clear`.\n   */\n  type: 'output_audio_buffer.clear';\n\n  /**\n   * The unique ID of the client event used for error handling.\n   */\n  event_id?: string;\n}\n\n/**\n * Emitted at the beginning of a Response to indicate the updated rate limits. When\n * a Response is created some tokens will be \"reserved\" for the output tokens, the\n * rate limits shown here reflect that reservation, which is then adjusted\n * accordingly once the Response is completed.\n */\nexport interface RateLimitsUpdatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * List of rate limit information.\n   */\n  rate_limits: Array<RateLimitsUpdatedEvent.RateLimit>;\n\n  /**\n   * The event type, must be `rate_limits.updated`.\n   */\n  type: 'rate_limits.updated';\n}\n\nexport namespace RateLimitsUpdatedEvent {\n  export interface RateLimit {\n    /**\n     * The maximum allowed value for the rate limit.\n     */\n    limit?: number;\n\n    /**\n     * The name of the rate limit (`requests`, `tokens`).\n     */\n    name?: 'requests' | 'tokens';\n\n    /**\n     * The remaining value before the limit is reached.\n     */\n    remaining?: number;\n\n    /**\n     * Seconds until the rate limit resets.\n     */\n    reset_seconds?: number;\n  }\n}\n\n/**\n * Configuration for input and output audio.\n */\nexport interface RealtimeAudioConfig {\n  input?: RealtimeAudioConfigInput;\n\n  output?: RealtimeAudioConfigOutput;\n}\n\nexport interface RealtimeAudioConfigInput {\n  /**\n   * The format of the input audio.\n   */\n  format?: RealtimeAudioFormats;\n\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  noise_reduction?: RealtimeAudioConfigInput.NoiseReduction;\n\n  /**\n   * Configuration for input audio transcription, defaults to off and can be set to\n   * `null` to turn off once on. Input audio transcription is not native to the\n   * model, since the model consumes audio directly. Transcription runs\n   * asynchronously through\n   * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n   * and should be treated as guidance of input audio content rather than precisely\n   * what the model heard. The client can optionally set the language and prompt for\n   * transcription, these offer additional guidance to the transcription service.\n   */\n  transcription?: AudioTranscription;\n\n  /**\n   * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n   * set to `null` to turn off, in which case the client must manually trigger model\n   * response.\n   *\n   * Server VAD means that the model will detect the start and end of speech based on\n   * audio volume and respond at the end of user speech.\n   *\n   * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n   * with VAD) to semantically estimate whether the user has finished speaking, then\n   * dynamically sets a timeout based on this probability. For example, if user audio\n   * trails off with \"uhhm\", the model will score a low probability of turn end and\n   * wait longer for the user to continue speaking. This can be useful for more\n   * natural conversations, but may have a higher latency.\n   */\n  turn_detection?: RealtimeAudioInputTurnDetection | null;\n}\n\nexport namespace RealtimeAudioConfigInput {\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  export interface NoiseReduction {\n    /**\n     * Type of noise reduction. `near_field` is for close-talking microphones such as\n     * headphones, `far_field` is for far-field microphones such as laptop or\n     * conference room microphones.\n     */\n    type?: RealtimeAPI.NoiseReductionType;\n  }\n}\n\nexport interface RealtimeAudioConfigOutput {\n  /**\n   * The format of the output audio.\n   */\n  format?: RealtimeAudioFormats;\n\n  /**\n   * The speed of the model's spoken response as a multiple of the original speed.\n   * 1.0 is the default speed. 0.25 is the minimum speed. 1.5 is the maximum speed.\n   * This value can only be changed in between model turns, not while a response is\n   * in progress.\n   *\n   * This parameter is a post-processing adjustment to the audio after it is\n   * generated, it's also possible to prompt the model to speak faster or slower.\n   */\n  speed?: number;\n\n  /**\n   * The voice the model uses to respond. Supported built-in voices are `alloy`,\n   * `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, `verse`, `marin`, and\n   * `cedar`. You may also provide a custom voice object with an `id`, for example\n   * `{ \"id\": \"voice_1234\" }`. Voice cannot be changed during the session once the\n   * model has responded with audio at least once. We recommend `marin` and `cedar`\n   * for best quality.\n   */\n  voice?:\n    | string\n    | 'alloy'\n    | 'ash'\n    | 'ballad'\n    | 'coral'\n    | 'echo'\n    | 'sage'\n    | 'shimmer'\n    | 'verse'\n    | 'marin'\n    | 'cedar'\n    | RealtimeAudioConfigOutput.ID;\n}\n\nexport namespace RealtimeAudioConfigOutput {\n  /**\n   * Custom voice reference.\n   */\n  export interface ID {\n    /**\n     * The custom voice ID, e.g. `voice_1234`.\n     */\n    id: string;\n  }\n}\n\n/**\n * The PCM audio format. Only a 24kHz sample rate is supported.\n */\nexport type RealtimeAudioFormats =\n  | RealtimeAudioFormats.AudioPCM\n  | RealtimeAudioFormats.AudioPCMU\n  | RealtimeAudioFormats.AudioPCMA;\n\nexport namespace RealtimeAudioFormats {\n  /**\n   * The PCM audio format. Only a 24kHz sample rate is supported.\n   */\n  export interface AudioPCM {\n    /**\n     * The sample rate of the audio. Always `24000`.\n     */\n    rate?: 24000;\n\n    /**\n     * The audio format. Always `audio/pcm`.\n     */\n    type?: 'audio/pcm';\n  }\n\n  /**\n   * The G.711 μ-law format.\n   */\n  export interface AudioPCMU {\n    /**\n     * The audio format. Always `audio/pcmu`.\n     */\n    type?: 'audio/pcmu';\n  }\n\n  /**\n   * The G.711 A-law format.\n   */\n  export interface AudioPCMA {\n    /**\n     * The audio format. Always `audio/pcma`.\n     */\n    type?: 'audio/pcma';\n  }\n}\n\n/**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response.\n *\n * Server VAD means that the model will detect the start and end of speech based on\n * audio volume and respond at the end of user speech.\n *\n * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n * with VAD) to semantically estimate whether the user has finished speaking, then\n * dynamically sets a timeout based on this probability. For example, if user audio\n * trails off with \"uhhm\", the model will score a low probability of turn end and\n * wait longer for the user to continue speaking. This can be useful for more\n * natural conversations, but may have a higher latency.\n */\nexport type RealtimeAudioInputTurnDetection =\n  | RealtimeAudioInputTurnDetection.ServerVad\n  | RealtimeAudioInputTurnDetection.SemanticVad;\n\nexport namespace RealtimeAudioInputTurnDetection {\n  /**\n   * Server-side voice activity detection (VAD) which flips on when user speech is\n   * detected and off after a period of silence.\n   */\n  export interface ServerVad {\n    /**\n     * Type of turn detection, `server_vad` to turn on simple Server VAD.\n     */\n    type: 'server_vad';\n\n    /**\n     * Whether or not to automatically generate a response when a VAD stop event\n     * occurs. If `interrupt_response` is set to `false` this may fail to create a\n     * response if the model is already responding.\n     *\n     * If both `create_response` and `interrupt_response` are set to `false`, the model\n     * will never respond automatically but VAD events will still be emitted.\n     */\n    create_response?: boolean;\n\n    /**\n     * Optional timeout after which a model response will be triggered automatically.\n     * This is useful for situations in which a long pause from the user is unexpected,\n     * such as a phone call. The model will effectively prompt the user to continue the\n     * conversation based on the current context.\n     *\n     * The timeout value will be applied after the last model response's audio has\n     * finished playing, i.e. it's set to the `response.done` time plus audio playback\n     * duration.\n     *\n     * An `input_audio_buffer.timeout_triggered` event (plus events associated with the\n     * Response) will be emitted when the timeout is reached. Idle timeout is currently\n     * only supported for `server_vad` mode.\n     */\n    idle_timeout_ms?: number | null;\n\n    /**\n     * Whether or not to automatically interrupt (cancel) any ongoing response with\n     * output to the default conversation (i.e. `conversation` of `auto`) when a VAD\n     * start event occurs. If `true` then the response will be cancelled, otherwise it\n     * will continue until complete.\n     *\n     * If both `create_response` and `interrupt_response` are set to `false`, the model\n     * will never respond automatically but VAD events will still be emitted.\n     */\n    interrupt_response?: boolean;\n\n    /**\n     * Used only for `server_vad` mode. Amount of audio to include before the VAD\n     * detected speech (in milliseconds). Defaults to 300ms.\n     */\n    prefix_padding_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n     * milliseconds). Defaults to 500ms. With shorter values the model will respond\n     * more quickly, but may jump in on short pauses from the user.\n     */\n    silence_duration_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n     * defaults to 0.5. A higher threshold will require louder audio to activate the\n     * model, and thus might perform better in noisy environments.\n     */\n    threshold?: number;\n  }\n\n  /**\n   * Server-side semantic turn detection which uses a model to determine when the\n   * user has finished speaking.\n   */\n  export interface SemanticVad {\n    /**\n     * Type of turn detection, `semantic_vad` to turn on Semantic VAD.\n     */\n    type: 'semantic_vad';\n\n    /**\n     * Whether or not to automatically generate a response when a VAD stop event\n     * occurs.\n     */\n    create_response?: boolean;\n\n    /**\n     * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n     * will wait longer for the user to continue speaking, `high` will respond more\n     * quickly. `auto` is the default and is equivalent to `medium`. `low`, `medium`,\n     * and `high` have max timeouts of 8s, 4s, and 2s respectively.\n     */\n    eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n    /**\n     * Whether or not to automatically interrupt any ongoing response with output to\n     * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n     * occurs.\n     */\n    interrupt_response?: boolean;\n  }\n}\n\n/**\n * A realtime client event.\n */\nexport type RealtimeClientEvent =\n  | ConversationItemCreateEvent\n  | ConversationItemDeleteEvent\n  | ConversationItemRetrieveEvent\n  | ConversationItemTruncateEvent\n  | InputAudioBufferAppendEvent\n  | InputAudioBufferClearEvent\n  | OutputAudioBufferClearEvent\n  | InputAudioBufferCommitEvent\n  | ResponseCancelEvent\n  | ResponseCreateEvent\n  | SessionUpdateEvent;\n\n/**\n * An assistant message item in a Realtime conversation.\n */\nexport interface RealtimeConversationItemAssistantMessage {\n  /**\n   * The content of the message.\n   */\n  content: Array<RealtimeConversationItemAssistantMessage.Content>;\n\n  /**\n   * The role of the message sender. Always `assistant`.\n   */\n  role: 'assistant';\n\n  /**\n   * The type of the item. Always `message`.\n   */\n  type: 'message';\n\n  /**\n   * The unique ID of the item. This may be provided by the client or generated by\n   * the server.\n   */\n  id?: string;\n\n  /**\n   * Identifier for the API object being returned - always `realtime.item`. Optional\n   * when creating a new item.\n   */\n  object?: 'realtime.item';\n\n  /**\n   * The status of the item. Has no effect on the conversation.\n   */\n  status?: 'completed' | 'incomplete' | 'in_progress';\n}\n\nexport namespace RealtimeConversationItemAssistantMessage {\n  export interface Content {\n    /**\n     * Base64-encoded audio bytes, these will be parsed as the format specified in the\n     * session output audio type configuration. This defaults to PCM 16-bit 24kHz mono\n     * if not specified.\n     */\n    audio?: string;\n\n    /**\n     * The text content.\n     */\n    text?: string;\n\n    /**\n     * The transcript of the audio content, this will always be present if the output\n     * type is `audio`.\n     */\n    transcript?: string;\n\n    /**\n     * The content type, `output_text` or `output_audio` depending on the session\n     * `output_modalities` configuration.\n     */\n    type?: 'output_text' | 'output_audio';\n  }\n}\n\n/**\n * A function call item in a Realtime conversation.\n */\nexport interface RealtimeConversationItemFunctionCall {\n  /**\n   * The arguments of the function call. This is a JSON-encoded string representing\n   * the arguments passed to the function, for example\n   * `{\"arg1\": \"value1\", \"arg2\": 42}`.\n   */\n  arguments: string;\n\n  /**\n   * The name of the function being called.\n   */\n  name: string;\n\n  /**\n   * The type of the item. Always `function_call`.\n   */\n  type: 'function_call';\n\n  /**\n   * The unique ID of the item. This may be provided by the client or generated by\n   * the server.\n   */\n  id?: string;\n\n  /**\n   * The ID of the function call.\n   */\n  call_id?: string;\n\n  /**\n   * Identifier for the API object being returned - always `realtime.item`. Optional\n   * when creating a new item.\n   */\n  object?: 'realtime.item';\n\n  /**\n   * The status of the item. Has no effect on the conversation.\n   */\n  status?: 'completed' | 'incomplete' | 'in_progress';\n}\n\n/**\n * A function call output item in a Realtime conversation.\n */\nexport interface RealtimeConversationItemFunctionCallOutput {\n  /**\n   * The ID of the function call this output is for.\n   */\n  call_id: string;\n\n  /**\n   * The output of the function call, this is free text and can contain any\n   * information or simply be empty.\n   */\n  output: string;\n\n  /**\n   * The type of the item. Always `function_call_output`.\n   */\n  type: 'function_call_output';\n\n  /**\n   * The unique ID of the item. This may be provided by the client or generated by\n   * the server.\n   */\n  id?: string;\n\n  /**\n   * Identifier for the API object being returned - always `realtime.item`. Optional\n   * when creating a new item.\n   */\n  object?: 'realtime.item';\n\n  /**\n   * The status of the item. Has no effect on the conversation.\n   */\n  status?: 'completed' | 'incomplete' | 'in_progress';\n}\n\n/**\n * A system message in a Realtime conversation can be used to provide additional\n * context or instructions to the model. This is similar but distinct from the\n * instruction prompt provided at the start of a conversation, as system messages\n * can be added at any point in the conversation. For major changes to the\n * conversation's behavior, use instructions, but for smaller updates (e.g. \"the\n * user is now asking about a different topic\"), use system messages.\n */\nexport interface RealtimeConversationItemSystemMessage {\n  /**\n   * The content of the message.\n   */\n  content: Array<RealtimeConversationItemSystemMessage.Content>;\n\n  /**\n   * The role of the message sender. Always `system`.\n   */\n  role: 'system';\n\n  /**\n   * The type of the item. Always `message`.\n   */\n  type: 'message';\n\n  /**\n   * The unique ID of the item. This may be provided by the client or generated by\n   * the server.\n   */\n  id?: string;\n\n  /**\n   * Identifier for the API object being returned - always `realtime.item`. Optional\n   * when creating a new item.\n   */\n  object?: 'realtime.item';\n\n  /**\n   * The status of the item. Has no effect on the conversation.\n   */\n  status?: 'completed' | 'incomplete' | 'in_progress';\n}\n\nexport namespace RealtimeConversationItemSystemMessage {\n  export interface Content {\n    /**\n     * The text content.\n     */\n    text?: string;\n\n    /**\n     * The content type. Always `input_text` for system messages.\n     */\n    type?: 'input_text';\n  }\n}\n\n/**\n * A user message item in a Realtime conversation.\n */\nexport interface RealtimeConversationItemUserMessage {\n  /**\n   * The content of the message.\n   */\n  content: Array<RealtimeConversationItemUserMessage.Content>;\n\n  /**\n   * The role of the message sender. Always `user`.\n   */\n  role: 'user';\n\n  /**\n   * The type of the item. Always `message`.\n   */\n  type: 'message';\n\n  /**\n   * The unique ID of the item. This may be provided by the client or generated by\n   * the server.\n   */\n  id?: string;\n\n  /**\n   * Identifier for the API object being returned - always `realtime.item`. Optional\n   * when creating a new item.\n   */\n  object?: 'realtime.item';\n\n  /**\n   * The status of the item. Has no effect on the conversation.\n   */\n  status?: 'completed' | 'incomplete' | 'in_progress';\n}\n\nexport namespace RealtimeConversationItemUserMessage {\n  export interface Content {\n    /**\n     * Base64-encoded audio bytes (for `input_audio`), these will be parsed as the\n     * format specified in the session input audio type configuration. This defaults to\n     * PCM 16-bit 24kHz mono if not specified.\n     */\n    audio?: string;\n\n    /**\n     * The detail level of the image (for `input_image`). `auto` will default to\n     * `high`.\n     */\n    detail?: 'auto' | 'low' | 'high';\n\n    /**\n     * Base64-encoded image bytes (for `input_image`) as a data URI. For example\n     * `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...`. Supported formats are PNG\n     * and JPEG.\n     */\n    image_url?: string;\n\n    /**\n     * The text content (for `input_text`).\n     */\n    text?: string;\n\n    /**\n     * Transcript of the audio (for `input_audio`). This is not sent to the model, but\n     * will be attached to the message item for reference.\n     */\n    transcript?: string;\n\n    /**\n     * The content type (`input_text`, `input_audio`, or `input_image`).\n     */\n    type?: 'input_text' | 'input_audio' | 'input_image';\n  }\n}\n\n/**\n * Details of the error.\n */\nexport interface RealtimeError {\n  /**\n   * A human-readable error message.\n   */\n  message: string;\n\n  /**\n   * The type of error (e.g., \"invalid_request_error\", \"server_error\").\n   */\n  type: string;\n\n  /**\n   * Error code, if any.\n   */\n  code?: string | null;\n\n  /**\n   * The event_id of the client event that caused the error, if applicable.\n   */\n  event_id?: string | null;\n\n  /**\n   * Parameter related to the error, if any.\n   */\n  param?: string | null;\n}\n\n/**\n * Returned when an error occurs, which could be a client problem or a server\n * problem. Most errors are recoverable and the session will stay open, we\n * recommend to implementors to monitor and log error messages by default.\n */\nexport interface RealtimeErrorEvent {\n  /**\n   * Details of the error.\n   */\n  error: RealtimeError;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The event type, must be `error`.\n   */\n  type: 'error';\n}\n\nexport interface RealtimeFunctionTool {\n  /**\n   * The description of the function, including guidance on when and how to call it,\n   * and guidance about what to tell the user when calling (if anything).\n   */\n  description?: string;\n\n  /**\n   * The name of the function.\n   */\n  name?: string;\n\n  /**\n   * Parameters of the function in JSON Schema.\n   */\n  parameters?: unknown;\n\n  /**\n   * The type of the tool, i.e. `function`.\n   */\n  type?: 'function';\n}\n\n/**\n * A Realtime item requesting human approval of a tool invocation.\n */\nexport interface RealtimeMcpApprovalRequest {\n  /**\n   * The unique ID of the approval request.\n   */\n  id: string;\n\n  /**\n   * A JSON string of arguments for the tool.\n   */\n  arguments: string;\n\n  /**\n   * The name of the tool to run.\n   */\n  name: string;\n\n  /**\n   * The label of the MCP server making the request.\n   */\n  server_label: string;\n\n  /**\n   * The type of the item. Always `mcp_approval_request`.\n   */\n  type: 'mcp_approval_request';\n}\n\n/**\n * A Realtime item responding to an MCP approval request.\n */\nexport interface RealtimeMcpApprovalResponse {\n  /**\n   * The unique ID of the approval response.\n   */\n  id: string;\n\n  /**\n   * The ID of the approval request being answered.\n   */\n  approval_request_id: string;\n\n  /**\n   * Whether the request was approved.\n   */\n  approve: boolean;\n\n  /**\n   * The type of the item. Always `mcp_approval_response`.\n   */\n  type: 'mcp_approval_response';\n\n  /**\n   * Optional reason for the decision.\n   */\n  reason?: string | null;\n}\n\n/**\n * A Realtime item listing tools available on an MCP server.\n */\nexport interface RealtimeMcpListTools {\n  /**\n   * The label of the MCP server.\n   */\n  server_label: string;\n\n  /**\n   * The tools available on the server.\n   */\n  tools: Array<RealtimeMcpListTools.Tool>;\n\n  /**\n   * The type of the item. Always `mcp_list_tools`.\n   */\n  type: 'mcp_list_tools';\n\n  /**\n   * The unique ID of the list.\n   */\n  id?: string;\n}\n\nexport namespace RealtimeMcpListTools {\n  /**\n   * A tool available on an MCP server.\n   */\n  export interface Tool {\n    /**\n     * The JSON schema describing the tool's input.\n     */\n    input_schema: unknown;\n\n    /**\n     * The name of the tool.\n     */\n    name: string;\n\n    /**\n     * Additional annotations about the tool.\n     */\n    annotations?: unknown | null;\n\n    /**\n     * The description of the tool.\n     */\n    description?: string | null;\n  }\n}\n\nexport interface RealtimeMcpProtocolError {\n  code: number;\n\n  message: string;\n\n  type: 'protocol_error';\n}\n\n/**\n * A Realtime item representing an invocation of a tool on an MCP server.\n */\nexport interface RealtimeMcpToolCall {\n  /**\n   * The unique ID of the tool call.\n   */\n  id: string;\n\n  /**\n   * A JSON string of the arguments passed to the tool.\n   */\n  arguments: string;\n\n  /**\n   * The name of the tool that was run.\n   */\n  name: string;\n\n  /**\n   * The label of the MCP server running the tool.\n   */\n  server_label: string;\n\n  /**\n   * The type of the item. Always `mcp_call`.\n   */\n  type: 'mcp_call';\n\n  /**\n   * The ID of an associated approval request, if any.\n   */\n  approval_request_id?: string | null;\n\n  /**\n   * The error from the tool call, if any.\n   */\n  error?: RealtimeMcpProtocolError | RealtimeMcpToolExecutionError | RealtimeMcphttpError | null;\n\n  /**\n   * The output from the tool call.\n   */\n  output?: string | null;\n}\n\nexport interface RealtimeMcpToolExecutionError {\n  message: string;\n\n  type: 'tool_execution_error';\n}\n\nexport interface RealtimeMcphttpError {\n  code: number;\n\n  message: string;\n\n  type: 'http_error';\n}\n\n/**\n * The response resource.\n */\nexport interface RealtimeResponse {\n  /**\n   * The unique ID of the response, will look like `resp_1234`.\n   */\n  id?: string;\n\n  /**\n   * Configuration for audio output.\n   */\n  audio?: RealtimeResponse.Audio;\n\n  /**\n   * Which conversation the response is added to, determined by the `conversation`\n   * field in the `response.create` event. If `auto`, the response will be added to\n   * the default conversation and the value of `conversation_id` will be an id like\n   * `conv_1234`. If `none`, the response will not be added to any conversation and\n   * the value of `conversation_id` will be `null`. If responses are being triggered\n   * automatically by VAD the response will be added to the default conversation\n   */\n  conversation_id?: string;\n\n  /**\n   * Maximum number of output tokens for a single assistant response, inclusive of\n   * tool calls, that was used in this response.\n   */\n  max_output_tokens?: number | 'inf';\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The object type, must be `realtime.response`.\n   */\n  object?: 'realtime.response';\n\n  /**\n   * The list of output items generated by the response.\n   */\n  output?: Array<ConversationItem>;\n\n  /**\n   * The set of modalities the model used to respond, currently the only possible\n   * values are `[\\\"audio\\\"]`, `[\\\"text\\\"]`. Audio output always include a text\n   * transcript. Setting the output to mode `text` will disable audio output from the\n   * model.\n   */\n  output_modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * The final status of the response (`completed`, `cancelled`, `failed`, or\n   * `incomplete`, `in_progress`).\n   */\n  status?: 'completed' | 'cancelled' | 'failed' | 'incomplete' | 'in_progress';\n\n  /**\n   * Additional details about the status.\n   */\n  status_details?: RealtimeResponseStatus;\n\n  /**\n   * Usage statistics for the Response, this will correspond to billing. A Realtime\n   * API session will maintain a conversation context and append new Items to the\n   * Conversation, thus output from previous turns (text and audio tokens) will\n   * become the input for later turns.\n   */\n  usage?: RealtimeResponseUsage;\n}\n\nexport namespace RealtimeResponse {\n  /**\n   * Configuration for audio output.\n   */\n  export interface Audio {\n    output?: Audio.Output;\n  }\n\n  export namespace Audio {\n    export interface Output {\n      /**\n       * The format of the output audio.\n       */\n      format?: RealtimeAPI.RealtimeAudioFormats;\n\n      /**\n       * The voice the model uses to respond. Voice cannot be changed during the session\n       * once the model has responded with audio at least once. Current voice options are\n       * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, `verse`, `marin`,\n       * and `cedar`. We recommend `marin` and `cedar` for best quality.\n       */\n      voice?:\n        | (string & {})\n        | 'alloy'\n        | 'ash'\n        | 'ballad'\n        | 'coral'\n        | 'echo'\n        | 'sage'\n        | 'shimmer'\n        | 'verse'\n        | 'marin'\n        | 'cedar';\n    }\n  }\n}\n\n/**\n * Configuration for audio input and output.\n */\nexport interface RealtimeResponseCreateAudioOutput {\n  output?: RealtimeResponseCreateAudioOutput.Output;\n}\n\nexport namespace RealtimeResponseCreateAudioOutput {\n  export interface Output {\n    /**\n     * The format of the output audio.\n     */\n    format?: RealtimeAPI.RealtimeAudioFormats;\n\n    /**\n     * The voice the model uses to respond. Supported built-in voices are `alloy`,\n     * `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, `verse`, `marin`, and\n     * `cedar`. You may also provide a custom voice object with an `id`, for example\n     * `{ \"id\": \"voice_1234\" }`. Voice cannot be changed during the session once the\n     * model has responded with audio at least once. We recommend `marin` and `cedar`\n     * for best quality.\n     */\n    voice?:\n      | string\n      | 'alloy'\n      | 'ash'\n      | 'ballad'\n      | 'coral'\n      | 'echo'\n      | 'sage'\n      | 'shimmer'\n      | 'verse'\n      | 'marin'\n      | 'cedar'\n      | Output.ID;\n  }\n\n  export namespace Output {\n    /**\n     * Custom voice reference.\n     */\n    export interface ID {\n      /**\n       * The custom voice ID, e.g. `voice_1234`.\n       */\n      id: string;\n    }\n  }\n}\n\n/**\n * Give the model access to additional tools via remote Model Context Protocol\n * (MCP) servers.\n * [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).\n */\nexport interface RealtimeResponseCreateMcpTool {\n  /**\n   * A label for this MCP server, used to identify it in tool calls.\n   */\n  server_label: string;\n\n  /**\n   * The type of the MCP tool. Always `mcp`.\n   */\n  type: 'mcp';\n\n  /**\n   * List of allowed tool names or a filter object.\n   */\n  allowed_tools?: Array<string> | RealtimeResponseCreateMcpTool.McpToolFilter | null;\n\n  /**\n   * An OAuth access token that can be used with a remote MCP server, either with a\n   * custom MCP server URL or a service connector. Your application must handle the\n   * OAuth authorization flow and provide the token here.\n   */\n  authorization?: string;\n\n  /**\n   * Identifier for service connectors, like those available in ChatGPT. One of\n   * `server_url` or `connector_id` must be provided. Learn more about service\n   * connectors\n   * [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).\n   *\n   * Currently supported `connector_id` values are:\n   *\n   * - Dropbox: `connector_dropbox`\n   * - Gmail: `connector_gmail`\n   * - Google Calendar: `connector_googlecalendar`\n   * - Google Drive: `connector_googledrive`\n   * - Microsoft Teams: `connector_microsoftteams`\n   * - Outlook Calendar: `connector_outlookcalendar`\n   * - Outlook Email: `connector_outlookemail`\n   * - SharePoint: `connector_sharepoint`\n   */\n  connector_id?:\n    | 'connector_dropbox'\n    | 'connector_gmail'\n    | 'connector_googlecalendar'\n    | 'connector_googledrive'\n    | 'connector_microsoftteams'\n    | 'connector_outlookcalendar'\n    | 'connector_outlookemail'\n    | 'connector_sharepoint';\n\n  /**\n   * Whether this MCP tool is deferred and discovered via tool search.\n   */\n  defer_loading?: boolean;\n\n  /**\n   * Optional HTTP headers to send to the MCP server. Use for authentication or other\n   * purposes.\n   */\n  headers?: { [key: string]: string } | null;\n\n  /**\n   * Specify which of the MCP server's tools require approval.\n   */\n  require_approval?: RealtimeResponseCreateMcpTool.McpToolApprovalFilter | 'always' | 'never' | null;\n\n  /**\n   * Optional description of the MCP server, used to provide more context.\n   */\n  server_description?: string;\n\n  /**\n   * The URL for the MCP server. One of `server_url` or `connector_id` must be\n   * provided.\n   */\n  server_url?: string;\n}\n\nexport namespace RealtimeResponseCreateMcpTool {\n  /**\n   * A filter object to specify which tools are allowed.\n   */\n  export interface McpToolFilter {\n    /**\n     * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n     * is\n     * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n     * it will match this filter.\n     */\n    read_only?: boolean;\n\n    /**\n     * List of allowed tool names.\n     */\n    tool_names?: Array<string>;\n  }\n\n  /**\n   * Specify which of the MCP server's tools require approval. Can be `always`,\n   * `never`, or a filter object associated with tools that require approval.\n   */\n  export interface McpToolApprovalFilter {\n    /**\n     * A filter object to specify which tools are allowed.\n     */\n    always?: McpToolApprovalFilter.Always;\n\n    /**\n     * A filter object to specify which tools are allowed.\n     */\n    never?: McpToolApprovalFilter.Never;\n  }\n\n  export namespace McpToolApprovalFilter {\n    /**\n     * A filter object to specify which tools are allowed.\n     */\n    export interface Always {\n      /**\n       * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n       * is\n       * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n       * it will match this filter.\n       */\n      read_only?: boolean;\n\n      /**\n       * List of allowed tool names.\n       */\n      tool_names?: Array<string>;\n    }\n\n    /**\n     * A filter object to specify which tools are allowed.\n     */\n    export interface Never {\n      /**\n       * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n       * is\n       * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n       * it will match this filter.\n       */\n      read_only?: boolean;\n\n      /**\n       * List of allowed tool names.\n       */\n      tool_names?: Array<string>;\n    }\n  }\n}\n\n/**\n * Create a new Realtime response with these parameters\n */\nexport interface RealtimeResponseCreateParams {\n  /**\n   * Configuration for audio input and output.\n   */\n  audio?: RealtimeResponseCreateAudioOutput;\n\n  /**\n   * Controls which conversation the response is added to. Currently supports `auto`\n   * and `none`, with `auto` as the default value. The `auto` value means that the\n   * contents of the response will be added to the default conversation. Set this to\n   * `none` to create an out-of-band response which will not add items to default\n   * conversation.\n   */\n  conversation?: (string & {}) | 'auto' | 'none';\n\n  /**\n   * Input items to include in the prompt for the model. Using this field creates a\n   * new context for this Response instead of using the default conversation. An\n   * empty array `[]` will clear the context for this Response. Note that this can\n   * include references to items that previously appeared in the session using their\n   * id.\n   */\n  input?: Array<ConversationItem>;\n\n  /**\n   * The default system instructions (i.e. system message) prepended to model calls.\n   * This field allows the client to guide the model on desired responses. The model\n   * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n   * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n   * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n   * instructions are not guaranteed to be followed by the model, but they provide\n   * guidance to the model on the desired behavior. Note that the server sets default\n   * instructions which will be used if this field is not set and are visible in the\n   * `session.created` event at the start of the session.\n   */\n  instructions?: string;\n\n  /**\n   * Maximum number of output tokens for a single assistant response, inclusive of\n   * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n   * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n   */\n  max_output_tokens?: number | 'inf';\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The set of modalities the model used to respond, currently the only possible\n   * values are `[\\\"audio\\\"]`, `[\\\"text\\\"]`. Audio output always include a text\n   * transcript. Setting the output to mode `text` will disable audio output from the\n   * model.\n   */\n  output_modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * Reference to a prompt template and its variables.\n   * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n   */\n  prompt?: ResponsesAPI.ResponsePrompt | null;\n\n  /**\n   * How the model chooses tools. Provide one of the string modes or force a specific\n   * function/MCP tool.\n   */\n  tool_choice?: ResponsesAPI.ToolChoiceOptions | ResponsesAPI.ToolChoiceFunction | ResponsesAPI.ToolChoiceMcp;\n\n  /**\n   * Tools available to the model.\n   */\n  tools?: Array<RealtimeFunctionTool | RealtimeResponseCreateMcpTool>;\n}\n\n/**\n * Additional details about the status.\n */\nexport interface RealtimeResponseStatus {\n  /**\n   * A description of the error that caused the response to fail, populated when the\n   * `status` is `failed`.\n   */\n  error?: RealtimeResponseStatus.Error;\n\n  /**\n   * The reason the Response did not complete. For a `cancelled` Response, one of\n   * `turn_detected` (the server VAD detected a new start of speech) or\n   * `client_cancelled` (the client sent a cancel event). For an `incomplete`\n   * Response, one of `max_output_tokens` or `content_filter` (the server-side safety\n   * filter activated and cut off the response).\n   */\n  reason?: 'turn_detected' | 'client_cancelled' | 'max_output_tokens' | 'content_filter';\n\n  /**\n   * The type of error that caused the response to fail, corresponding with the\n   * `status` field (`completed`, `cancelled`, `incomplete`, `failed`).\n   */\n  type?: 'completed' | 'cancelled' | 'incomplete' | 'failed';\n}\n\nexport namespace RealtimeResponseStatus {\n  /**\n   * A description of the error that caused the response to fail, populated when the\n   * `status` is `failed`.\n   */\n  export interface Error {\n    /**\n     * Error code, if any.\n     */\n    code?: string;\n\n    /**\n     * The type of error.\n     */\n    type?: string;\n  }\n}\n\n/**\n * Usage statistics for the Response, this will correspond to billing. A Realtime\n * API session will maintain a conversation context and append new Items to the\n * Conversation, thus output from previous turns (text and audio tokens) will\n * become the input for later turns.\n */\nexport interface RealtimeResponseUsage {\n  /**\n   * Details about the input tokens used in the Response. Cached tokens are tokens\n   * from previous turns in the conversation that are included as context for the\n   * current response. Cached tokens here are counted as a subset of input tokens,\n   * meaning input tokens will include cached and uncached tokens.\n   */\n  input_token_details?: RealtimeResponseUsageInputTokenDetails;\n\n  /**\n   * The number of input tokens used in the Response, including text and audio\n   * tokens.\n   */\n  input_tokens?: number;\n\n  /**\n   * Details about the output tokens used in the Response.\n   */\n  output_token_details?: RealtimeResponseUsageOutputTokenDetails;\n\n  /**\n   * The number of output tokens sent in the Response, including text and audio\n   * tokens.\n   */\n  output_tokens?: number;\n\n  /**\n   * The total number of tokens in the Response including input and output text and\n   * audio tokens.\n   */\n  total_tokens?: number;\n}\n\n/**\n * Details about the input tokens used in the Response. Cached tokens are tokens\n * from previous turns in the conversation that are included as context for the\n * current response. Cached tokens here are counted as a subset of input tokens,\n * meaning input tokens will include cached and uncached tokens.\n */\nexport interface RealtimeResponseUsageInputTokenDetails {\n  /**\n   * The number of audio tokens used as input for the Response.\n   */\n  audio_tokens?: number;\n\n  /**\n   * The number of cached tokens used as input for the Response.\n   */\n  cached_tokens?: number;\n\n  /**\n   * Details about the cached tokens used as input for the Response.\n   */\n  cached_tokens_details?: RealtimeResponseUsageInputTokenDetails.CachedTokensDetails;\n\n  /**\n   * The number of image tokens used as input for the Response.\n   */\n  image_tokens?: number;\n\n  /**\n   * The number of text tokens used as input for the Response.\n   */\n  text_tokens?: number;\n}\n\nexport namespace RealtimeResponseUsageInputTokenDetails {\n  /**\n   * Details about the cached tokens used as input for the Response.\n   */\n  export interface CachedTokensDetails {\n    /**\n     * The number of cached audio tokens used as input for the Response.\n     */\n    audio_tokens?: number;\n\n    /**\n     * The number of cached image tokens used as input for the Response.\n     */\n    image_tokens?: number;\n\n    /**\n     * The number of cached text tokens used as input for the Response.\n     */\n    text_tokens?: number;\n  }\n}\n\n/**\n * Details about the output tokens used in the Response.\n */\nexport interface RealtimeResponseUsageOutputTokenDetails {\n  /**\n   * The number of audio tokens used in the Response.\n   */\n  audio_tokens?: number;\n\n  /**\n   * The number of text tokens used in the Response.\n   */\n  text_tokens?: number;\n}\n\n/**\n * A realtime server event.\n */\nexport type RealtimeServerEvent =\n  | ConversationCreatedEvent\n  | ConversationItemCreatedEvent\n  | ConversationItemDeletedEvent\n  | ConversationItemInputAudioTranscriptionCompletedEvent\n  | ConversationItemInputAudioTranscriptionDeltaEvent\n  | ConversationItemInputAudioTranscriptionFailedEvent\n  | RealtimeServerEvent.ConversationItemRetrieved\n  | ConversationItemTruncatedEvent\n  | RealtimeErrorEvent\n  | InputAudioBufferClearedEvent\n  | InputAudioBufferCommittedEvent\n  | InputAudioBufferDtmfEventReceivedEvent\n  | InputAudioBufferSpeechStartedEvent\n  | InputAudioBufferSpeechStoppedEvent\n  | RateLimitsUpdatedEvent\n  | ResponseAudioDeltaEvent\n  | ResponseAudioDoneEvent\n  | ResponseAudioTranscriptDeltaEvent\n  | ResponseAudioTranscriptDoneEvent\n  | ResponseContentPartAddedEvent\n  | ResponseContentPartDoneEvent\n  | ResponseCreatedEvent\n  | ResponseDoneEvent\n  | ResponseFunctionCallArgumentsDeltaEvent\n  | ResponseFunctionCallArgumentsDoneEvent\n  | ResponseOutputItemAddedEvent\n  | ResponseOutputItemDoneEvent\n  | ResponseTextDeltaEvent\n  | ResponseTextDoneEvent\n  | SessionCreatedEvent\n  | SessionUpdatedEvent\n  | RealtimeServerEvent.OutputAudioBufferStarted\n  | RealtimeServerEvent.OutputAudioBufferStopped\n  | RealtimeServerEvent.OutputAudioBufferCleared\n  | ConversationItemAdded\n  | ConversationItemDone\n  | InputAudioBufferTimeoutTriggered\n  | ConversationItemInputAudioTranscriptionSegment\n  | McpListToolsInProgress\n  | McpListToolsCompleted\n  | McpListToolsFailed\n  | ResponseMcpCallArgumentsDelta\n  | ResponseMcpCallArgumentsDone\n  | ResponseMcpCallInProgress\n  | ResponseMcpCallCompleted\n  | ResponseMcpCallFailed;\n\nexport namespace RealtimeServerEvent {\n  /**\n   * Returned when a conversation item is retrieved with\n   * `conversation.item.retrieve`. This is provided as a way to fetch the server's\n   * representation of an item, for example to get access to the post-processed audio\n   * data after noise cancellation and VAD. It includes the full content of the Item,\n   * including audio data.\n   */\n  export interface ConversationItemRetrieved {\n    /**\n     * The unique ID of the server event.\n     */\n    event_id: string;\n\n    /**\n     * A single item within a Realtime conversation.\n     */\n    item: RealtimeAPI.ConversationItem;\n\n    /**\n     * The event type, must be `conversation.item.retrieved`.\n     */\n    type: 'conversation.item.retrieved';\n  }\n\n  /**\n   * **WebRTC/SIP Only:** Emitted when the server begins streaming audio to the\n   * client. This event is emitted after an audio content part has been added\n   * (`response.content_part.added`) to the response.\n   * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n   */\n  export interface OutputAudioBufferStarted {\n    /**\n     * The unique ID of the server event.\n     */\n    event_id: string;\n\n    /**\n     * The unique ID of the response that produced the audio.\n     */\n    response_id: string;\n\n    /**\n     * The event type, must be `output_audio_buffer.started`.\n     */\n    type: 'output_audio_buffer.started';\n  }\n\n  /**\n   * **WebRTC/SIP Only:** Emitted when the output audio buffer has been completely\n   * drained on the server, and no more audio is forthcoming. This event is emitted\n   * after the full response data has been sent to the client (`response.done`).\n   * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n   */\n  export interface OutputAudioBufferStopped {\n    /**\n     * The unique ID of the server event.\n     */\n    event_id: string;\n\n    /**\n     * The unique ID of the response that produced the audio.\n     */\n    response_id: string;\n\n    /**\n     * The event type, must be `output_audio_buffer.stopped`.\n     */\n    type: 'output_audio_buffer.stopped';\n  }\n\n  /**\n   * **WebRTC/SIP Only:** Emitted when the output audio buffer is cleared. This\n   * happens either in VAD mode when the user has interrupted\n   * (`input_audio_buffer.speech_started`), or when the client has emitted the\n   * `output_audio_buffer.clear` event to manually cut off the current audio\n   * response.\n   * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n   */\n  export interface OutputAudioBufferCleared {\n    /**\n     * The unique ID of the server event.\n     */\n    event_id: string;\n\n    /**\n     * The unique ID of the response that produced the audio.\n     */\n    response_id: string;\n\n    /**\n     * The event type, must be `output_audio_buffer.cleared`.\n     */\n    type: 'output_audio_buffer.cleared';\n  }\n}\n\n/**\n * Realtime session object for the beta interface.\n */\nexport interface RealtimeSession {\n  /**\n   * Unique identifier for the session that looks like `sess_1234567890abcdef`.\n   */\n  id?: string;\n\n  /**\n   * Expiration timestamp for the session, in seconds since epoch.\n   */\n  expires_at?: number;\n\n  /**\n   * Additional fields to include in server outputs.\n   *\n   * - `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n   *   transcription.\n   */\n  include?: Array<'item.input_audio_transcription.logprobs'> | null;\n\n  /**\n   * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n   * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n   * (mono), and little-endian byte order.\n   */\n  input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  input_audio_noise_reduction?: RealtimeSession.InputAudioNoiseReduction;\n\n  /**\n   * Configuration for input audio transcription, defaults to off and can be set to\n   * `null` to turn off once on. Input audio transcription is not native to the\n   * model, since the model consumes audio directly. Transcription runs\n   * asynchronously through\n   * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n   * and should be treated as guidance of input audio content rather than precisely\n   * what the model heard. The client can optionally set the language and prompt for\n   * transcription, these offer additional guidance to the transcription service.\n   */\n  input_audio_transcription?: AudioTranscription | null;\n\n  /**\n   * The default system instructions (i.e. system message) prepended to model calls.\n   * This field allows the client to guide the model on desired responses. The model\n   * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n   * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n   * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n   * instructions are not guaranteed to be followed by the model, but they provide\n   * guidance to the model on the desired behavior.\n   *\n   * Note that the server sets default instructions which will be used if this field\n   * is not set and are visible in the `session.created` event at the start of the\n   * session.\n   */\n  instructions?: string;\n\n  /**\n   * Maximum number of output tokens for a single assistant response, inclusive of\n   * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n   * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n   */\n  max_response_output_tokens?: number | 'inf';\n\n  /**\n   * The set of modalities the model can respond with. To disable audio, set this to\n   * [\"text\"].\n   */\n  modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * The Realtime model used for this session.\n   */\n  model?:\n    | (string & {})\n    | 'gpt-realtime'\n    | 'gpt-realtime-1.5'\n    | 'gpt-realtime-2025-08-28'\n    | 'gpt-4o-realtime-preview'\n    | 'gpt-4o-realtime-preview-2024-10-01'\n    | 'gpt-4o-realtime-preview-2024-12-17'\n    | 'gpt-4o-realtime-preview-2025-06-03'\n    | 'gpt-4o-mini-realtime-preview'\n    | 'gpt-4o-mini-realtime-preview-2024-12-17'\n    | 'gpt-realtime-mini'\n    | 'gpt-realtime-mini-2025-10-06'\n    | 'gpt-realtime-mini-2025-12-15'\n    | 'gpt-audio-1.5'\n    | 'gpt-audio-mini'\n    | 'gpt-audio-mini-2025-10-06'\n    | 'gpt-audio-mini-2025-12-15';\n\n  /**\n   * The object type. Always `realtime.session`.\n   */\n  object?: 'realtime.session';\n\n  /**\n   * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n   * For `pcm16`, output audio is sampled at a rate of 24kHz.\n   */\n  output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n  /**\n   * Reference to a prompt template and its variables.\n   * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n   */\n  prompt?: ResponsesAPI.ResponsePrompt | null;\n\n  /**\n   * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the\n   * minimum speed. 1.5 is the maximum speed. This value can only be changed in\n   * between model turns, not while a response is in progress.\n   */\n  speed?: number;\n\n  /**\n   * Sampling temperature for the model, limited to [0.6, 1.2]. For audio models a\n   * temperature of 0.8 is highly recommended for best performance.\n   */\n  temperature?: number;\n\n  /**\n   * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n   * a function.\n   */\n  tool_choice?: string;\n\n  /**\n   * Tools (functions) available to the model.\n   */\n  tools?: Array<RealtimeFunctionTool>;\n\n  /**\n   * Configuration options for tracing. Set to null to disable tracing. Once tracing\n   * is enabled for a session, the configuration cannot be modified.\n   *\n   * `auto` will create a trace for the session with default values for the workflow\n   * name, group id, and metadata.\n   */\n  tracing?: 'auto' | RealtimeSession.TracingConfiguration | null;\n\n  /**\n   * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n   * set to `null` to turn off, in which case the client must manually trigger model\n   * response.\n   *\n   * Server VAD means that the model will detect the start and end of speech based on\n   * audio volume and respond at the end of user speech.\n   *\n   * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n   * with VAD) to semantically estimate whether the user has finished speaking, then\n   * dynamically sets a timeout based on this probability. For example, if user audio\n   * trails off with \"uhhm\", the model will score a low probability of turn end and\n   * wait longer for the user to continue speaking. This can be useful for more\n   * natural conversations, but may have a higher latency.\n   */\n  turn_detection?: RealtimeSession.ServerVad | RealtimeSession.SemanticVad | null;\n\n  /**\n   * The voice the model uses to respond. Voice cannot be changed during the session\n   * once the model has responded with audio at least once. Current voice options are\n   * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n   */\n  voice?:\n    | (string & {})\n    | 'alloy'\n    | 'ash'\n    | 'ballad'\n    | 'coral'\n    | 'echo'\n    | 'sage'\n    | 'shimmer'\n    | 'verse'\n    | 'marin'\n    | 'cedar';\n}\n\nexport namespace RealtimeSession {\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  export interface InputAudioNoiseReduction {\n    /**\n     * Type of noise reduction. `near_field` is for close-talking microphones such as\n     * headphones, `far_field` is for far-field microphones such as laptop or\n     * conference room microphones.\n     */\n    type?: RealtimeAPI.NoiseReductionType;\n  }\n\n  /**\n   * Granular configuration for tracing.\n   */\n  export interface TracingConfiguration {\n    /**\n     * The group id to attach to this trace to enable filtering and grouping in the\n     * traces dashboard.\n     */\n    group_id?: string;\n\n    /**\n     * The arbitrary metadata to attach to this trace to enable filtering in the traces\n     * dashboard.\n     */\n    metadata?: unknown;\n\n    /**\n     * The name of the workflow to attach to this trace. This is used to name the trace\n     * in the traces dashboard.\n     */\n    workflow_name?: string;\n  }\n\n  /**\n   * Server-side voice activity detection (VAD) which flips on when user speech is\n   * detected and off after a period of silence.\n   */\n  export interface ServerVad {\n    /**\n     * Type of turn detection, `server_vad` to turn on simple Server VAD.\n     */\n    type: 'server_vad';\n\n    /**\n     * Whether or not to automatically generate a response when a VAD stop event\n     * occurs. If `interrupt_response` is set to `false` this may fail to create a\n     * response if the model is already responding.\n     *\n     * If both `create_response` and `interrupt_response` are set to `false`, the model\n     * will never respond automatically but VAD events will still be emitted.\n     */\n    create_response?: boolean;\n\n    /**\n     * Optional timeout after which a model response will be triggered automatically.\n     * This is useful for situations in which a long pause from the user is unexpected,\n     * such as a phone call. The model will effectively prompt the user to continue the\n     * conversation based on the current context.\n     *\n     * The timeout value will be applied after the last model response's audio has\n     * finished playing, i.e. it's set to the `response.done` time plus audio playback\n     * duration.\n     *\n     * An `input_audio_buffer.timeout_triggered` event (plus events associated with the\n     * Response) will be emitted when the timeout is reached. Idle timeout is currently\n     * only supported for `server_vad` mode.\n     */\n    idle_timeout_ms?: number | null;\n\n    /**\n     * Whether or not to automatically interrupt (cancel) any ongoing response with\n     * output to the default conversation (i.e. `conversation` of `auto`) when a VAD\n     * start event occurs. If `true` then the response will be cancelled, otherwise it\n     * will continue until complete.\n     *\n     * If both `create_response` and `interrupt_response` are set to `false`, the model\n     * will never respond automatically but VAD events will still be emitted.\n     */\n    interrupt_response?: boolean;\n\n    /**\n     * Used only for `server_vad` mode. Amount of audio to include before the VAD\n     * detected speech (in milliseconds). Defaults to 300ms.\n     */\n    prefix_padding_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n     * milliseconds). Defaults to 500ms. With shorter values the model will respond\n     * more quickly, but may jump in on short pauses from the user.\n     */\n    silence_duration_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n     * defaults to 0.5. A higher threshold will require louder audio to activate the\n     * model, and thus might perform better in noisy environments.\n     */\n    threshold?: number;\n  }\n\n  /**\n   * Server-side semantic turn detection which uses a model to determine when the\n   * user has finished speaking.\n   */\n  export interface SemanticVad {\n    /**\n     * Type of turn detection, `semantic_vad` to turn on Semantic VAD.\n     */\n    type: 'semantic_vad';\n\n    /**\n     * Whether or not to automatically generate a response when a VAD stop event\n     * occurs.\n     */\n    create_response?: boolean;\n\n    /**\n     * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n     * will wait longer for the user to continue speaking, `high` will respond more\n     * quickly. `auto` is the default and is equivalent to `medium`. `low`, `medium`,\n     * and `high` have max timeouts of 8s, 4s, and 2s respectively.\n     */\n    eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n    /**\n     * Whether or not to automatically interrupt any ongoing response with output to\n     * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n     * occurs.\n     */\n    interrupt_response?: boolean;\n  }\n}\n\n/**\n * Realtime session object configuration.\n */\nexport interface RealtimeSessionCreateRequest {\n  /**\n   * The type of session to create. Always `realtime` for the Realtime API.\n   */\n  type: 'realtime';\n\n  /**\n   * Configuration for input and output audio.\n   */\n  audio?: RealtimeAudioConfig;\n\n  /**\n   * Additional fields to include in server outputs.\n   *\n   * `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n   * transcription.\n   */\n  include?: Array<'item.input_audio_transcription.logprobs'>;\n\n  /**\n   * The default system instructions (i.e. system message) prepended to model calls.\n   * This field allows the client to guide the model on desired responses. The model\n   * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n   * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n   * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n   * instructions are not guaranteed to be followed by the model, but they provide\n   * guidance to the model on the desired behavior.\n   *\n   * Note that the server sets default instructions which will be used if this field\n   * is not set and are visible in the `session.created` event at the start of the\n   * session.\n   */\n  instructions?: string;\n\n  /**\n   * Maximum number of output tokens for a single assistant response, inclusive of\n   * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n   * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n   */\n  max_output_tokens?: number | 'inf';\n\n  /**\n   * The Realtime model used for this session.\n   */\n  model?:\n    | (string & {})\n    | 'gpt-realtime'\n    | 'gpt-realtime-1.5'\n    | 'gpt-realtime-2025-08-28'\n    | 'gpt-4o-realtime-preview'\n    | 'gpt-4o-realtime-preview-2024-10-01'\n    | 'gpt-4o-realtime-preview-2024-12-17'\n    | 'gpt-4o-realtime-preview-2025-06-03'\n    | 'gpt-4o-mini-realtime-preview'\n    | 'gpt-4o-mini-realtime-preview-2024-12-17'\n    | 'gpt-realtime-mini'\n    | 'gpt-realtime-mini-2025-10-06'\n    | 'gpt-realtime-mini-2025-12-15'\n    | 'gpt-audio-1.5'\n    | 'gpt-audio-mini'\n    | 'gpt-audio-mini-2025-10-06'\n    | 'gpt-audio-mini-2025-12-15';\n\n  /**\n   * The set of modalities the model can respond with. It defaults to `[\"audio\"]`,\n   * indicating that the model will respond with audio plus a transcript. `[\"text\"]`\n   * can be used to make the model respond with text only. It is not possible to\n   * request both `text` and `audio` at the same time.\n   */\n  output_modalities?: Array<'text' | 'audio'>;\n\n  /**\n   * Reference to a prompt template and its variables.\n   * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n   */\n  prompt?: ResponsesAPI.ResponsePrompt | null;\n\n  /**\n   * How the model chooses tools. Provide one of the string modes or force a specific\n   * function/MCP tool.\n   */\n  tool_choice?: RealtimeToolChoiceConfig;\n\n  /**\n   * Tools available to the model.\n   */\n  tools?: RealtimeToolsConfig;\n\n  /**\n   * Realtime API can write session traces to the\n   * [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once\n   * tracing is enabled for a session, the configuration cannot be modified.\n   *\n   * `auto` will create a trace for the session with default values for the workflow\n   * name, group id, and metadata.\n   */\n  tracing?: RealtimeTracingConfig | null;\n\n  /**\n   * When the number of tokens in a conversation exceeds the model's input token\n   * limit, the conversation be truncated, meaning messages (starting from the\n   * oldest) will not be included in the model's context. A 32k context model with\n   * 4,096 max output tokens can only include 28,224 tokens in the context before\n   * truncation occurs.\n   *\n   * Clients can configure truncation behavior to truncate with a lower max token\n   * limit, which is an effective way to control token usage and cost.\n   *\n   * Truncation will reduce the number of cached tokens on the next turn (busting the\n   * cache), since messages are dropped from the beginning of the context. However,\n   * clients can also configure truncation to retain messages up to a fraction of the\n   * maximum context size, which will reduce the need for future truncations and thus\n   * improve the cache rate.\n   *\n   * Truncation can be disabled entirely, which means the server will never truncate\n   * but would instead return an error if the conversation exceeds the model's input\n   * token limit.\n   */\n  truncation?: RealtimeTruncation;\n}\n\n/**\n * How the model chooses tools. Provide one of the string modes or force a specific\n * function/MCP tool.\n */\nexport type RealtimeToolChoiceConfig =\n  | ResponsesAPI.ToolChoiceOptions\n  | ResponsesAPI.ToolChoiceFunction\n  | ResponsesAPI.ToolChoiceMcp;\n\n/**\n * Tools available to the model.\n */\nexport type RealtimeToolsConfig = Array<RealtimeToolsConfigUnion>;\n\n/**\n * Give the model access to additional tools via remote Model Context Protocol\n * (MCP) servers.\n * [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).\n */\nexport type RealtimeToolsConfigUnion = RealtimeFunctionTool | RealtimeToolsConfigUnion.Mcp;\n\nexport namespace RealtimeToolsConfigUnion {\n  /**\n   * Give the model access to additional tools via remote Model Context Protocol\n   * (MCP) servers.\n   * [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).\n   */\n  export interface Mcp {\n    /**\n     * A label for this MCP server, used to identify it in tool calls.\n     */\n    server_label: string;\n\n    /**\n     * The type of the MCP tool. Always `mcp`.\n     */\n    type: 'mcp';\n\n    /**\n     * List of allowed tool names or a filter object.\n     */\n    allowed_tools?: Array<string> | Mcp.McpToolFilter | null;\n\n    /**\n     * An OAuth access token that can be used with a remote MCP server, either with a\n     * custom MCP server URL or a service connector. Your application must handle the\n     * OAuth authorization flow and provide the token here.\n     */\n    authorization?: string;\n\n    /**\n     * Identifier for service connectors, like those available in ChatGPT. One of\n     * `server_url` or `connector_id` must be provided. Learn more about service\n     * connectors\n     * [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).\n     *\n     * Currently supported `connector_id` values are:\n     *\n     * - Dropbox: `connector_dropbox`\n     * - Gmail: `connector_gmail`\n     * - Google Calendar: `connector_googlecalendar`\n     * - Google Drive: `connector_googledrive`\n     * - Microsoft Teams: `connector_microsoftteams`\n     * - Outlook Calendar: `connector_outlookcalendar`\n     * - Outlook Email: `connector_outlookemail`\n     * - SharePoint: `connector_sharepoint`\n     */\n    connector_id?:\n      | 'connector_dropbox'\n      | 'connector_gmail'\n      | 'connector_googlecalendar'\n      | 'connector_googledrive'\n      | 'connector_microsoftteams'\n      | 'connector_outlookcalendar'\n      | 'connector_outlookemail'\n      | 'connector_sharepoint';\n\n    /**\n     * Whether this MCP tool is deferred and discovered via tool search.\n     */\n    defer_loading?: boolean;\n\n    /**\n     * Optional HTTP headers to send to the MCP server. Use for authentication or other\n     * purposes.\n     */\n    headers?: { [key: string]: string } | null;\n\n    /**\n     * Specify which of the MCP server's tools require approval.\n     */\n    require_approval?: Mcp.McpToolApprovalFilter | 'always' | 'never' | null;\n\n    /**\n     * Optional description of the MCP server, used to provide more context.\n     */\n    server_description?: string;\n\n    /**\n     * The URL for the MCP server. One of `server_url` or `connector_id` must be\n     * provided.\n     */\n    server_url?: string;\n  }\n\n  export namespace Mcp {\n    /**\n     * A filter object to specify which tools are allowed.\n     */\n    export interface McpToolFilter {\n      /**\n       * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n       * is\n       * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n       * it will match this filter.\n       */\n      read_only?: boolean;\n\n      /**\n       * List of allowed tool names.\n       */\n      tool_names?: Array<string>;\n    }\n\n    /**\n     * Specify which of the MCP server's tools require approval. Can be `always`,\n     * `never`, or a filter object associated with tools that require approval.\n     */\n    export interface McpToolApprovalFilter {\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      always?: McpToolApprovalFilter.Always;\n\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      never?: McpToolApprovalFilter.Never;\n    }\n\n    export namespace McpToolApprovalFilter {\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      export interface Always {\n        /**\n         * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n         * is\n         * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n         * it will match this filter.\n         */\n        read_only?: boolean;\n\n        /**\n         * List of allowed tool names.\n         */\n        tool_names?: Array<string>;\n      }\n\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      export interface Never {\n        /**\n         * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n         * is\n         * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n         * it will match this filter.\n         */\n        read_only?: boolean;\n\n        /**\n         * List of allowed tool names.\n         */\n        tool_names?: Array<string>;\n      }\n    }\n  }\n}\n\n/**\n * Realtime API can write session traces to the\n * [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once\n * tracing is enabled for a session, the configuration cannot be modified.\n *\n * `auto` will create a trace for the session with default values for the workflow\n * name, group id, and metadata.\n */\nexport type RealtimeTracingConfig = 'auto' | RealtimeTracingConfig.TracingConfiguration;\n\nexport namespace RealtimeTracingConfig {\n  /**\n   * Granular configuration for tracing.\n   */\n  export interface TracingConfiguration {\n    /**\n     * The group id to attach to this trace to enable filtering and grouping in the\n     * Traces Dashboard.\n     */\n    group_id?: string;\n\n    /**\n     * The arbitrary metadata to attach to this trace to enable filtering in the Traces\n     * Dashboard.\n     */\n    metadata?: unknown;\n\n    /**\n     * The name of the workflow to attach to this trace. This is used to name the trace\n     * in the Traces Dashboard.\n     */\n    workflow_name?: string;\n  }\n}\n\n/**\n * Configuration for input and output audio.\n */\nexport interface RealtimeTranscriptionSessionAudio {\n  input?: RealtimeTranscriptionSessionAudioInput;\n}\n\nexport interface RealtimeTranscriptionSessionAudioInput {\n  /**\n   * The PCM audio format. Only a 24kHz sample rate is supported.\n   */\n  format?: RealtimeAudioFormats;\n\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  noise_reduction?: RealtimeTranscriptionSessionAudioInput.NoiseReduction;\n\n  /**\n   * Configuration for input audio transcription, defaults to off and can be set to\n   * `null` to turn off once on. Input audio transcription is not native to the\n   * model, since the model consumes audio directly. Transcription runs\n   * asynchronously through\n   * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n   * and should be treated as guidance of input audio content rather than precisely\n   * what the model heard. The client can optionally set the language and prompt for\n   * transcription, these offer additional guidance to the transcription service.\n   */\n  transcription?: AudioTranscription;\n\n  /**\n   * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n   * set to `null` to turn off, in which case the client must manually trigger model\n   * response.\n   *\n   * Server VAD means that the model will detect the start and end of speech based on\n   * audio volume and respond at the end of user speech.\n   *\n   * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n   * with VAD) to semantically estimate whether the user has finished speaking, then\n   * dynamically sets a timeout based on this probability. For example, if user audio\n   * trails off with \"uhhm\", the model will score a low probability of turn end and\n   * wait longer for the user to continue speaking. This can be useful for more\n   * natural conversations, but may have a higher latency.\n   */\n  turn_detection?: RealtimeTranscriptionSessionAudioInputTurnDetection | null;\n}\n\nexport namespace RealtimeTranscriptionSessionAudioInput {\n  /**\n   * Configuration for input audio noise reduction. This can be set to `null` to turn\n   * off. Noise reduction filters audio added to the input audio buffer before it is\n   * sent to VAD and the model. Filtering the audio can improve VAD and turn\n   * detection accuracy (reducing false positives) and model performance by improving\n   * perception of the input audio.\n   */\n  export interface NoiseReduction {\n    /**\n     * Type of noise reduction. `near_field` is for close-talking microphones such as\n     * headphones, `far_field` is for far-field microphones such as laptop or\n     * conference room microphones.\n     */\n    type?: RealtimeAPI.NoiseReductionType;\n  }\n}\n\n/**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response.\n *\n * Server VAD means that the model will detect the start and end of speech based on\n * audio volume and respond at the end of user speech.\n *\n * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n * with VAD) to semantically estimate whether the user has finished speaking, then\n * dynamically sets a timeout based on this probability. For example, if user audio\n * trails off with \"uhhm\", the model will score a low probability of turn end and\n * wait longer for the user to continue speaking. This can be useful for more\n * natural conversations, but may have a higher latency.\n */\nexport type RealtimeTranscriptionSessionAudioInputTurnDetection =\n  | RealtimeTranscriptionSessionAudioInputTurnDetection.ServerVad\n  | RealtimeTranscriptionSessionAudioInputTurnDetection.SemanticVad;\n\nexport namespace RealtimeTranscriptionSessionAudioInputTurnDetection {\n  /**\n   * Server-side voice activity detection (VAD) which flips on when user speech is\n   * detected and off after a period of silence.\n   */\n  export interface ServerVad {\n    /**\n     * Type of turn detection, `server_vad` to turn on simple Server VAD.\n     */\n    type: 'server_vad';\n\n    /**\n     * Whether or not to automatically generate a response when a VAD stop event\n     * occurs. If `interrupt_response` is set to `false` this may fail to create a\n     * response if the model is already responding.\n     *\n     * If both `create_response` and `interrupt_response` are set to `false`, the model\n     * will never respond automatically but VAD events will still be emitted.\n     */\n    create_response?: boolean;\n\n    /**\n     * Optional timeout after which a model response will be triggered automatically.\n     * This is useful for situations in which a long pause from the user is unexpected,\n     * such as a phone call. The model will effectively prompt the user to continue the\n     * conversation based on the current context.\n     *\n     * The timeout value will be applied after the last model response's audio has\n     * finished playing, i.e. it's set to the `response.done` time plus audio playback\n     * duration.\n     *\n     * An `input_audio_buffer.timeout_triggered` event (plus events associated with the\n     * Response) will be emitted when the timeout is reached. Idle timeout is currently\n     * only supported for `server_vad` mode.\n     */\n    idle_timeout_ms?: number | null;\n\n    /**\n     * Whether or not to automatically interrupt (cancel) any ongoing response with\n     * output to the default conversation (i.e. `conversation` of `auto`) when a VAD\n     * start event occurs. If `true` then the response will be cancelled, otherwise it\n     * will continue until complete.\n     *\n     * If both `create_response` and `interrupt_response` are set to `false`, the model\n     * will never respond automatically but VAD events will still be emitted.\n     */\n    interrupt_response?: boolean;\n\n    /**\n     * Used only for `server_vad` mode. Amount of audio to include before the VAD\n     * detected speech (in milliseconds). Defaults to 300ms.\n     */\n    prefix_padding_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n     * milliseconds). Defaults to 500ms. With shorter values the model will respond\n     * more quickly, but may jump in on short pauses from the user.\n     */\n    silence_duration_ms?: number;\n\n    /**\n     * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n     * defaults to 0.5. A higher threshold will require louder audio to activate the\n     * model, and thus might perform better in noisy environments.\n     */\n    threshold?: number;\n  }\n\n  /**\n   * Server-side semantic turn detection which uses a model to determine when the\n   * user has finished speaking.\n   */\n  export interface SemanticVad {\n    /**\n     * Type of turn detection, `semantic_vad` to turn on Semantic VAD.\n     */\n    type: 'semantic_vad';\n\n    /**\n     * Whether or not to automatically generate a response when a VAD stop event\n     * occurs.\n     */\n    create_response?: boolean;\n\n    /**\n     * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n     * will wait longer for the user to continue speaking, `high` will respond more\n     * quickly. `auto` is the default and is equivalent to `medium`. `low`, `medium`,\n     * and `high` have max timeouts of 8s, 4s, and 2s respectively.\n     */\n    eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n    /**\n     * Whether or not to automatically interrupt any ongoing response with output to\n     * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n     * occurs.\n     */\n    interrupt_response?: boolean;\n  }\n}\n\n/**\n * Realtime transcription session object configuration.\n */\nexport interface RealtimeTranscriptionSessionCreateRequest {\n  /**\n   * The type of session to create. Always `transcription` for transcription\n   * sessions.\n   */\n  type: 'transcription';\n\n  /**\n   * Configuration for input and output audio.\n   */\n  audio?: RealtimeTranscriptionSessionAudio;\n\n  /**\n   * Additional fields to include in server outputs.\n   *\n   * `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n   * transcription.\n   */\n  include?: Array<'item.input_audio_transcription.logprobs'>;\n}\n\n/**\n * When the number of tokens in a conversation exceeds the model's input token\n * limit, the conversation be truncated, meaning messages (starting from the\n * oldest) will not be included in the model's context. A 32k context model with\n * 4,096 max output tokens can only include 28,224 tokens in the context before\n * truncation occurs.\n *\n * Clients can configure truncation behavior to truncate with a lower max token\n * limit, which is an effective way to control token usage and cost.\n *\n * Truncation will reduce the number of cached tokens on the next turn (busting the\n * cache), since messages are dropped from the beginning of the context. However,\n * clients can also configure truncation to retain messages up to a fraction of the\n * maximum context size, which will reduce the need for future truncations and thus\n * improve the cache rate.\n *\n * Truncation can be disabled entirely, which means the server will never truncate\n * but would instead return an error if the conversation exceeds the model's input\n * token limit.\n */\nexport type RealtimeTruncation = 'auto' | 'disabled' | RealtimeTruncationRetentionRatio;\n\n/**\n * Retain a fraction of the conversation tokens when the conversation exceeds the\n * input token limit. This allows you to amortize truncations across multiple\n * turns, which can help improve cached token usage.\n */\nexport interface RealtimeTruncationRetentionRatio {\n  /**\n   * Fraction of post-instruction conversation tokens to retain (`0.0` - `1.0`) when\n   * the conversation exceeds the input token limit. Setting this to `0.8` means that\n   * messages will be dropped until 80% of the maximum allowed tokens are used. This\n   * helps reduce the frequency of truncations and improve cache rates.\n   */\n  retention_ratio: number;\n\n  /**\n   * Use retention ratio truncation.\n   */\n  type: 'retention_ratio';\n\n  /**\n   * Optional custom token limits for this truncation strategy. If not provided, the\n   * model's default token limits will be used.\n   */\n  token_limits?: RealtimeTruncationRetentionRatio.TokenLimits;\n}\n\nexport namespace RealtimeTruncationRetentionRatio {\n  /**\n   * Optional custom token limits for this truncation strategy. If not provided, the\n   * model's default token limits will be used.\n   */\n  export interface TokenLimits {\n    /**\n     * Maximum tokens allowed in the conversation after instructions (which including\n     * tool definitions). For example, setting this to 5,000 would mean that truncation\n     * would occur when the conversation exceeds 5,000 tokens after instructions. This\n     * cannot be higher than the model's context window size minus the maximum output\n     * tokens.\n     */\n    post_instructions?: number;\n  }\n}\n\n/**\n * Returned when the model-generated audio is updated.\n */\nexport interface ResponseAudioDeltaEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * Base64-encoded audio data delta.\n   */\n  delta: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.output_audio.delta`.\n   */\n  type: 'response.output_audio.delta';\n}\n\n/**\n * Returned when the model-generated audio is done. Also emitted when a Response is\n * interrupted, incomplete, or cancelled.\n */\nexport interface ResponseAudioDoneEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.output_audio.done`.\n   */\n  type: 'response.output_audio.done';\n}\n\n/**\n * Returned when the model-generated transcription of audio output is updated.\n */\nexport interface ResponseAudioTranscriptDeltaEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The transcript delta.\n   */\n  delta: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.output_audio_transcript.delta`.\n   */\n  type: 'response.output_audio_transcript.delta';\n}\n\n/**\n * Returned when the model-generated transcription of audio output is done\n * streaming. Also emitted when a Response is interrupted, incomplete, or\n * cancelled.\n */\nexport interface ResponseAudioTranscriptDoneEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The final transcript of the audio.\n   */\n  transcript: string;\n\n  /**\n   * The event type, must be `response.output_audio_transcript.done`.\n   */\n  type: 'response.output_audio_transcript.done';\n}\n\n/**\n * Send this event to cancel an in-progress response. The server will respond with\n * a `response.done` event with a status of `response.status=cancelled`. If there\n * is no response to cancel, the server will respond with an error. It's safe to\n * call `response.cancel` even if no response is in progress, an error will be\n * returned the session will remain unaffected.\n */\nexport interface ResponseCancelEvent {\n  /**\n   * The event type, must be `response.cancel`.\n   */\n  type: 'response.cancel';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n\n  /**\n   * A specific response ID to cancel - if not provided, will cancel an in-progress\n   * response in the default conversation.\n   */\n  response_id?: string;\n}\n\n/**\n * Returned when a new content part is added to an assistant message item during\n * response generation.\n */\nexport interface ResponseContentPartAddedEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item to which the content part was added.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The content part that was added.\n   */\n  part: ResponseContentPartAddedEvent.Part;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.content_part.added`.\n   */\n  type: 'response.content_part.added';\n}\n\nexport namespace ResponseContentPartAddedEvent {\n  /**\n   * The content part that was added.\n   */\n  export interface Part {\n    /**\n     * Base64-encoded audio data (if type is \"audio\").\n     */\n    audio?: string;\n\n    /**\n     * The text content (if type is \"text\").\n     */\n    text?: string;\n\n    /**\n     * The transcript of the audio (if type is \"audio\").\n     */\n    transcript?: string;\n\n    /**\n     * The content type (\"text\", \"audio\").\n     */\n    type?: 'text' | 'audio';\n  }\n}\n\n/**\n * Returned when a content part is done streaming in an assistant message item.\n * Also emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseContentPartDoneEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The content part that is done.\n   */\n  part: ResponseContentPartDoneEvent.Part;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.content_part.done`.\n   */\n  type: 'response.content_part.done';\n}\n\nexport namespace ResponseContentPartDoneEvent {\n  /**\n   * The content part that is done.\n   */\n  export interface Part {\n    /**\n     * Base64-encoded audio data (if type is \"audio\").\n     */\n    audio?: string;\n\n    /**\n     * The text content (if type is \"text\").\n     */\n    text?: string;\n\n    /**\n     * The transcript of the audio (if type is \"audio\").\n     */\n    transcript?: string;\n\n    /**\n     * The content type (\"text\", \"audio\").\n     */\n    type?: 'text' | 'audio';\n  }\n}\n\n/**\n * This event instructs the server to create a Response, which means triggering\n * model inference. When in Server VAD mode, the server will create Responses\n * automatically.\n *\n * A Response will include at least one Item, and may have two, in which case the\n * second will be a function call. These Items will be appended to the conversation\n * history by default.\n *\n * The server will respond with a `response.created` event, events for Items and\n * content created, and finally a `response.done` event to indicate the Response is\n * complete.\n *\n * The `response.create` event includes inference configuration like `instructions`\n * and `tools`. If these are set, they will override the Session's configuration\n * for this Response only.\n *\n * Responses can be created out-of-band of the default Conversation, meaning that\n * they can have arbitrary input, and it's possible to disable writing the output\n * to the Conversation. Only one Response can write to the default Conversation at\n * a time, but otherwise multiple Responses can be created in parallel. The\n * `metadata` field is a good way to disambiguate multiple simultaneous Responses.\n *\n * Clients can set `conversation` to `none` to create a Response that does not\n * write to the default Conversation. Arbitrary input can be provided with the\n * `input` field, which is an array accepting raw Items and references to existing\n * Items.\n */\nexport interface ResponseCreateEvent {\n  /**\n   * The event type, must be `response.create`.\n   */\n  type: 'response.create';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n\n  /**\n   * Create a new Realtime response with these parameters\n   */\n  response?: RealtimeResponseCreateParams;\n}\n\n/**\n * Returned when a new Response is created. The first event of response creation,\n * where the response is in an initial state of `in_progress`.\n */\nexport interface ResponseCreatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The response resource.\n   */\n  response: RealtimeResponse;\n\n  /**\n   * The event type, must be `response.created`.\n   */\n  type: 'response.created';\n}\n\n/**\n * Returned when a Response is done streaming. Always emitted, no matter the final\n * state. The Response object included in the `response.done` event will include\n * all output Items in the Response but will omit the raw audio data.\n *\n * Clients should check the `status` field of the Response to determine if it was\n * successful (`completed`) or if there was another outcome: `cancelled`, `failed`,\n * or `incomplete`.\n *\n * A response will contain all output items that were generated during the\n * response, excluding any audio content.\n */\nexport interface ResponseDoneEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The response resource.\n   */\n  response: RealtimeResponse;\n\n  /**\n   * The event type, must be `response.done`.\n   */\n  type: 'response.done';\n}\n\n/**\n * Returned when the model-generated function call arguments are updated.\n */\nexport interface ResponseFunctionCallArgumentsDeltaEvent {\n  /**\n   * The ID of the function call.\n   */\n  call_id: string;\n\n  /**\n   * The arguments delta as a JSON string.\n   */\n  delta: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the function call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.function_call_arguments.delta`.\n   */\n  type: 'response.function_call_arguments.delta';\n}\n\n/**\n * Returned when the model-generated function call arguments are done streaming.\n * Also emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseFunctionCallArgumentsDoneEvent {\n  /**\n   * The final arguments as a JSON string.\n   */\n  arguments: string;\n\n  /**\n   * The ID of the function call.\n   */\n  call_id: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the function call item.\n   */\n  item_id: string;\n\n  /**\n   * The name of the function that was called.\n   */\n  name: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.function_call_arguments.done`.\n   */\n  type: 'response.function_call_arguments.done';\n}\n\n/**\n * Returned when MCP tool call arguments are updated during response generation.\n */\nexport interface ResponseMcpCallArgumentsDelta {\n  /**\n   * The JSON-encoded arguments delta.\n   */\n  delta: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the MCP tool call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.mcp_call_arguments.delta`.\n   */\n  type: 'response.mcp_call_arguments.delta';\n\n  /**\n   * If present, indicates the delta text was obfuscated.\n   */\n  obfuscation?: string | null;\n}\n\n/**\n * Returned when MCP tool call arguments are finalized during response generation.\n */\nexport interface ResponseMcpCallArgumentsDone {\n  /**\n   * The final JSON-encoded arguments string.\n   */\n  arguments: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the MCP tool call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.mcp_call_arguments.done`.\n   */\n  type: 'response.mcp_call_arguments.done';\n}\n\n/**\n * Returned when an MCP tool call has completed successfully.\n */\nexport interface ResponseMcpCallCompleted {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the MCP tool call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The event type, must be `response.mcp_call.completed`.\n   */\n  type: 'response.mcp_call.completed';\n}\n\n/**\n * Returned when an MCP tool call has failed.\n */\nexport interface ResponseMcpCallFailed {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the MCP tool call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The event type, must be `response.mcp_call.failed`.\n   */\n  type: 'response.mcp_call.failed';\n}\n\n/**\n * Returned when an MCP tool call has started and is in progress.\n */\nexport interface ResponseMcpCallInProgress {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the MCP tool call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The event type, must be `response.mcp_call.in_progress`.\n   */\n  type: 'response.mcp_call.in_progress';\n}\n\n/**\n * Returned when a new Item is created during Response generation.\n */\nexport interface ResponseOutputItemAddedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * A single item within a Realtime conversation.\n   */\n  item: ConversationItem;\n\n  /**\n   * The index of the output item in the Response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the Response to which the item belongs.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.output_item.added`.\n   */\n  type: 'response.output_item.added';\n}\n\n/**\n * Returned when an Item is done streaming. Also emitted when a Response is\n * interrupted, incomplete, or cancelled.\n */\nexport interface ResponseOutputItemDoneEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * A single item within a Realtime conversation.\n   */\n  item: ConversationItem;\n\n  /**\n   * The index of the output item in the Response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the Response to which the item belongs.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.output_item.done`.\n   */\n  type: 'response.output_item.done';\n}\n\n/**\n * Returned when the text value of an \"output_text\" content part is updated.\n */\nexport interface ResponseTextDeltaEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The text delta.\n   */\n  delta: string;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The event type, must be `response.output_text.delta`.\n   */\n  type: 'response.output_text.delta';\n}\n\n/**\n * Returned when the text value of an \"output_text\" content part is done streaming.\n * Also emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseTextDoneEvent {\n  /**\n   * The index of the content part in the item's content array.\n   */\n  content_index: number;\n\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response.\n   */\n  output_index: number;\n\n  /**\n   * The ID of the response.\n   */\n  response_id: string;\n\n  /**\n   * The final text content.\n   */\n  text: string;\n\n  /**\n   * The event type, must be `response.output_text.done`.\n   */\n  type: 'response.output_text.done';\n}\n\n/**\n * Returned when a Session is created. Emitted automatically when a new connection\n * is established as the first server event. This event will contain the default\n * Session configuration.\n */\nexport interface SessionCreatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The session configuration.\n   */\n  session: RealtimeSessionCreateRequest | RealtimeTranscriptionSessionCreateRequest;\n\n  /**\n   * The event type, must be `session.created`.\n   */\n  type: 'session.created';\n}\n\n/**\n * Send this event to update the session’s configuration. The client may send this\n * event at any time to update any field except for `voice` and `model`. `voice`\n * can be updated only if there have been no other audio outputs yet.\n *\n * When the server receives a `session.update`, it will respond with a\n * `session.updated` event showing the full, effective configuration. Only the\n * fields that are present in the `session.update` are updated. To clear a field\n * like `instructions`, pass an empty string. To clear a field like `tools`, pass\n * an empty array. To clear a field like `turn_detection`, pass `null`.\n */\nexport interface SessionUpdateEvent {\n  /**\n   * Update the Realtime session. Choose either a realtime session or a transcription\n   * session.\n   */\n  session: RealtimeSessionCreateRequest | RealtimeTranscriptionSessionCreateRequest;\n\n  /**\n   * The event type, must be `session.update`.\n   */\n  type: 'session.update';\n\n  /**\n   * Optional client-generated ID used to identify this event. This is an arbitrary\n   * string that a client may assign. It will be passed back if there is an error\n   * with the event, but the corresponding `session.updated` event will not include\n   * it.\n   */\n  event_id?: string;\n}\n\n/**\n * Returned when a session is updated with a `session.update` event, unless there\n * is an error.\n */\nexport interface SessionUpdatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * The session configuration.\n   */\n  session: RealtimeSessionCreateRequest | RealtimeTranscriptionSessionCreateRequest;\n\n  /**\n   * The event type, must be `session.updated`.\n   */\n  type: 'session.updated';\n}\n\n/**\n * Send this event to update a transcription session.\n */\nexport interface TranscriptionSessionUpdate {\n  /**\n   * Realtime transcription session object configuration.\n   */\n  session: TranscriptionSessionUpdate.Session;\n\n  /**\n   * The event type, must be `transcription_session.update`.\n   */\n  type: 'transcription_session.update';\n\n  /**\n   * Optional client-generated ID used to identify this event.\n   */\n  event_id?: string;\n}\n\nexport namespace TranscriptionSessionUpdate {\n  /**\n   * Realtime transcription session object configuration.\n   */\n  export interface Session {\n    /**\n     * The set of items to include in the transcription. Current available items are:\n     * `item.input_audio_transcription.logprobs`\n     */\n    include?: Array<'item.input_audio_transcription.logprobs'>;\n\n    /**\n     * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n     * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n     * (mono), and little-endian byte order.\n     */\n    input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n    /**\n     * Configuration for input audio noise reduction. This can be set to `null` to turn\n     * off. Noise reduction filters audio added to the input audio buffer before it is\n     * sent to VAD and the model. Filtering the audio can improve VAD and turn\n     * detection accuracy (reducing false positives) and model performance by improving\n     * perception of the input audio.\n     */\n    input_audio_noise_reduction?: Session.InputAudioNoiseReduction;\n\n    /**\n     * Configuration for input audio transcription. The client can optionally set the\n     * language and prompt for transcription, these offer additional guidance to the\n     * transcription service.\n     */\n    input_audio_transcription?: RealtimeAPI.AudioTranscription;\n\n    /**\n     * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n     * means that the model will detect the start and end of speech based on audio\n     * volume and respond at the end of user speech.\n     */\n    turn_detection?: Session.TurnDetection;\n  }\n\n  export namespace Session {\n    /**\n     * Configuration for input audio noise reduction. This can be set to `null` to turn\n     * off. Noise reduction filters audio added to the input audio buffer before it is\n     * sent to VAD and the model. Filtering the audio can improve VAD and turn\n     * detection accuracy (reducing false positives) and model performance by improving\n     * perception of the input audio.\n     */\n    export interface InputAudioNoiseReduction {\n      /**\n       * Type of noise reduction. `near_field` is for close-talking microphones such as\n       * headphones, `far_field` is for far-field microphones such as laptop or\n       * conference room microphones.\n       */\n      type?: RealtimeAPI.NoiseReductionType;\n    }\n\n    /**\n     * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n     * means that the model will detect the start and end of speech based on audio\n     * volume and respond at the end of user speech.\n     */\n    export interface TurnDetection {\n      /**\n       * Amount of audio to include before the VAD detected speech (in milliseconds).\n       * Defaults to 300ms.\n       */\n      prefix_padding_ms?: number;\n\n      /**\n       * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.\n       * With shorter values the model will respond more quickly, but may jump in on\n       * short pauses from the user.\n       */\n      silence_duration_ms?: number;\n\n      /**\n       * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher\n       * threshold will require louder audio to activate the model, and thus might\n       * perform better in noisy environments.\n       */\n      threshold?: number;\n\n      /**\n       * Type of turn detection. Only `server_vad` is currently supported for\n       * transcription sessions.\n       */\n      type?: 'server_vad';\n    }\n  }\n}\n\n/**\n * Returned when a transcription session is updated with a\n * `transcription_session.update` event, unless there is an error.\n */\nexport interface TranscriptionSessionUpdatedEvent {\n  /**\n   * The unique ID of the server event.\n   */\n  event_id: string;\n\n  /**\n   * A new Realtime transcription session configuration.\n   *\n   * When a session is created on the server via REST API, the session object also\n   * contains an ephemeral key. Default TTL for keys is 10 minutes. This property is\n   * not present when a session is updated via the WebSocket API.\n   */\n  session: TranscriptionSessionUpdatedEvent.Session;\n\n  /**\n   * The event type, must be `transcription_session.updated`.\n   */\n  type: 'transcription_session.updated';\n}\n\nexport namespace TranscriptionSessionUpdatedEvent {\n  /**\n   * A new Realtime transcription session configuration.\n   *\n   * When a session is created on the server via REST API, the session object also\n   * contains an ephemeral key. Default TTL for keys is 10 minutes. This property is\n   * not present when a session is updated via the WebSocket API.\n   */\n  export interface Session {\n    /**\n     * Ephemeral key returned by the API. Only present when the session is created on\n     * the server via REST API.\n     */\n    client_secret: Session.ClientSecret;\n\n    /**\n     * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n     */\n    input_audio_format?: string;\n\n    /**\n     * Configuration of the transcription model.\n     */\n    input_audio_transcription?: RealtimeAPI.AudioTranscription;\n\n    /**\n     * The set of modalities the model can respond with. To disable audio, set this to\n     * [\"text\"].\n     */\n    modalities?: Array<'text' | 'audio'>;\n\n    /**\n     * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n     * means that the model will detect the start and end of speech based on audio\n     * volume and respond at the end of user speech.\n     */\n    turn_detection?: Session.TurnDetection;\n  }\n\n  export namespace Session {\n    /**\n     * Ephemeral key returned by the API. Only present when the session is created on\n     * the server via REST API.\n     */\n    export interface ClientSecret {\n      /**\n       * Timestamp for when the token expires. Currently, all tokens expire after one\n       * minute.\n       */\n      expires_at: number;\n\n      /**\n       * Ephemeral key usable in client environments to authenticate connections to the\n       * Realtime API. Use this in client-side environments rather than a standard API\n       * token, which should only be used server-side.\n       */\n      value: string;\n    }\n\n    /**\n     * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n     * means that the model will detect the start and end of speech based on audio\n     * volume and respond at the end of user speech.\n     */\n    export interface TurnDetection {\n      /**\n       * Amount of audio to include before the VAD detected speech (in milliseconds).\n       * Defaults to 300ms.\n       */\n      prefix_padding_ms?: number;\n\n      /**\n       * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.\n       * With shorter values the model will respond more quickly, but may jump in on\n       * short pauses from the user.\n       */\n      silence_duration_ms?: number;\n\n      /**\n       * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher\n       * threshold will require louder audio to activate the model, and thus might\n       * perform better in noisy environments.\n       */\n      threshold?: number;\n\n      /**\n       * Type of turn detection, only `server_vad` is currently supported.\n       */\n      type?: string;\n    }\n  }\n}\n\nRealtime.ClientSecrets = ClientSecrets;\nRealtime.Calls = Calls;\n\nexport declare namespace Realtime {\n  export {\n    type AudioTranscription as AudioTranscription,\n    type ConversationCreatedEvent as ConversationCreatedEvent,\n    type ConversationItem as ConversationItem,\n    type ConversationItemAdded as ConversationItemAdded,\n    type ConversationItemCreateEvent as ConversationItemCreateEvent,\n    type ConversationItemCreatedEvent as ConversationItemCreatedEvent,\n    type ConversationItemDeleteEvent as ConversationItemDeleteEvent,\n    type ConversationItemDeletedEvent as ConversationItemDeletedEvent,\n    type ConversationItemDone as ConversationItemDone,\n    type ConversationItemInputAudioTranscriptionCompletedEvent as ConversationItemInputAudioTranscriptionCompletedEvent,\n    type ConversationItemInputAudioTranscriptionDeltaEvent as ConversationItemInputAudioTranscriptionDeltaEvent,\n    type ConversationItemInputAudioTranscriptionFailedEvent as ConversationItemInputAudioTranscriptionFailedEvent,\n    type ConversationItemInputAudioTranscriptionSegment as ConversationItemInputAudioTranscriptionSegment,\n    type ConversationItemRetrieveEvent as ConversationItemRetrieveEvent,\n    type ConversationItemTruncateEvent as ConversationItemTruncateEvent,\n    type ConversationItemTruncatedEvent as ConversationItemTruncatedEvent,\n    type ConversationItemWithReference as ConversationItemWithReference,\n    type InputAudioBufferAppendEvent as InputAudioBufferAppendEvent,\n    type InputAudioBufferClearEvent as InputAudioBufferClearEvent,\n    type InputAudioBufferClearedEvent as InputAudioBufferClearedEvent,\n    type InputAudioBufferCommitEvent as InputAudioBufferCommitEvent,\n    type InputAudioBufferCommittedEvent as InputAudioBufferCommittedEvent,\n    type InputAudioBufferDtmfEventReceivedEvent as InputAudioBufferDtmfEventReceivedEvent,\n    type InputAudioBufferSpeechStartedEvent as InputAudioBufferSpeechStartedEvent,\n    type InputAudioBufferSpeechStoppedEvent as InputAudioBufferSpeechStoppedEvent,\n    type InputAudioBufferTimeoutTriggered as InputAudioBufferTimeoutTriggered,\n    type LogProbProperties as LogProbProperties,\n    type McpListToolsCompleted as McpListToolsCompleted,\n    type McpListToolsFailed as McpListToolsFailed,\n    type McpListToolsInProgress as McpListToolsInProgress,\n    type NoiseReductionType as NoiseReductionType,\n    type OutputAudioBufferClearEvent as OutputAudioBufferClearEvent,\n    type RateLimitsUpdatedEvent as RateLimitsUpdatedEvent,\n    type RealtimeAudioConfig as RealtimeAudioConfig,\n    type RealtimeAudioConfigInput as RealtimeAudioConfigInput,\n    type RealtimeAudioConfigOutput as RealtimeAudioConfigOutput,\n    type RealtimeAudioFormats as RealtimeAudioFormats,\n    type RealtimeAudioInputTurnDetection as RealtimeAudioInputTurnDetection,\n    type RealtimeClientEvent as RealtimeClientEvent,\n    type RealtimeConversationItemAssistantMessage as RealtimeConversationItemAssistantMessage,\n    type RealtimeConversationItemFunctionCall as RealtimeConversationItemFunctionCall,\n    type RealtimeConversationItemFunctionCallOutput as RealtimeConversationItemFunctionCallOutput,\n    type RealtimeConversationItemSystemMessage as RealtimeConversationItemSystemMessage,\n    type RealtimeConversationItemUserMessage as RealtimeConversationItemUserMessage,\n    type RealtimeError as RealtimeError,\n    type RealtimeErrorEvent as RealtimeErrorEvent,\n    type RealtimeFunctionTool as RealtimeFunctionTool,\n    type RealtimeMcpApprovalRequest as RealtimeMcpApprovalRequest,\n    type RealtimeMcpApprovalResponse as RealtimeMcpApprovalResponse,\n    type RealtimeMcpListTools as RealtimeMcpListTools,\n    type RealtimeMcpProtocolError as RealtimeMcpProtocolError,\n    type RealtimeMcpToolCall as RealtimeMcpToolCall,\n    type RealtimeMcpToolExecutionError as RealtimeMcpToolExecutionError,\n    type RealtimeMcphttpError as RealtimeMcphttpError,\n    type RealtimeResponse as RealtimeResponse,\n    type RealtimeResponseCreateAudioOutput as RealtimeResponseCreateAudioOutput,\n    type RealtimeResponseCreateMcpTool as RealtimeResponseCreateMcpTool,\n    type RealtimeResponseCreateParams as RealtimeResponseCreateParams,\n    type RealtimeResponseStatus as RealtimeResponseStatus,\n    type RealtimeResponseUsage as RealtimeResponseUsage,\n    type RealtimeResponseUsageInputTokenDetails as RealtimeResponseUsageInputTokenDetails,\n    type RealtimeResponseUsageOutputTokenDetails as RealtimeResponseUsageOutputTokenDetails,\n    type RealtimeServerEvent as RealtimeServerEvent,\n    type RealtimeSession as RealtimeSession,\n    type RealtimeSessionCreateRequest as RealtimeSessionCreateRequest,\n    type RealtimeToolChoiceConfig as RealtimeToolChoiceConfig,\n    type RealtimeToolsConfig as RealtimeToolsConfig,\n    type RealtimeToolsConfigUnion as RealtimeToolsConfigUnion,\n    type RealtimeTracingConfig as RealtimeTracingConfig,\n    type RealtimeTranscriptionSessionAudio as RealtimeTranscriptionSessionAudio,\n    type RealtimeTranscriptionSessionAudioInput as RealtimeTranscriptionSessionAudioInput,\n    type RealtimeTranscriptionSessionAudioInputTurnDetection as RealtimeTranscriptionSessionAudioInputTurnDetection,\n    type RealtimeTranscriptionSessionCreateRequest as RealtimeTranscriptionSessionCreateRequest,\n    type RealtimeTruncation as RealtimeTruncation,\n    type RealtimeTruncationRetentionRatio as RealtimeTruncationRetentionRatio,\n    type ResponseAudioDeltaEvent as ResponseAudioDeltaEvent,\n    type ResponseAudioDoneEvent as ResponseAudioDoneEvent,\n    type ResponseAudioTranscriptDeltaEvent as ResponseAudioTranscriptDeltaEvent,\n    type ResponseAudioTranscriptDoneEvent as ResponseAudioTranscriptDoneEvent,\n    type ResponseCancelEvent as ResponseCancelEvent,\n    type ResponseContentPartAddedEvent as ResponseContentPartAddedEvent,\n    type ResponseContentPartDoneEvent as ResponseContentPartDoneEvent,\n    type ResponseCreateEvent as ResponseCreateEvent,\n    type ResponseCreatedEvent as ResponseCreatedEvent,\n    type ResponseDoneEvent as ResponseDoneEvent,\n    type ResponseFunctionCallArgumentsDeltaEvent as ResponseFunctionCallArgumentsDeltaEvent,\n    type ResponseFunctionCallArgumentsDoneEvent as ResponseFunctionCallArgumentsDoneEvent,\n    type ResponseMcpCallArgumentsDelta as ResponseMcpCallArgumentsDelta,\n    type ResponseMcpCallArgumentsDone as ResponseMcpCallArgumentsDone,\n    type ResponseMcpCallCompleted as ResponseMcpCallCompleted,\n    type ResponseMcpCallFailed as ResponseMcpCallFailed,\n    type ResponseMcpCallInProgress as ResponseMcpCallInProgress,\n    type ResponseOutputItemAddedEvent as ResponseOutputItemAddedEvent,\n    type ResponseOutputItemDoneEvent as ResponseOutputItemDoneEvent,\n    type ResponseTextDeltaEvent as ResponseTextDeltaEvent,\n    type ResponseTextDoneEvent as ResponseTextDoneEvent,\n    type SessionCreatedEvent as SessionCreatedEvent,\n    type SessionUpdateEvent as SessionUpdateEvent,\n    type SessionUpdatedEvent as SessionUpdatedEvent,\n    type TranscriptionSessionUpdate as TranscriptionSessionUpdate,\n    type TranscriptionSessionUpdatedEvent as TranscriptionSessionUpdatedEvent,\n  };\n\n  export {\n    ClientSecrets as ClientSecrets,\n    type RealtimeSessionClientSecret as RealtimeSessionClientSecret,\n    type RealtimeSessionCreateResponse as RealtimeSessionCreateResponse,\n    type RealtimeTranscriptionSessionCreateResponse as RealtimeTranscriptionSessionCreateResponse,\n    type RealtimeTranscriptionSessionTurnDetection as RealtimeTranscriptionSessionTurnDetection,\n    type ClientSecretCreateResponse as ClientSecretCreateResponse,\n    type ClientSecretCreateParams as ClientSecretCreateParams,\n  };\n\n  export {\n    Calls as Calls,\n    type CallAcceptParams as CallAcceptParams,\n    type CallReferParams as CallReferParams,\n    type CallRejectParams as CallRejectParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/realtime.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './realtime/index';\n"
  },
  {
    "path": "src/resources/responses/api.md",
    "content": "# Responses\n\nTypes:\n\n- <code><a href=\"./src/resources/responses/responses.ts\">ApplyPatchTool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">CompactedResponse</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ComputerAction</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ComputerActionList</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ComputerTool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ComputerUsePreviewTool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ContainerAuto</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ContainerNetworkPolicyAllowlist</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ContainerNetworkPolicyDisabled</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ContainerNetworkPolicyDomainSecret</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ContainerReference</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">CustomTool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">EasyInputMessage</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">FileSearchTool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">FunctionShellTool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">FunctionTool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">InlineSkill</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">InlineSkillSource</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">LocalEnvironment</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">LocalSkill</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">NamespaceTool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">Response</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseApplyPatchToolCall</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseApplyPatchToolCallOutput</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseAudioDeltaEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseAudioDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseAudioTranscriptDeltaEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseAudioTranscriptDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCodeInterpreterCallCodeDeltaEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCodeInterpreterCallCodeDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCodeInterpreterCallCompletedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCodeInterpreterCallInProgressEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCodeInterpreterCallInterpretingEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCodeInterpreterToolCall</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCompactionItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCompactionItemParam</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCompletedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseComputerToolCall</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseComputerToolCallOutputItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseComputerToolCallOutputScreenshot</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseContainerReference</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseContent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseContentPartAddedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseContentPartDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseConversationParam</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCreatedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCustomToolCall</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCustomToolCallInputDeltaEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCustomToolCallInputDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseCustomToolCallOutput</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseError</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseErrorEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFailedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFileSearchCallCompletedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFileSearchCallInProgressEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFileSearchCallSearchingEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFileSearchToolCall</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFormatTextConfig</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFormatTextJSONSchemaConfig</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionCallArgumentsDeltaEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionCallArgumentsDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionCallOutputItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionCallOutputItemList</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionShellCallOutputContent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionShellToolCall</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionShellToolCallOutput</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionToolCall</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionToolCallItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionToolCallOutputItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseFunctionWebSearch</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseImageGenCallCompletedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseImageGenCallGeneratingEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseImageGenCallInProgressEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseImageGenCallPartialImageEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInProgressEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseIncludable</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseIncompleteEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInput</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputAudio</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputContent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputFile</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputFileContent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputImage</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputImageContent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputMessageContentList</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputMessageItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputText</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseInputTextContent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseLocalEnvironment</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseMcpCallArgumentsDeltaEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseMcpCallArgumentsDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseMcpCallCompletedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseMcpCallFailedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseMcpCallInProgressEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseMcpListToolsCompletedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseMcpListToolsFailedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseMcpListToolsInProgressEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseOutputAudio</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseOutputItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseOutputItemAddedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseOutputItemDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseOutputMessage</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseOutputRefusal</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseOutputText</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseOutputTextAnnotationAddedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponsePrompt</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseQueuedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseReasoningItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseReasoningSummaryPartAddedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseReasoningSummaryPartDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseReasoningSummaryTextDeltaEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseReasoningSummaryTextDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseReasoningTextDeltaEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseReasoningTextDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseRefusalDeltaEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseRefusalDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseStatus</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseStreamEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseTextConfig</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseTextDeltaEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseTextDoneEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseToolSearchCall</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseToolSearchOutputItem</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseToolSearchOutputItemParam</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseUsage</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseWebSearchCallCompletedEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseWebSearchCallInProgressEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponseWebSearchCallSearchingEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponsesClientEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ResponsesServerEvent</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">SkillReference</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">Tool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ToolChoiceAllowed</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ToolChoiceApplyPatch</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ToolChoiceCustom</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ToolChoiceFunction</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ToolChoiceMcp</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ToolChoiceOptions</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ToolChoiceShell</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ToolChoiceTypes</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">ToolSearchTool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">WebSearchPreviewTool</a></code>\n- <code><a href=\"./src/resources/responses/responses.ts\">WebSearchTool</a></code>\n\nMethods:\n\n- <code title=\"post /responses\">client.responses.<a href=\"./src/resources/responses/responses.ts\">create</a>({ ...params }) -> Response</code>\n- <code title=\"get /responses/{response_id}\">client.responses.<a href=\"./src/resources/responses/responses.ts\">retrieve</a>(responseID, { ...params }) -> Response</code>\n- <code title=\"delete /responses/{response_id}\">client.responses.<a href=\"./src/resources/responses/responses.ts\">delete</a>(responseID) -> void</code>\n- <code title=\"post /responses/{response_id}/cancel\">client.responses.<a href=\"./src/resources/responses/responses.ts\">cancel</a>(responseID) -> Response</code>\n- <code title=\"post /responses/compact\">client.responses.<a href=\"./src/resources/responses/responses.ts\">compact</a>({ ...params }) -> CompactedResponse</code>\n\n## InputItems\n\nTypes:\n\n- <code><a href=\"./src/resources/responses/input-items.ts\">ResponseItemList</a></code>\n\nMethods:\n\n- <code title=\"get /responses/{response_id}/input_items\">client.responses.inputItems.<a href=\"./src/resources/responses/input-items.ts\">list</a>(responseID, { ...params }) -> ResponseItemsPage</code>\n\n## InputTokens\n\nTypes:\n\n- <code><a href=\"./src/resources/responses/input-tokens.ts\">InputTokenCountResponse</a></code>\n\nMethods:\n\n- <code title=\"post /responses/input_tokens\">client.responses.inputTokens.<a href=\"./src/resources/responses/input-tokens.ts\">count</a>({ ...params }) -> InputTokenCountResponse</code>\n"
  },
  {
    "path": "src/resources/responses/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { InputItems, type ResponseItemList, type InputItemListParams } from './input-items';\nexport { InputTokens, type InputTokenCountResponse, type InputTokenCountParams } from './input-tokens';\nexport { Responses } from './responses';\n"
  },
  {
    "path": "src/resources/responses/input-items.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as ResponsesAPI from './responses';\nimport { ResponseItemsPage } from './responses';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport class InputItems extends APIResource {\n  /**\n   * Returns a list of input items for a given response.\n   *\n   * @example\n   * ```ts\n   * // Automatically fetches more pages as needed.\n   * for await (const responseItem of client.responses.inputItems.list(\n   *   'response_id',\n   * )) {\n   *   // ...\n   * }\n   * ```\n   */\n  list(\n    responseID: string,\n    query: InputItemListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<ResponseItemsPage, ResponsesAPI.ResponseItem> {\n    return this._client.getAPIList(\n      path`/responses/${responseID}/input_items`,\n      CursorPage<ResponsesAPI.ResponseItem>,\n      { query, ...options },\n    );\n  }\n}\n\n/**\n * A list of Response items.\n */\nexport interface ResponseItemList {\n  /**\n   * A list of items used to generate this response.\n   */\n  data: Array<ResponsesAPI.ResponseItem>;\n\n  /**\n   * The ID of the first item in the list.\n   */\n  first_id: string;\n\n  /**\n   * Whether there are more items available.\n   */\n  has_more: boolean;\n\n  /**\n   * The ID of the last item in the list.\n   */\n  last_id: string;\n\n  /**\n   * The type of object returned, must be `list`.\n   */\n  object: 'list';\n}\n\nexport interface InputItemListParams extends CursorPageParams {\n  /**\n   * Additional fields to include in the response. See the `include` parameter for\n   * Response creation above for more information.\n   */\n  include?: Array<ResponsesAPI.ResponseIncludable>;\n\n  /**\n   * The order to return the input items in. Default is `desc`.\n   *\n   * - `asc`: Return the input items in ascending order.\n   * - `desc`: Return the input items in descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport declare namespace InputItems {\n  export { type ResponseItemList as ResponseItemList, type InputItemListParams as InputItemListParams };\n}\n\nexport { type ResponseItemsPage };\n"
  },
  {
    "path": "src/resources/responses/input-tokens.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as ResponsesAPI from './responses';\nimport { APIPromise } from '../../core/api-promise';\nimport { RequestOptions } from '../../internal/request-options';\n\nexport class InputTokens extends APIResource {\n  /**\n   * Returns input token counts of the request.\n   *\n   * Returns an object with `object` set to `response.input_tokens` and an\n   * `input_tokens` count.\n   *\n   * @example\n   * ```ts\n   * const response = await client.responses.inputTokens.count();\n   * ```\n   */\n  count(\n    body: InputTokenCountParams | null | undefined = {},\n    options?: RequestOptions,\n  ): APIPromise<InputTokenCountResponse> {\n    return this._client.post('/responses/input_tokens', { body, ...options });\n  }\n}\n\nexport interface InputTokenCountResponse {\n  input_tokens: number;\n\n  object: 'response.input_tokens';\n}\n\nexport interface InputTokenCountParams {\n  /**\n   * The conversation that this response belongs to. Items from this conversation are\n   * prepended to `input_items` for this response request. Input items and output\n   * items from this response are automatically added to this conversation after this\n   * response completes.\n   */\n  conversation?: string | ResponsesAPI.ResponseConversationParam | null;\n\n  /**\n   * Text, image, or file inputs to the model, used to generate a response\n   */\n  input?: string | Array<ResponsesAPI.ResponseInputItem> | null;\n\n  /**\n   * A system (or developer) message inserted into the model's context. When used\n   * along with `previous_response_id`, the instructions from a previous response\n   * will not be carried over to the next response. This makes it simple to swap out\n   * system (or developer) messages in new responses.\n   */\n  instructions?: string | null;\n\n  /**\n   * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a\n   * wide range of models with different capabilities, performance characteristics,\n   * and price points. Refer to the\n   * [model guide](https://platform.openai.com/docs/models) to browse and compare\n   * available models.\n   */\n  model?: string | null;\n\n  /**\n   * Whether to allow the model to run tool calls in parallel.\n   */\n  parallel_tool_calls?: boolean | null;\n\n  /**\n   * The unique ID of the previous response to the model. Use this to create\n   * multi-turn conversations. Learn more about\n   * [conversation state](https://platform.openai.com/docs/guides/conversation-state).\n   * Cannot be used in conjunction with `conversation`.\n   */\n  previous_response_id?: string | null;\n\n  /**\n   * **gpt-5 and o-series models only** Configuration options for\n   * [reasoning models](https://platform.openai.com/docs/guides/reasoning).\n   */\n  reasoning?: Shared.Reasoning | null;\n\n  /**\n   * Configuration options for a text response from the model. Can be plain text or\n   * structured JSON data. Learn more:\n   *\n   * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n   * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n   */\n  text?: InputTokenCountParams.Text | null;\n\n  /**\n   * Controls which tool the model should use, if any.\n   */\n  tool_choice?:\n    | ResponsesAPI.ToolChoiceOptions\n    | ResponsesAPI.ToolChoiceAllowed\n    | ResponsesAPI.ToolChoiceTypes\n    | ResponsesAPI.ToolChoiceFunction\n    | ResponsesAPI.ToolChoiceMcp\n    | ResponsesAPI.ToolChoiceCustom\n    | ResponsesAPI.ToolChoiceApplyPatch\n    | ResponsesAPI.ToolChoiceShell\n    | null;\n\n  /**\n   * An array of tools the model may call while generating a response. You can\n   * specify which tool to use by setting the `tool_choice` parameter.\n   */\n  tools?: Array<ResponsesAPI.Tool> | null;\n\n  /**\n   * The truncation strategy to use for the model response. - `auto`: If the input to\n   * this Response exceeds the model's context window size, the model will truncate\n   * the response to fit the context window by dropping items from the beginning of\n   * the conversation. - `disabled` (default): If the input size will exceed the\n   * context window size for a model, the request will fail with a 400 error.\n   */\n  truncation?: 'auto' | 'disabled';\n}\n\nexport namespace InputTokenCountParams {\n  /**\n   * Configuration options for a text response from the model. Can be plain text or\n   * structured JSON data. Learn more:\n   *\n   * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n   * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n   */\n  export interface Text {\n    /**\n     * An object specifying the format that the model must output.\n     *\n     * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n     * ensures the model will match your supplied JSON schema. Learn more in the\n     * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n     *\n     * The default format is `{ \"type\": \"text\" }` with no additional options.\n     *\n     * **Not recommended for gpt-4o and newer models:**\n     *\n     * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n     * ensures the message the model generates is valid JSON. Using `json_schema` is\n     * preferred for models that support it.\n     */\n    format?: ResponsesAPI.ResponseFormatTextConfig;\n\n    /**\n     * Constrains the verbosity of the model's response. Lower values will result in\n     * more concise responses, while higher values will result in more verbose\n     * responses. Currently supported values are `low`, `medium`, and `high`.\n     */\n    verbosity?: 'low' | 'medium' | 'high' | null;\n  }\n}\n\nexport declare namespace InputTokens {\n  export {\n    type InputTokenCountResponse as InputTokenCountResponse,\n    type InputTokenCountParams as InputTokenCountParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/responses/internal-base.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport * as ResponsesAPI from './responses';\nimport { OpenAI } from '../../client';\n\nimport { EventEmitter } from '../../core/EventEmitter';\nimport { OpenAIError } from '../../core/error';\nimport { stringifyQuery } from '../../internal/utils';\n\nexport class WebSocketError extends OpenAIError {\n  /**\n   * The error data that the API sent back in an error event.\n   */\n  error?: ResponsesAPI.ResponseErrorEvent | undefined;\n\n  constructor(message: string, event: ResponsesAPI.ResponseErrorEvent | null) {\n    super(message);\n\n    this.error = event ?? undefined;\n  }\n}\n\ntype Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};\n\ntype WebSocketEvents = Simplify<\n  {\n    event: (event: ResponsesAPI.ResponsesServerEvent) => void;\n    error: (error: WebSocketError) => void;\n  } & {\n    [EventType in Exclude<NonNullable<ResponsesAPI.ResponsesServerEvent['type']>, 'error'>]: (\n      event: Extract<ResponsesAPI.ResponsesServerEvent, { type?: EventType }>,\n    ) => unknown;\n  }\n>;\n\nexport abstract class ResponsesEmitter extends EventEmitter<WebSocketEvents> {\n  /**\n   * Send an event to the API.\n   */\n  abstract send(event: ResponsesAPI.ResponsesClientEvent): void;\n\n  /**\n   * Close the WebSocket connection.\n   */\n  abstract close(props?: { code: number; reason: string }): void;\n\n  protected _onError(event: null, message: string, cause: any): void;\n  protected _onError(event: ResponsesAPI.ResponseErrorEvent, message?: string | undefined): void;\n  protected _onError(\n    event: ResponsesAPI.ResponseErrorEvent | null,\n    message?: string | undefined,\n    cause?: any,\n  ): void {\n    message = message ?? safeJSONStringify(event) ?? 'unknown error';\n\n    if (!this._hasListener('error')) {\n      const error = new WebSocketError(\n        message +\n          `\\n\\nTo resolve these unhandled rejection errors you should bind an \\`error\\` callback, e.g. \\`ws.on('error', (error) => ...)\\` `,\n        event,\n      );\n      // @ts-ignore\n      error.cause = cause;\n      Promise.reject(error);\n      return;\n    }\n\n    const error = new WebSocketError(message, event);\n    // @ts-ignore\n    error.cause = cause;\n\n    this._emit('error', error);\n  }\n}\n\nexport function buildURL(client: OpenAI, query?: object | null): URL {\n  const path = '/responses';\n  const baseURL = client.baseURL;\n  const url = new URL(baseURL + (baseURL.endsWith('/') ? path.slice(1) : path));\n  if (query) {\n    url.search = stringifyQuery(query);\n  }\n  url.protocol = url.protocol === 'http:' ? 'ws:' : 'wss:';\n  return url;\n}\n\nfunction safeJSONStringify(value: unknown): string | null {\n  try {\n    return JSON.stringify(value);\n  } catch {\n    return null;\n  }\n}\n"
  },
  {
    "path": "src/resources/responses/responses.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport {\n  type ExtractParsedContentFromParams,\n  parseResponse,\n  type ResponseCreateParamsWithTools,\n  addOutputText,\n} from '../../lib/ResponsesParser';\nimport { ResponseStream, ResponseStreamParams } from '../../lib/responses/ResponseStream';\nimport { APIResource } from '../../core/resource';\nimport * as ResponsesAPI from './responses';\nimport * as Shared from '../shared';\nimport * as InputItemsAPI from './input-items';\nimport { InputItemListParams, InputItems, ResponseItemList } from './input-items';\nimport * as InputTokensAPI from './input-tokens';\nimport { InputTokenCountParams, InputTokenCountResponse, InputTokens } from './input-tokens';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage } from '../../core/pagination';\nimport { Stream } from '../../core/streaming';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport interface ParsedResponseOutputText<ParsedT> extends ResponseOutputText {\n  parsed: ParsedT | null;\n}\n\nexport type ParsedContent<ParsedT> = ParsedResponseOutputText<ParsedT> | ResponseOutputRefusal;\n\nexport interface ParsedResponseOutputMessage<ParsedT> extends ResponseOutputMessage {\n  content: ParsedContent<ParsedT>[];\n}\n\nexport interface ParsedResponseFunctionToolCall extends ResponseFunctionToolCall {\n  parsed_arguments: any;\n}\n\nexport type ParsedResponseOutputItem<ParsedT> =\n  | ParsedResponseOutputMessage<ParsedT>\n  | ParsedResponseFunctionToolCall\n  | ResponseFileSearchToolCall\n  | ResponseFunctionWebSearch\n  | ResponseComputerToolCall\n  | ResponseToolSearchCall\n  | ResponseToolSearchOutputItem\n  | ResponseReasoningItem\n  | ResponseCompactionItem\n  | ResponseOutputItem.ImageGenerationCall\n  | ResponseCodeInterpreterToolCall\n  | ResponseOutputItem.LocalShellCall\n  | ResponseFunctionShellToolCall\n  | ResponseFunctionShellToolCallOutput\n  | ResponseApplyPatchToolCall\n  | ResponseApplyPatchToolCallOutput\n  | ResponseOutputItem.McpCall\n  | ResponseOutputItem.McpListTools\n  | ResponseOutputItem.McpApprovalRequest\n  | ResponseCustomToolCall;\n\nexport interface ParsedResponse<ParsedT> extends Response {\n  output: Array<ParsedResponseOutputItem<ParsedT>>;\n\n  output_parsed: ParsedT | null;\n}\n\nexport type ResponseParseParams = ResponseCreateParamsNonStreaming;\n\nexport class Responses extends APIResource {\n  inputItems: InputItemsAPI.InputItems = new InputItemsAPI.InputItems(this._client);\n  inputTokens: InputTokensAPI.InputTokens = new InputTokensAPI.InputTokens(this._client);\n\n  /**\n   * Creates a model response. Provide\n   * [text](https://platform.openai.com/docs/guides/text) or\n   * [image](https://platform.openai.com/docs/guides/images) inputs to generate\n   * [text](https://platform.openai.com/docs/guides/text) or\n   * [JSON](https://platform.openai.com/docs/guides/structured-outputs) outputs. Have\n   * the model call your own\n   * [custom code](https://platform.openai.com/docs/guides/function-calling) or use\n   * built-in [tools](https://platform.openai.com/docs/guides/tools) like\n   * [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n   * [file search](https://platform.openai.com/docs/guides/tools-file-search) to use\n   * your own data as input for the model's response.\n   *\n   * @example\n   * ```ts\n   * const response = await client.responses.create();\n   * ```\n   */\n  create(body: ResponseCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Response>;\n  create(\n    body: ResponseCreateParamsStreaming,\n    options?: RequestOptions,\n  ): APIPromise<Stream<ResponseStreamEvent>>;\n  create(\n    body: ResponseCreateParamsBase,\n    options?: RequestOptions,\n  ): APIPromise<Stream<ResponseStreamEvent> | Response>;\n  create(\n    body: ResponseCreateParams,\n    options?: RequestOptions,\n  ): APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>> {\n    return (\n      this._client.post('/responses', { body, ...options, stream: body.stream ?? false }) as\n        | APIPromise<Response>\n        | APIPromise<Stream<ResponseStreamEvent>>\n    )._thenUnwrap((rsp) => {\n      if ('object' in rsp && rsp.object === 'response') {\n        addOutputText(rsp as Response);\n      }\n\n      return rsp;\n    }) as APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>>;\n  }\n\n  /**\n   * Retrieves a model response with the given ID.\n   *\n   * @example\n   * ```ts\n   * const response = await client.responses.retrieve(\n   *   'resp_677efb5139a88190b512bc3fef8e535d',\n   * );\n   * ```\n   */\n  retrieve(\n    responseID: string,\n    query?: ResponseRetrieveParamsNonStreaming,\n    options?: RequestOptions,\n  ): APIPromise<Response>;\n  retrieve(\n    responseID: string,\n    query: ResponseRetrieveParamsStreaming,\n    options?: RequestOptions,\n  ): APIPromise<Stream<ResponseStreamEvent>>;\n  retrieve(\n    responseID: string,\n    query?: ResponseRetrieveParamsBase | undefined,\n    options?: RequestOptions,\n  ): APIPromise<Stream<ResponseStreamEvent> | Response>;\n  retrieve(\n    responseID: string,\n    query: ResponseRetrieveParams | undefined = {},\n    options?: RequestOptions,\n  ): APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>> {\n    return (\n      this._client.get(path`/responses/${responseID}`, {\n        query,\n        ...options,\n        stream: query?.stream ?? false,\n      }) as APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>>\n    )._thenUnwrap((rsp) => {\n      if ('object' in rsp && rsp.object === 'response') {\n        addOutputText(rsp as Response);\n      }\n\n      return rsp;\n    }) as APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>>;\n  }\n\n  /**\n   * Deletes a model response with the given ID.\n   *\n   * @example\n   * ```ts\n   * await client.responses.delete(\n   *   'resp_677efb5139a88190b512bc3fef8e535d',\n   * );\n   * ```\n   */\n  delete(responseID: string, options?: RequestOptions): APIPromise<void> {\n    return this._client.delete(path`/responses/${responseID}`, {\n      ...options,\n      headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n    });\n  }\n\n  parse<Params extends ResponseCreateParamsWithTools, ParsedT = ExtractParsedContentFromParams<Params>>(\n    body: Params,\n    options?: RequestOptions,\n  ): APIPromise<ParsedResponse<ParsedT>> {\n    return this._client.responses\n      .create(body, options)\n      ._thenUnwrap((response) => parseResponse(response as Response, body));\n  }\n\n  /**\n   * Creates a model response stream\n   */\n  stream<Params extends ResponseStreamParams, ParsedT = ExtractParsedContentFromParams<Params>>(\n    body: Params,\n    options?: RequestOptions,\n  ): ResponseStream<ParsedT> {\n    return ResponseStream.createResponse<ParsedT>(this._client, body, options);\n  }\n\n  /**\n   * Cancels a model response with the given ID. Only responses created with the\n   * `background` parameter set to `true` can be cancelled.\n   * [Learn more](https://platform.openai.com/docs/guides/background).\n   *\n   * @example\n   * ```ts\n   * const response = await client.responses.cancel(\n   *   'resp_677efb5139a88190b512bc3fef8e535d',\n   * );\n   * ```\n   */\n  cancel(responseID: string, options?: RequestOptions): APIPromise<Response> {\n    return this._client.post(path`/responses/${responseID}/cancel`, options);\n  }\n\n  /**\n   * Compact a conversation. Returns a compacted response object.\n   *\n   * Learn when and how to compact long-running conversations in the\n   * [conversation state guide](https://platform.openai.com/docs/guides/conversation-state#managing-the-context-window).\n   * For ZDR-compatible compaction details, see\n   * [Compaction (advanced)](https://platform.openai.com/docs/guides/conversation-state#compaction-advanced).\n   *\n   * @example\n   * ```ts\n   * const compactedResponse = await client.responses.compact({\n   *   model: 'gpt-5.4',\n   * });\n   * ```\n   */\n  compact(body: ResponseCompactParams, options?: RequestOptions): APIPromise<CompactedResponse> {\n    return this._client.post('/responses/compact', { body, ...options });\n  }\n}\n\nexport type ResponseItemsPage = CursorPage<ResponseItem>;\n\n/**\n * Allows the assistant to create, delete, or update files using unified diffs.\n */\nexport interface ApplyPatchTool {\n  /**\n   * The type of the tool. Always `apply_patch`.\n   */\n  type: 'apply_patch';\n}\n\nexport interface CompactedResponse {\n  /**\n   * The unique identifier for the compacted response.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) when the compacted conversation was created.\n   */\n  created_at: number;\n\n  /**\n   * The object type. Always `response.compaction`.\n   */\n  object: 'response.compaction';\n\n  /**\n   * The compacted list of output items. This is a list of all user messages,\n   * followed by a single compaction item.\n   */\n  output: Array<ResponseOutputItem>;\n\n  /**\n   * Token accounting for the compaction pass, including cached, reasoning, and total\n   * tokens.\n   */\n  usage: ResponseUsage;\n}\n\n/**\n * A click action.\n */\nexport type ComputerAction =\n  | ComputerAction.Click\n  | ComputerAction.DoubleClick\n  | ComputerAction.Drag\n  | ComputerAction.Keypress\n  | ComputerAction.Move\n  | ComputerAction.Screenshot\n  | ComputerAction.Scroll\n  | ComputerAction.Type\n  | ComputerAction.Wait;\n\nexport namespace ComputerAction {\n  /**\n   * A click action.\n   */\n  export interface Click {\n    /**\n     * Indicates which mouse button was pressed during the click. One of `left`,\n     * `right`, `wheel`, `back`, or `forward`.\n     */\n    button: 'left' | 'right' | 'wheel' | 'back' | 'forward';\n\n    /**\n     * Specifies the event type. For a click action, this property is always `click`.\n     */\n    type: 'click';\n\n    /**\n     * The x-coordinate where the click occurred.\n     */\n    x: number;\n\n    /**\n     * The y-coordinate where the click occurred.\n     */\n    y: number;\n  }\n\n  /**\n   * A double click action.\n   */\n  export interface DoubleClick {\n    /**\n     * Specifies the event type. For a double click action, this property is always set\n     * to `double_click`.\n     */\n    type: 'double_click';\n\n    /**\n     * The x-coordinate where the double click occurred.\n     */\n    x: number;\n\n    /**\n     * The y-coordinate where the double click occurred.\n     */\n    y: number;\n  }\n\n  /**\n   * A drag action.\n   */\n  export interface Drag {\n    /**\n     * An array of coordinates representing the path of the drag action. Coordinates\n     * will appear as an array of objects, eg\n     *\n     * ```\n     * [\n     *   { x: 100, y: 200 },\n     *   { x: 200, y: 300 }\n     * ]\n     * ```\n     */\n    path: Array<Drag.Path>;\n\n    /**\n     * Specifies the event type. For a drag action, this property is always set to\n     * `drag`.\n     */\n    type: 'drag';\n  }\n\n  export namespace Drag {\n    /**\n     * An x/y coordinate pair, e.g. `{ x: 100, y: 200 }`.\n     */\n    export interface Path {\n      /**\n       * The x-coordinate.\n       */\n      x: number;\n\n      /**\n       * The y-coordinate.\n       */\n      y: number;\n    }\n  }\n\n  /**\n   * A collection of keypresses the model would like to perform.\n   */\n  export interface Keypress {\n    /**\n     * The combination of keys the model is requesting to be pressed. This is an array\n     * of strings, each representing a key.\n     */\n    keys: Array<string>;\n\n    /**\n     * Specifies the event type. For a keypress action, this property is always set to\n     * `keypress`.\n     */\n    type: 'keypress';\n  }\n\n  /**\n   * A mouse move action.\n   */\n  export interface Move {\n    /**\n     * Specifies the event type. For a move action, this property is always set to\n     * `move`.\n     */\n    type: 'move';\n\n    /**\n     * The x-coordinate to move to.\n     */\n    x: number;\n\n    /**\n     * The y-coordinate to move to.\n     */\n    y: number;\n  }\n\n  /**\n   * A screenshot action.\n   */\n  export interface Screenshot {\n    /**\n     * Specifies the event type. For a screenshot action, this property is always set\n     * to `screenshot`.\n     */\n    type: 'screenshot';\n  }\n\n  /**\n   * A scroll action.\n   */\n  export interface Scroll {\n    /**\n     * The horizontal scroll distance.\n     */\n    scroll_x: number;\n\n    /**\n     * The vertical scroll distance.\n     */\n    scroll_y: number;\n\n    /**\n     * Specifies the event type. For a scroll action, this property is always set to\n     * `scroll`.\n     */\n    type: 'scroll';\n\n    /**\n     * The x-coordinate where the scroll occurred.\n     */\n    x: number;\n\n    /**\n     * The y-coordinate where the scroll occurred.\n     */\n    y: number;\n  }\n\n  /**\n   * An action to type in text.\n   */\n  export interface Type {\n    /**\n     * The text to type.\n     */\n    text: string;\n\n    /**\n     * Specifies the event type. For a type action, this property is always set to\n     * `type`.\n     */\n    type: 'type';\n  }\n\n  /**\n   * A wait action.\n   */\n  export interface Wait {\n    /**\n     * Specifies the event type. For a wait action, this property is always set to\n     * `wait`.\n     */\n    type: 'wait';\n  }\n}\n\n/**\n * Flattened batched actions for `computer_use`. Each action includes an `type`\n * discriminator and action-specific fields.\n */\nexport type ComputerActionList = Array<ComputerAction>;\n\n/**\n * A tool that controls a virtual computer. Learn more about the\n * [computer tool](https://platform.openai.com/docs/guides/tools-computer-use).\n */\nexport interface ComputerTool {\n  /**\n   * The type of the computer tool. Always `computer`.\n   */\n  type: 'computer';\n}\n\n/**\n * A tool that controls a virtual computer. Learn more about the\n * [computer tool](https://platform.openai.com/docs/guides/tools-computer-use).\n */\nexport interface ComputerUsePreviewTool {\n  /**\n   * The height of the computer display.\n   */\n  display_height: number;\n\n  /**\n   * The width of the computer display.\n   */\n  display_width: number;\n\n  /**\n   * The type of computer environment to control.\n   */\n  environment: 'windows' | 'mac' | 'linux' | 'ubuntu' | 'browser';\n\n  /**\n   * The type of the computer use tool. Always `computer_use_preview`.\n   */\n  type: 'computer_use_preview';\n}\n\nexport interface ContainerAuto {\n  /**\n   * Automatically creates a container for this request\n   */\n  type: 'container_auto';\n\n  /**\n   * An optional list of uploaded files to make available to your code.\n   */\n  file_ids?: Array<string>;\n\n  /**\n   * The memory limit for the container.\n   */\n  memory_limit?: '1g' | '4g' | '16g' | '64g' | null;\n\n  /**\n   * Network access policy for the container.\n   */\n  network_policy?: ContainerNetworkPolicyDisabled | ContainerNetworkPolicyAllowlist;\n\n  /**\n   * An optional list of skills referenced by id or inline data.\n   */\n  skills?: Array<SkillReference | InlineSkill>;\n}\n\nexport interface ContainerNetworkPolicyAllowlist {\n  /**\n   * A list of allowed domains when type is `allowlist`.\n   */\n  allowed_domains: Array<string>;\n\n  /**\n   * Allow outbound network access only to specified domains. Always `allowlist`.\n   */\n  type: 'allowlist';\n\n  /**\n   * Optional domain-scoped secrets for allowlisted domains.\n   */\n  domain_secrets?: Array<ContainerNetworkPolicyDomainSecret>;\n}\n\nexport interface ContainerNetworkPolicyDisabled {\n  /**\n   * Disable outbound network access. Always `disabled`.\n   */\n  type: 'disabled';\n}\n\nexport interface ContainerNetworkPolicyDomainSecret {\n  /**\n   * The domain associated with the secret.\n   */\n  domain: string;\n\n  /**\n   * The name of the secret to inject for the domain.\n   */\n  name: string;\n\n  /**\n   * The secret value to inject for the domain.\n   */\n  value: string;\n}\n\nexport interface ContainerReference {\n  /**\n   * The ID of the referenced container.\n   */\n  container_id: string;\n\n  /**\n   * References a container created with the /v1/containers endpoint\n   */\n  type: 'container_reference';\n}\n\n/**\n * A custom tool that processes input using a specified format. Learn more about\n * [custom tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)\n */\nexport interface CustomTool {\n  /**\n   * The name of the custom tool, used to identify it in tool calls.\n   */\n  name: string;\n\n  /**\n   * The type of the custom tool. Always `custom`.\n   */\n  type: 'custom';\n\n  /**\n   * Whether this tool should be deferred and discovered via tool search.\n   */\n  defer_loading?: boolean;\n\n  /**\n   * Optional description of the custom tool, used to provide more context.\n   */\n  description?: string;\n\n  /**\n   * The input format for the custom tool. Default is unconstrained text.\n   */\n  format?: Shared.CustomToolInputFormat;\n}\n\n/**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\nexport interface EasyInputMessage {\n  /**\n   * Text, image, or audio input to the model, used to generate a response. Can also\n   * contain previous assistant responses.\n   */\n  content: string | ResponseInputMessageContentList;\n\n  /**\n   * The role of the message input. One of `user`, `assistant`, `system`, or\n   * `developer`.\n   */\n  role: 'user' | 'assistant' | 'system' | 'developer';\n\n  /**\n   * Labels an `assistant` message as intermediate commentary (`commentary`) or the\n   * final answer (`final_answer`). For models like `gpt-5.3-codex` and beyond, when\n   * sending follow-up requests, preserve and resend phase on all assistant messages\n   * — dropping it can degrade performance. Not used for user messages.\n   */\n  phase?: 'commentary' | 'final_answer' | null;\n\n  /**\n   * The type of the message input. Always `message`.\n   */\n  type?: 'message';\n}\n\n/**\n * A tool that searches for relevant content from uploaded files. Learn more about\n * the\n * [file search tool](https://platform.openai.com/docs/guides/tools-file-search).\n */\nexport interface FileSearchTool {\n  /**\n   * The type of the file search tool. Always `file_search`.\n   */\n  type: 'file_search';\n\n  /**\n   * The IDs of the vector stores to search.\n   */\n  vector_store_ids: Array<string>;\n\n  /**\n   * A filter to apply.\n   */\n  filters?: Shared.ComparisonFilter | Shared.CompoundFilter | null;\n\n  /**\n   * The maximum number of results to return. This number should be between 1 and 50\n   * inclusive.\n   */\n  max_num_results?: number;\n\n  /**\n   * Ranking options for search.\n   */\n  ranking_options?: FileSearchTool.RankingOptions;\n}\n\nexport namespace FileSearchTool {\n  /**\n   * Ranking options for search.\n   */\n  export interface RankingOptions {\n    /**\n     * Weights that control how reciprocal rank fusion balances semantic embedding\n     * matches versus sparse keyword matches when hybrid search is enabled.\n     */\n    hybrid_search?: RankingOptions.HybridSearch;\n\n    /**\n     * The ranker to use for the file search.\n     */\n    ranker?: 'auto' | 'default-2024-11-15';\n\n    /**\n     * The score threshold for the file search, a number between 0 and 1. Numbers\n     * closer to 1 will attempt to return only the most relevant results, but may\n     * return fewer results.\n     */\n    score_threshold?: number;\n  }\n\n  export namespace RankingOptions {\n    /**\n     * Weights that control how reciprocal rank fusion balances semantic embedding\n     * matches versus sparse keyword matches when hybrid search is enabled.\n     */\n    export interface HybridSearch {\n      /**\n       * The weight of the embedding in the reciprocal ranking fusion.\n       */\n      embedding_weight: number;\n\n      /**\n       * The weight of the text in the reciprocal ranking fusion.\n       */\n      text_weight: number;\n    }\n  }\n}\n\n/**\n * A tool that allows the model to execute shell commands.\n */\nexport interface FunctionShellTool {\n  /**\n   * The type of the shell tool. Always `shell`.\n   */\n  type: 'shell';\n\n  environment?: ContainerAuto | LocalEnvironment | ContainerReference | null;\n}\n\n/**\n * Defines a function in your own code the model can choose to call. Learn more\n * about\n * [function calling](https://platform.openai.com/docs/guides/function-calling).\n */\nexport interface FunctionTool {\n  /**\n   * The name of the function to call.\n   */\n  name: string;\n\n  /**\n   * A JSON schema object describing the parameters of the function.\n   */\n  parameters: { [key: string]: unknown } | null;\n\n  /**\n   * Whether to enforce strict parameter validation. Default `true`.\n   */\n  strict: boolean | null;\n\n  /**\n   * The type of the function tool. Always `function`.\n   */\n  type: 'function';\n\n  /**\n   * Whether this function is deferred and loaded via tool search.\n   */\n  defer_loading?: boolean;\n\n  /**\n   * A description of the function. Used by the model to determine whether or not to\n   * call the function.\n   */\n  description?: string | null;\n}\n\nexport interface InlineSkill {\n  /**\n   * The description of the skill.\n   */\n  description: string;\n\n  /**\n   * The name of the skill.\n   */\n  name: string;\n\n  /**\n   * Inline skill payload\n   */\n  source: InlineSkillSource;\n\n  /**\n   * Defines an inline skill for this request.\n   */\n  type: 'inline';\n}\n\n/**\n * Inline skill payload\n */\nexport interface InlineSkillSource {\n  /**\n   * Base64-encoded skill zip bundle.\n   */\n  data: string;\n\n  /**\n   * The media type of the inline skill payload. Must be `application/zip`.\n   */\n  media_type: 'application/zip';\n\n  /**\n   * The type of the inline skill source. Must be `base64`.\n   */\n  type: 'base64';\n}\n\nexport interface LocalEnvironment {\n  /**\n   * Use a local computer environment.\n   */\n  type: 'local';\n\n  /**\n   * An optional list of skills.\n   */\n  skills?: Array<LocalSkill>;\n}\n\nexport interface LocalSkill {\n  /**\n   * The description of the skill.\n   */\n  description: string;\n\n  /**\n   * The name of the skill.\n   */\n  name: string;\n\n  /**\n   * The path to the directory containing the skill.\n   */\n  path: string;\n}\n\n/**\n * Groups function/custom tools under a shared namespace.\n */\nexport interface NamespaceTool {\n  /**\n   * A description of the namespace shown to the model.\n   */\n  description: string;\n\n  /**\n   * The namespace name used in tool calls (for example, `crm`).\n   */\n  name: string;\n\n  /**\n   * The function/custom tools available inside this namespace.\n   */\n  tools: Array<NamespaceTool.Function | CustomTool>;\n\n  /**\n   * The type of the tool. Always `namespace`.\n   */\n  type: 'namespace';\n}\n\nexport namespace NamespaceTool {\n  export interface Function {\n    name: string;\n\n    type: 'function';\n\n    /**\n     * Whether this function should be deferred and discovered via tool search.\n     */\n    defer_loading?: boolean;\n\n    description?: string | null;\n\n    parameters?: unknown | null;\n\n    strict?: boolean | null;\n  }\n}\n\nexport interface Response {\n  /**\n   * Unique identifier for this Response.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (in seconds) of when this Response was created.\n   */\n  created_at: number;\n\n  output_text: string;\n\n  /**\n   * An error object returned when the model fails to generate a Response.\n   */\n  error: ResponseError | null;\n\n  /**\n   * Details about why the response is incomplete.\n   */\n  incomplete_details: Response.IncompleteDetails | null;\n\n  /**\n   * A system (or developer) message inserted into the model's context.\n   *\n   * When using along with `previous_response_id`, the instructions from a previous\n   * response will not be carried over to the next response. This makes it simple to\n   * swap out system (or developer) messages in new responses.\n   */\n  instructions: string | Array<ResponseInputItem> | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a\n   * wide range of models with different capabilities, performance characteristics,\n   * and price points. Refer to the\n   * [model guide](https://platform.openai.com/docs/models) to browse and compare\n   * available models.\n   */\n  model: Shared.ResponsesModel;\n\n  /**\n   * The object type of this resource - always set to `response`.\n   */\n  object: 'response';\n\n  /**\n   * An array of content items generated by the model.\n   *\n   * - The length and order of items in the `output` array is dependent on the\n   *   model's response.\n   * - Rather than accessing the first item in the `output` array and assuming it's\n   *   an `assistant` message with the content generated by the model, you might\n   *   consider using the `output_text` property where supported in SDKs.\n   */\n  output: Array<ResponseOutputItem>;\n\n  /**\n   * Whether to allow the model to run tool calls in parallel.\n   */\n  parallel_tool_calls: boolean;\n\n  /**\n   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n   * make the output more random, while lower values like 0.2 will make it more\n   * focused and deterministic. We generally recommend altering this or `top_p` but\n   * not both.\n   */\n  temperature: number | null;\n\n  /**\n   * How the model should select which tool (or tools) to use when generating a\n   * response. See the `tools` parameter to see how to specify which tools the model\n   * can call.\n   */\n  tool_choice:\n    | ToolChoiceOptions\n    | ToolChoiceAllowed\n    | ToolChoiceTypes\n    | ToolChoiceFunction\n    | ToolChoiceMcp\n    | ToolChoiceCustom\n    | ToolChoiceApplyPatch\n    | ToolChoiceShell;\n\n  /**\n   * An array of tools the model may call while generating a response. You can\n   * specify which tool to use by setting the `tool_choice` parameter.\n   *\n   * We support the following categories of tools:\n   *\n   * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n   *   capabilities, like\n   *   [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n   *   [file search](https://platform.openai.com/docs/guides/tools-file-search).\n   *   Learn more about\n   *   [built-in tools](https://platform.openai.com/docs/guides/tools).\n   * - **MCP Tools**: Integrations with third-party systems via custom MCP servers or\n   *   predefined connectors such as Google Drive and SharePoint. Learn more about\n   *   [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).\n   * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n   *   the model to call your own code with strongly typed arguments and outputs.\n   *   Learn more about\n   *   [function calling](https://platform.openai.com/docs/guides/function-calling).\n   *   You can also use custom tools to call your own code.\n   */\n  tools: Array<Tool>;\n\n  /**\n   * An alternative to sampling with temperature, called nucleus sampling, where the\n   * model considers the results of the tokens with top_p probability mass. So 0.1\n   * means only the tokens comprising the top 10% probability mass are considered.\n   *\n   * We generally recommend altering this or `temperature` but not both.\n   */\n  top_p: number | null;\n\n  /**\n   * Whether to run the model response in the background.\n   * [Learn more](https://platform.openai.com/docs/guides/background).\n   */\n  background?: boolean | null;\n\n  /**\n   * Unix timestamp (in seconds) of when this Response was completed. Only present\n   * when the status is `completed`.\n   */\n  completed_at?: number | null;\n\n  /**\n   * The conversation that this response belonged to. Input items and output items\n   * from this response were automatically added to this conversation.\n   */\n  conversation?: Response.Conversation | null;\n\n  /**\n   * An upper bound for the number of tokens that can be generated for a response,\n   * including visible output tokens and\n   * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).\n   */\n  max_output_tokens?: number | null;\n\n  /**\n   * The unique ID of the previous response to the model. Use this to create\n   * multi-turn conversations. Learn more about\n   * [conversation state](https://platform.openai.com/docs/guides/conversation-state).\n   * Cannot be used in conjunction with `conversation`.\n   */\n  previous_response_id?: string | null;\n\n  /**\n   * Reference to a prompt template and its variables.\n   * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n   */\n  prompt?: ResponsePrompt | null;\n\n  /**\n   * Used by OpenAI to cache responses for similar requests to optimize your cache\n   * hit rates. Replaces the `user` field.\n   * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n   */\n  prompt_cache_key?: string;\n\n  /**\n   * The retention policy for the prompt cache. Set to `24h` to enable extended\n   * prompt caching, which keeps cached prefixes active for longer, up to a maximum\n   * of 24 hours.\n   * [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).\n   */\n  prompt_cache_retention?: 'in-memory' | '24h' | null;\n\n  /**\n   * **gpt-5 and o-series models only**\n   *\n   * Configuration options for\n   * [reasoning models](https://platform.openai.com/docs/guides/reasoning).\n   */\n  reasoning?: Shared.Reasoning | null;\n\n  /**\n   * A stable identifier used to help detect users of your application that may be\n   * violating OpenAI's usage policies. The IDs should be a string that uniquely\n   * identifies each user, with a maximum length of 64 characters. We recommend\n   * hashing their username or email address, in order to avoid sending us any\n   * identifying information.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n   */\n  safety_identifier?: string;\n\n  /**\n   * Specifies the latency tier to use for processing the request. This parameter is\n   * relevant for customers subscribed to the scale tier service:\n   *\n   * - If set to 'auto', then the request will be processed with the service tier\n   *   configured in the Project settings. Unless otherwise configured, the Project\n   *   will use 'default'.\n   * - If set to 'default', then the request will be processed with the standard\n   *   pricing and performance for the selected model.\n   * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n   *   '[priority](https://openai.com/api-priority-processing/)', then the request\n   *   will be processed with the corresponding service tier.\n   * - When not set, the default behavior is 'auto'.\n   *\n   * When this parameter is set, the response body will include the `service_tier`\n   * utilized.\n   */\n  service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n  /**\n   * The status of the response generation. One of `completed`, `failed`,\n   * `in_progress`, `cancelled`, `queued`, or `incomplete`.\n   */\n  status?: ResponseStatus;\n\n  /**\n   * Configuration options for a text response from the model. Can be plain text or\n   * structured JSON data. Learn more:\n   *\n   * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n   * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n   */\n  text?: ResponseTextConfig;\n\n  /**\n   * The truncation strategy to use for the model response.\n   *\n   * - `auto`: If the input to this Response exceeds the model's context window size,\n   *   the model will truncate the response to fit the context window by dropping\n   *   items from the beginning of the conversation.\n   * - `disabled` (default): If the input size will exceed the context window size\n   *   for a model, the request will fail with a 400 error.\n   */\n  truncation?: 'auto' | 'disabled' | null;\n\n  /**\n   * Represents token usage details including input tokens, output tokens, a\n   * breakdown of output tokens, and the total tokens used.\n   */\n  usage?: ResponseUsage;\n\n  /**\n   * @deprecated This field is being replaced by `safety_identifier` and\n   * `prompt_cache_key`. Use `prompt_cache_key` instead to maintain caching\n   * optimizations. A stable identifier for your end-users. Used to boost cache hit\n   * rates by better bucketing similar requests and to help OpenAI detect and prevent\n   * abuse.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n   */\n  user?: string;\n}\n\nexport namespace Response {\n  /**\n   * Details about why the response is incomplete.\n   */\n  export interface IncompleteDetails {\n    /**\n     * The reason why the response is incomplete.\n     */\n    reason?: 'max_output_tokens' | 'content_filter';\n  }\n\n  /**\n   * The conversation that this response belonged to. Input items and output items\n   * from this response were automatically added to this conversation.\n   */\n  export interface Conversation {\n    /**\n     * The unique ID of the conversation that this response was associated with.\n     */\n    id: string;\n  }\n}\n\n/**\n * A tool call that applies file diffs by creating, deleting, or updating files.\n */\nexport interface ResponseApplyPatchToolCall {\n  /**\n   * The unique ID of the apply patch tool call. Populated when this item is returned\n   * via API.\n   */\n  id: string;\n\n  /**\n   * The unique ID of the apply patch tool call generated by the model.\n   */\n  call_id: string;\n\n  /**\n   * One of the create_file, delete_file, or update_file operations applied via\n   * apply_patch.\n   */\n  operation:\n    | ResponseApplyPatchToolCall.CreateFile\n    | ResponseApplyPatchToolCall.DeleteFile\n    | ResponseApplyPatchToolCall.UpdateFile;\n\n  /**\n   * The status of the apply patch tool call. One of `in_progress` or `completed`.\n   */\n  status: 'in_progress' | 'completed';\n\n  /**\n   * The type of the item. Always `apply_patch_call`.\n   */\n  type: 'apply_patch_call';\n\n  /**\n   * The ID of the entity that created this tool call.\n   */\n  created_by?: string;\n}\n\nexport namespace ResponseApplyPatchToolCall {\n  /**\n   * Instruction describing how to create a file via the apply_patch tool.\n   */\n  export interface CreateFile {\n    /**\n     * Diff to apply.\n     */\n    diff: string;\n\n    /**\n     * Path of the file to create.\n     */\n    path: string;\n\n    /**\n     * Create a new file with the provided diff.\n     */\n    type: 'create_file';\n  }\n\n  /**\n   * Instruction describing how to delete a file via the apply_patch tool.\n   */\n  export interface DeleteFile {\n    /**\n     * Path of the file to delete.\n     */\n    path: string;\n\n    /**\n     * Delete the specified file.\n     */\n    type: 'delete_file';\n  }\n\n  /**\n   * Instruction describing how to update a file via the apply_patch tool.\n   */\n  export interface UpdateFile {\n    /**\n     * Diff to apply.\n     */\n    diff: string;\n\n    /**\n     * Path of the file to update.\n     */\n    path: string;\n\n    /**\n     * Update an existing file with the provided diff.\n     */\n    type: 'update_file';\n  }\n}\n\n/**\n * The output emitted by an apply patch tool call.\n */\nexport interface ResponseApplyPatchToolCallOutput {\n  /**\n   * The unique ID of the apply patch tool call output. Populated when this item is\n   * returned via API.\n   */\n  id: string;\n\n  /**\n   * The unique ID of the apply patch tool call generated by the model.\n   */\n  call_id: string;\n\n  /**\n   * The status of the apply patch tool call output. One of `completed` or `failed`.\n   */\n  status: 'completed' | 'failed';\n\n  /**\n   * The type of the item. Always `apply_patch_call_output`.\n   */\n  type: 'apply_patch_call_output';\n\n  /**\n   * The ID of the entity that created this tool call output.\n   */\n  created_by?: string;\n\n  /**\n   * Optional textual output returned by the apply patch tool.\n   */\n  output?: string | null;\n}\n\n/**\n * Emitted when there is a partial audio response.\n */\nexport interface ResponseAudioDeltaEvent {\n  /**\n   * A chunk of Base64 encoded response audio bytes.\n   */\n  delta: string;\n\n  /**\n   * A sequence number for this chunk of the stream response.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.audio.delta`.\n   */\n  type: 'response.audio.delta';\n}\n\n/**\n * Emitted when the audio response is complete.\n */\nexport interface ResponseAudioDoneEvent {\n  /**\n   * The sequence number of the delta.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.audio.done`.\n   */\n  type: 'response.audio.done';\n}\n\n/**\n * Emitted when there is a partial transcript of audio.\n */\nexport interface ResponseAudioTranscriptDeltaEvent {\n  /**\n   * The partial transcript of the audio response.\n   */\n  delta: string;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.audio.transcript.delta`.\n   */\n  type: 'response.audio.transcript.delta';\n}\n\n/**\n * Emitted when the full audio transcript is completed.\n */\nexport interface ResponseAudioTranscriptDoneEvent {\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.audio.transcript.done`.\n   */\n  type: 'response.audio.transcript.done';\n}\n\n/**\n * Emitted when a partial code snippet is streamed by the code interpreter.\n */\nexport interface ResponseCodeInterpreterCallCodeDeltaEvent {\n  /**\n   * The partial code snippet being streamed by the code interpreter.\n   */\n  delta: string;\n\n  /**\n   * The unique identifier of the code interpreter tool call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response for which the code is being\n   * streamed.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event, used to order streaming events.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.code_interpreter_call_code.delta`.\n   */\n  type: 'response.code_interpreter_call_code.delta';\n}\n\n/**\n * Emitted when the code snippet is finalized by the code interpreter.\n */\nexport interface ResponseCodeInterpreterCallCodeDoneEvent {\n  /**\n   * The final code snippet output by the code interpreter.\n   */\n  code: string;\n\n  /**\n   * The unique identifier of the code interpreter tool call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response for which the code is finalized.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event, used to order streaming events.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.code_interpreter_call_code.done`.\n   */\n  type: 'response.code_interpreter_call_code.done';\n}\n\n/**\n * Emitted when the code interpreter call is completed.\n */\nexport interface ResponseCodeInterpreterCallCompletedEvent {\n  /**\n   * The unique identifier of the code interpreter tool call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response for which the code interpreter call\n   * is completed.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event, used to order streaming events.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.code_interpreter_call.completed`.\n   */\n  type: 'response.code_interpreter_call.completed';\n}\n\n/**\n * Emitted when a code interpreter call is in progress.\n */\nexport interface ResponseCodeInterpreterCallInProgressEvent {\n  /**\n   * The unique identifier of the code interpreter tool call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response for which the code interpreter call\n   * is in progress.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event, used to order streaming events.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.code_interpreter_call.in_progress`.\n   */\n  type: 'response.code_interpreter_call.in_progress';\n}\n\n/**\n * Emitted when the code interpreter is actively interpreting the code snippet.\n */\nexport interface ResponseCodeInterpreterCallInterpretingEvent {\n  /**\n   * The unique identifier of the code interpreter tool call item.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response for which the code interpreter is\n   * interpreting code.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event, used to order streaming events.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.code_interpreter_call.interpreting`.\n   */\n  type: 'response.code_interpreter_call.interpreting';\n}\n\n/**\n * A tool call to run code.\n */\nexport interface ResponseCodeInterpreterToolCall {\n  /**\n   * The unique ID of the code interpreter tool call.\n   */\n  id: string;\n\n  /**\n   * The code to run, or null if not available.\n   */\n  code: string | null;\n\n  /**\n   * The ID of the container used to run the code.\n   */\n  container_id: string;\n\n  /**\n   * The outputs generated by the code interpreter, such as logs or images. Can be\n   * null if no outputs are available.\n   */\n  outputs: Array<ResponseCodeInterpreterToolCall.Logs | ResponseCodeInterpreterToolCall.Image> | null;\n\n  /**\n   * The status of the code interpreter tool call. Valid values are `in_progress`,\n   * `completed`, `incomplete`, `interpreting`, and `failed`.\n   */\n  status: 'in_progress' | 'completed' | 'incomplete' | 'interpreting' | 'failed';\n\n  /**\n   * The type of the code interpreter tool call. Always `code_interpreter_call`.\n   */\n  type: 'code_interpreter_call';\n}\n\nexport namespace ResponseCodeInterpreterToolCall {\n  /**\n   * The logs output from the code interpreter.\n   */\n  export interface Logs {\n    /**\n     * The logs output from the code interpreter.\n     */\n    logs: string;\n\n    /**\n     * The type of the output. Always `logs`.\n     */\n    type: 'logs';\n  }\n\n  /**\n   * The image output from the code interpreter.\n   */\n  export interface Image {\n    /**\n     * The type of the output. Always `image`.\n     */\n    type: 'image';\n\n    /**\n     * The URL of the image output from the code interpreter.\n     */\n    url: string;\n  }\n}\n\n/**\n * A compaction item generated by the\n * [`v1/responses/compact` API](https://platform.openai.com/docs/api-reference/responses/compact).\n */\nexport interface ResponseCompactionItem {\n  /**\n   * The unique ID of the compaction item.\n   */\n  id: string;\n\n  /**\n   * The encrypted content that was produced by compaction.\n   */\n  encrypted_content: string;\n\n  /**\n   * The type of the item. Always `compaction`.\n   */\n  type: 'compaction';\n\n  /**\n   * The identifier of the actor that created the item.\n   */\n  created_by?: string;\n}\n\n/**\n * A compaction item generated by the\n * [`v1/responses/compact` API](https://platform.openai.com/docs/api-reference/responses/compact).\n */\nexport interface ResponseCompactionItemParam {\n  /**\n   * The encrypted content of the compaction summary.\n   */\n  encrypted_content: string;\n\n  /**\n   * The type of the item. Always `compaction`.\n   */\n  type: 'compaction';\n\n  /**\n   * The ID of the compaction item.\n   */\n  id?: string | null;\n}\n\n/**\n * Emitted when the model response is complete.\n */\nexport interface ResponseCompletedEvent {\n  /**\n   * Properties of the completed response.\n   */\n  response: Response;\n\n  /**\n   * The sequence number for this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.completed`.\n   */\n  type: 'response.completed';\n}\n\n/**\n * A tool call to a computer use tool. See the\n * [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use)\n * for more information.\n */\nexport interface ResponseComputerToolCall {\n  /**\n   * The unique ID of the computer call.\n   */\n  id: string;\n\n  /**\n   * An identifier used when responding to the tool call with output.\n   */\n  call_id: string;\n\n  /**\n   * The pending safety checks for the computer call.\n   */\n  pending_safety_checks: Array<ResponseComputerToolCall.PendingSafetyCheck>;\n\n  /**\n   * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n   * Populated when items are returned via API.\n   */\n  status: 'in_progress' | 'completed' | 'incomplete';\n\n  /**\n   * The type of the computer call. Always `computer_call`.\n   */\n  type: 'computer_call';\n\n  /**\n   * A click action.\n   */\n  action?:\n    | ResponseComputerToolCall.Click\n    | ResponseComputerToolCall.DoubleClick\n    | ResponseComputerToolCall.Drag\n    | ResponseComputerToolCall.Keypress\n    | ResponseComputerToolCall.Move\n    | ResponseComputerToolCall.Screenshot\n    | ResponseComputerToolCall.Scroll\n    | ResponseComputerToolCall.Type\n    | ResponseComputerToolCall.Wait;\n\n  /**\n   * Flattened batched actions for `computer_use`. Each action includes an `type`\n   * discriminator and action-specific fields.\n   */\n  actions?: ComputerActionList;\n}\n\nexport namespace ResponseComputerToolCall {\n  /**\n   * A pending safety check for the computer call.\n   */\n  export interface PendingSafetyCheck {\n    /**\n     * The ID of the pending safety check.\n     */\n    id: string;\n\n    /**\n     * The type of the pending safety check.\n     */\n    code?: string | null;\n\n    /**\n     * Details about the pending safety check.\n     */\n    message?: string | null;\n  }\n\n  /**\n   * A click action.\n   */\n  export interface Click {\n    /**\n     * Indicates which mouse button was pressed during the click. One of `left`,\n     * `right`, `wheel`, `back`, or `forward`.\n     */\n    button: 'left' | 'right' | 'wheel' | 'back' | 'forward';\n\n    /**\n     * Specifies the event type. For a click action, this property is always `click`.\n     */\n    type: 'click';\n\n    /**\n     * The x-coordinate where the click occurred.\n     */\n    x: number;\n\n    /**\n     * The y-coordinate where the click occurred.\n     */\n    y: number;\n  }\n\n  /**\n   * A double click action.\n   */\n  export interface DoubleClick {\n    /**\n     * Specifies the event type. For a double click action, this property is always set\n     * to `double_click`.\n     */\n    type: 'double_click';\n\n    /**\n     * The x-coordinate where the double click occurred.\n     */\n    x: number;\n\n    /**\n     * The y-coordinate where the double click occurred.\n     */\n    y: number;\n  }\n\n  /**\n   * A drag action.\n   */\n  export interface Drag {\n    /**\n     * An array of coordinates representing the path of the drag action. Coordinates\n     * will appear as an array of objects, eg\n     *\n     * ```\n     * [\n     *   { x: 100, y: 200 },\n     *   { x: 200, y: 300 }\n     * ]\n     * ```\n     */\n    path: Array<Drag.Path>;\n\n    /**\n     * Specifies the event type. For a drag action, this property is always set to\n     * `drag`.\n     */\n    type: 'drag';\n  }\n\n  export namespace Drag {\n    /**\n     * An x/y coordinate pair, e.g. `{ x: 100, y: 200 }`.\n     */\n    export interface Path {\n      /**\n       * The x-coordinate.\n       */\n      x: number;\n\n      /**\n       * The y-coordinate.\n       */\n      y: number;\n    }\n  }\n\n  /**\n   * A collection of keypresses the model would like to perform.\n   */\n  export interface Keypress {\n    /**\n     * The combination of keys the model is requesting to be pressed. This is an array\n     * of strings, each representing a key.\n     */\n    keys: Array<string>;\n\n    /**\n     * Specifies the event type. For a keypress action, this property is always set to\n     * `keypress`.\n     */\n    type: 'keypress';\n  }\n\n  /**\n   * A mouse move action.\n   */\n  export interface Move {\n    /**\n     * Specifies the event type. For a move action, this property is always set to\n     * `move`.\n     */\n    type: 'move';\n\n    /**\n     * The x-coordinate to move to.\n     */\n    x: number;\n\n    /**\n     * The y-coordinate to move to.\n     */\n    y: number;\n  }\n\n  /**\n   * A screenshot action.\n   */\n  export interface Screenshot {\n    /**\n     * Specifies the event type. For a screenshot action, this property is always set\n     * to `screenshot`.\n     */\n    type: 'screenshot';\n  }\n\n  /**\n   * A scroll action.\n   */\n  export interface Scroll {\n    /**\n     * The horizontal scroll distance.\n     */\n    scroll_x: number;\n\n    /**\n     * The vertical scroll distance.\n     */\n    scroll_y: number;\n\n    /**\n     * Specifies the event type. For a scroll action, this property is always set to\n     * `scroll`.\n     */\n    type: 'scroll';\n\n    /**\n     * The x-coordinate where the scroll occurred.\n     */\n    x: number;\n\n    /**\n     * The y-coordinate where the scroll occurred.\n     */\n    y: number;\n  }\n\n  /**\n   * An action to type in text.\n   */\n  export interface Type {\n    /**\n     * The text to type.\n     */\n    text: string;\n\n    /**\n     * Specifies the event type. For a type action, this property is always set to\n     * `type`.\n     */\n    type: 'type';\n  }\n\n  /**\n   * A wait action.\n   */\n  export interface Wait {\n    /**\n     * Specifies the event type. For a wait action, this property is always set to\n     * `wait`.\n     */\n    type: 'wait';\n  }\n}\n\nexport interface ResponseComputerToolCallOutputItem {\n  /**\n   * The unique ID of the computer call tool output.\n   */\n  id: string;\n\n  /**\n   * The ID of the computer tool call that produced the output.\n   */\n  call_id: string;\n\n  /**\n   * A computer screenshot image used with the computer use tool.\n   */\n  output: ResponseComputerToolCallOutputScreenshot;\n\n  /**\n   * The type of the computer tool call output. Always `computer_call_output`.\n   */\n  type: 'computer_call_output';\n\n  /**\n   * The safety checks reported by the API that have been acknowledged by the\n   * developer.\n   */\n  acknowledged_safety_checks?: Array<ResponseComputerToolCallOutputItem.AcknowledgedSafetyCheck>;\n\n  /**\n   * The status of the message input. One of `in_progress`, `completed`, or\n   * `incomplete`. Populated when input items are returned via API.\n   */\n  status?: 'in_progress' | 'completed' | 'incomplete';\n}\n\nexport namespace ResponseComputerToolCallOutputItem {\n  /**\n   * A pending safety check for the computer call.\n   */\n  export interface AcknowledgedSafetyCheck {\n    /**\n     * The ID of the pending safety check.\n     */\n    id: string;\n\n    /**\n     * The type of the pending safety check.\n     */\n    code?: string | null;\n\n    /**\n     * Details about the pending safety check.\n     */\n    message?: string | null;\n  }\n}\n\n/**\n * A computer screenshot image used with the computer use tool.\n */\nexport interface ResponseComputerToolCallOutputScreenshot {\n  /**\n   * Specifies the event type. For a computer screenshot, this property is always set\n   * to `computer_screenshot`.\n   */\n  type: 'computer_screenshot';\n\n  /**\n   * The identifier of an uploaded file that contains the screenshot.\n   */\n  file_id?: string;\n\n  /**\n   * The URL of the screenshot image.\n   */\n  image_url?: string;\n}\n\n/**\n * Represents a container created with /v1/containers.\n */\nexport interface ResponseContainerReference {\n  container_id: string;\n\n  /**\n   * The environment type. Always `container_reference`.\n   */\n  type: 'container_reference';\n}\n\n/**\n * Multi-modal input and output contents.\n */\nexport type ResponseContent =\n  | ResponseInputText\n  | ResponseInputImage\n  | ResponseInputFile\n  | ResponseOutputText\n  | ResponseOutputRefusal\n  | ResponseContent.ReasoningTextContent;\n\nexport namespace ResponseContent {\n  /**\n   * Reasoning text from the model.\n   */\n  export interface ReasoningTextContent {\n    /**\n     * The reasoning text from the model.\n     */\n    text: string;\n\n    /**\n     * The type of the reasoning text. Always `reasoning_text`.\n     */\n    type: 'reasoning_text';\n  }\n}\n\n/**\n * Emitted when a new content part is added.\n */\nexport interface ResponseContentPartAddedEvent {\n  /**\n   * The index of the content part that was added.\n   */\n  content_index: number;\n\n  /**\n   * The ID of the output item that the content part was added to.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the content part was added to.\n   */\n  output_index: number;\n\n  /**\n   * The content part that was added.\n   */\n  part: ResponseOutputText | ResponseOutputRefusal | ResponseContentPartAddedEvent.ReasoningText;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.content_part.added`.\n   */\n  type: 'response.content_part.added';\n}\n\nexport namespace ResponseContentPartAddedEvent {\n  /**\n   * Reasoning text from the model.\n   */\n  export interface ReasoningText {\n    /**\n     * The reasoning text from the model.\n     */\n    text: string;\n\n    /**\n     * The type of the reasoning text. Always `reasoning_text`.\n     */\n    type: 'reasoning_text';\n  }\n}\n\n/**\n * Emitted when a content part is done.\n */\nexport interface ResponseContentPartDoneEvent {\n  /**\n   * The index of the content part that is done.\n   */\n  content_index: number;\n\n  /**\n   * The ID of the output item that the content part was added to.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the content part was added to.\n   */\n  output_index: number;\n\n  /**\n   * The content part that is done.\n   */\n  part: ResponseOutputText | ResponseOutputRefusal | ResponseContentPartDoneEvent.ReasoningText;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.content_part.done`.\n   */\n  type: 'response.content_part.done';\n}\n\nexport namespace ResponseContentPartDoneEvent {\n  /**\n   * Reasoning text from the model.\n   */\n  export interface ReasoningText {\n    /**\n     * The reasoning text from the model.\n     */\n    text: string;\n\n    /**\n     * The type of the reasoning text. Always `reasoning_text`.\n     */\n    type: 'reasoning_text';\n  }\n}\n\n/**\n * The conversation that this response belongs to.\n */\nexport interface ResponseConversationParam {\n  /**\n   * The unique ID of the conversation.\n   */\n  id: string;\n}\n\n/**\n * An event that is emitted when a response is created.\n */\nexport interface ResponseCreatedEvent {\n  /**\n   * The response that was created.\n   */\n  response: Response;\n\n  /**\n   * The sequence number for this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.created`.\n   */\n  type: 'response.created';\n}\n\n/**\n * A call to a custom tool created by the model.\n */\nexport interface ResponseCustomToolCall {\n  /**\n   * An identifier used to map this custom tool call to a tool call output.\n   */\n  call_id: string;\n\n  /**\n   * The input for the custom tool call generated by the model.\n   */\n  input: string;\n\n  /**\n   * The name of the custom tool being called.\n   */\n  name: string;\n\n  /**\n   * The type of the custom tool call. Always `custom_tool_call`.\n   */\n  type: 'custom_tool_call';\n\n  /**\n   * The unique ID of the custom tool call in the OpenAI platform.\n   */\n  id?: string;\n\n  /**\n   * The namespace of the custom tool being called.\n   */\n  namespace?: string;\n}\n\n/**\n * Event representing a delta (partial update) to the input of a custom tool call.\n */\nexport interface ResponseCustomToolCallInputDeltaEvent {\n  /**\n   * The incremental input data (delta) for the custom tool call.\n   */\n  delta: string;\n\n  /**\n   * Unique identifier for the API item associated with this event.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output this delta applies to.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The event type identifier.\n   */\n  type: 'response.custom_tool_call_input.delta';\n}\n\n/**\n * Event indicating that input for a custom tool call is complete.\n */\nexport interface ResponseCustomToolCallInputDoneEvent {\n  /**\n   * The complete input data for the custom tool call.\n   */\n  input: string;\n\n  /**\n   * Unique identifier for the API item associated with this event.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output this event applies to.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The event type identifier.\n   */\n  type: 'response.custom_tool_call_input.done';\n}\n\n/**\n * The output of a custom tool call from your code, being sent back to the model.\n */\nexport interface ResponseCustomToolCallOutput {\n  /**\n   * The call ID, used to map this custom tool call output to a custom tool call.\n   */\n  call_id: string;\n\n  /**\n   * The output from the custom tool call generated by your code. Can be a string or\n   * an list of output content.\n   */\n  output: string | Array<ResponseInputText | ResponseInputImage | ResponseInputFile>;\n\n  /**\n   * The type of the custom tool call output. Always `custom_tool_call_output`.\n   */\n  type: 'custom_tool_call_output';\n\n  /**\n   * The unique ID of the custom tool call output in the OpenAI platform.\n   */\n  id?: string;\n}\n\n/**\n * An error object returned when the model fails to generate a Response.\n */\nexport interface ResponseError {\n  /**\n   * The error code for the response.\n   */\n  code:\n    | 'server_error'\n    | 'rate_limit_exceeded'\n    | 'invalid_prompt'\n    | 'vector_store_timeout'\n    | 'invalid_image'\n    | 'invalid_image_format'\n    | 'invalid_base64_image'\n    | 'invalid_image_url'\n    | 'image_too_large'\n    | 'image_too_small'\n    | 'image_parse_error'\n    | 'image_content_policy_violation'\n    | 'invalid_image_mode'\n    | 'image_file_too_large'\n    | 'unsupported_image_media_type'\n    | 'empty_image_file'\n    | 'failed_to_download_image'\n    | 'image_file_not_found';\n\n  /**\n   * A human-readable description of the error.\n   */\n  message: string;\n}\n\n/**\n * Emitted when an error occurs.\n */\nexport interface ResponseErrorEvent {\n  /**\n   * The error code.\n   */\n  code: string | null;\n\n  /**\n   * The error message.\n   */\n  message: string;\n\n  /**\n   * The error parameter.\n   */\n  param: string | null;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `error`.\n   */\n  type: 'error';\n}\n\n/**\n * An event that is emitted when a response fails.\n */\nexport interface ResponseFailedEvent {\n  /**\n   * The response that failed.\n   */\n  response: Response;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.failed`.\n   */\n  type: 'response.failed';\n}\n\n/**\n * Emitted when a file search call is completed (results found).\n */\nexport interface ResponseFileSearchCallCompletedEvent {\n  /**\n   * The ID of the output item that the file search call is initiated.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the file search call is initiated.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.file_search_call.completed`.\n   */\n  type: 'response.file_search_call.completed';\n}\n\n/**\n * Emitted when a file search call is initiated.\n */\nexport interface ResponseFileSearchCallInProgressEvent {\n  /**\n   * The ID of the output item that the file search call is initiated.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the file search call is initiated.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.file_search_call.in_progress`.\n   */\n  type: 'response.file_search_call.in_progress';\n}\n\n/**\n * Emitted when a file search is currently searching.\n */\nexport interface ResponseFileSearchCallSearchingEvent {\n  /**\n   * The ID of the output item that the file search call is initiated.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the file search call is searching.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.file_search_call.searching`.\n   */\n  type: 'response.file_search_call.searching';\n}\n\n/**\n * The results of a file search tool call. See the\n * [file search guide](https://platform.openai.com/docs/guides/tools-file-search)\n * for more information.\n */\nexport interface ResponseFileSearchToolCall {\n  /**\n   * The unique ID of the file search tool call.\n   */\n  id: string;\n\n  /**\n   * The queries used to search for files.\n   */\n  queries: Array<string>;\n\n  /**\n   * The status of the file search tool call. One of `in_progress`, `searching`,\n   * `incomplete` or `failed`,\n   */\n  status: 'in_progress' | 'searching' | 'completed' | 'incomplete' | 'failed';\n\n  /**\n   * The type of the file search tool call. Always `file_search_call`.\n   */\n  type: 'file_search_call';\n\n  /**\n   * The results of the file search tool call.\n   */\n  results?: Array<ResponseFileSearchToolCall.Result> | null;\n}\n\nexport namespace ResponseFileSearchToolCall {\n  export interface Result {\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard. Keys are strings with a maximum\n     * length of 64 characters. Values are strings with a maximum length of 512\n     * characters, booleans, or numbers.\n     */\n    attributes?: { [key: string]: string | number | boolean } | null;\n\n    /**\n     * The unique ID of the file.\n     */\n    file_id?: string;\n\n    /**\n     * The name of the file.\n     */\n    filename?: string;\n\n    /**\n     * The relevance score of the file - a value between 0 and 1.\n     */\n    score?: number;\n\n    /**\n     * The text that was retrieved from the file.\n     */\n    text?: string;\n  }\n}\n\n/**\n * An object specifying the format that the model must output.\n *\n * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n * ensures the model will match your supplied JSON schema. Learn more in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * The default format is `{ \"type\": \"text\" }` with no additional options.\n *\n * **Not recommended for gpt-4o and newer models:**\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\nexport type ResponseFormatTextConfig =\n  | Shared.ResponseFormatText\n  | ResponseFormatTextJSONSchemaConfig\n  | Shared.ResponseFormatJSONObject;\n\n/**\n * JSON Schema response format. Used to generate structured JSON responses. Learn\n * more about\n * [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).\n */\nexport interface ResponseFormatTextJSONSchemaConfig {\n  /**\n   * The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores\n   * and dashes, with a maximum length of 64.\n   */\n  name: string;\n\n  /**\n   * The schema for the response format, described as a JSON Schema object. Learn how\n   * to build JSON schemas [here](https://json-schema.org/).\n   */\n  schema: { [key: string]: unknown };\n\n  /**\n   * The type of response format being defined. Always `json_schema`.\n   */\n  type: 'json_schema';\n\n  /**\n   * A description of what the response format is for, used by the model to determine\n   * how to respond in the format.\n   */\n  description?: string;\n\n  /**\n   * Whether to enable strict schema adherence when generating the output. If set to\n   * true, the model will always follow the exact schema defined in the `schema`\n   * field. Only a subset of JSON Schema is supported when `strict` is `true`. To\n   * learn more, read the\n   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n   */\n  strict?: boolean | null;\n}\n\n/**\n * Emitted when there is a partial function-call arguments delta.\n */\nexport interface ResponseFunctionCallArgumentsDeltaEvent {\n  /**\n   * The function-call arguments delta that is added.\n   */\n  delta: string;\n\n  /**\n   * The ID of the output item that the function-call arguments delta is added to.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the function-call arguments delta is added to.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.function_call_arguments.delta`.\n   */\n  type: 'response.function_call_arguments.delta';\n}\n\n/**\n * Emitted when function-call arguments are finalized.\n */\nexport interface ResponseFunctionCallArgumentsDoneEvent {\n  /**\n   * The function-call arguments.\n   */\n  arguments: string;\n\n  /**\n   * The ID of the item.\n   */\n  item_id: string;\n\n  /**\n   * The name of the function that was called.\n   */\n  name: string;\n\n  /**\n   * The index of the output item.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  type: 'response.function_call_arguments.done';\n}\n\n/**\n * A piece of message content, such as text, an image, or a file.\n */\nexport type ResponseFunctionCallOutputItem =\n  | ResponseInputTextContent\n  | ResponseInputImageContent\n  | ResponseInputFileContent;\n\n/**\n * An array of content outputs (text, image, file) for the function tool call.\n */\nexport type ResponseFunctionCallOutputItemList = Array<ResponseFunctionCallOutputItem>;\n\n/**\n * Captured stdout and stderr for a portion of a shell tool call output.\n */\nexport interface ResponseFunctionShellCallOutputContent {\n  /**\n   * The exit or timeout outcome associated with this shell call.\n   */\n  outcome: ResponseFunctionShellCallOutputContent.Timeout | ResponseFunctionShellCallOutputContent.Exit;\n\n  /**\n   * Captured stderr output for the shell call.\n   */\n  stderr: string;\n\n  /**\n   * Captured stdout output for the shell call.\n   */\n  stdout: string;\n}\n\nexport namespace ResponseFunctionShellCallOutputContent {\n  /**\n   * Indicates that the shell call exceeded its configured time limit.\n   */\n  export interface Timeout {\n    /**\n     * The outcome type. Always `timeout`.\n     */\n    type: 'timeout';\n  }\n\n  /**\n   * Indicates that the shell commands finished and returned an exit code.\n   */\n  export interface Exit {\n    /**\n     * The exit code returned by the shell process.\n     */\n    exit_code: number;\n\n    /**\n     * The outcome type. Always `exit`.\n     */\n    type: 'exit';\n  }\n}\n\n/**\n * A tool call that executes one or more shell commands in a managed environment.\n */\nexport interface ResponseFunctionShellToolCall {\n  /**\n   * The unique ID of the shell tool call. Populated when this item is returned via\n   * API.\n   */\n  id: string;\n\n  /**\n   * The shell commands and limits that describe how to run the tool call.\n   */\n  action: ResponseFunctionShellToolCall.Action;\n\n  /**\n   * The unique ID of the shell tool call generated by the model.\n   */\n  call_id: string;\n\n  /**\n   * Represents the use of a local environment to perform shell actions.\n   */\n  environment: ResponseLocalEnvironment | ResponseContainerReference | null;\n\n  /**\n   * The status of the shell call. One of `in_progress`, `completed`, or\n   * `incomplete`.\n   */\n  status: 'in_progress' | 'completed' | 'incomplete';\n\n  /**\n   * The type of the item. Always `shell_call`.\n   */\n  type: 'shell_call';\n\n  /**\n   * The ID of the entity that created this tool call.\n   */\n  created_by?: string;\n}\n\nexport namespace ResponseFunctionShellToolCall {\n  /**\n   * The shell commands and limits that describe how to run the tool call.\n   */\n  export interface Action {\n    commands: Array<string>;\n\n    /**\n     * Optional maximum number of characters to return from each command.\n     */\n    max_output_length: number | null;\n\n    /**\n     * Optional timeout in milliseconds for the commands.\n     */\n    timeout_ms: number | null;\n  }\n}\n\n/**\n * The output of a shell tool call that was emitted.\n */\nexport interface ResponseFunctionShellToolCallOutput {\n  /**\n   * The unique ID of the shell call output. Populated when this item is returned via\n   * API.\n   */\n  id: string;\n\n  /**\n   * The unique ID of the shell tool call generated by the model.\n   */\n  call_id: string;\n\n  /**\n   * The maximum length of the shell command output. This is generated by the model\n   * and should be passed back with the raw output.\n   */\n  max_output_length: number | null;\n\n  /**\n   * An array of shell call output contents\n   */\n  output: Array<ResponseFunctionShellToolCallOutput.Output>;\n\n  /**\n   * The status of the shell call output. One of `in_progress`, `completed`, or\n   * `incomplete`.\n   */\n  status: 'in_progress' | 'completed' | 'incomplete';\n\n  /**\n   * The type of the shell call output. Always `shell_call_output`.\n   */\n  type: 'shell_call_output';\n\n  /**\n   * The identifier of the actor that created the item.\n   */\n  created_by?: string;\n}\n\nexport namespace ResponseFunctionShellToolCallOutput {\n  /**\n   * The content of a shell tool call output that was emitted.\n   */\n  export interface Output {\n    /**\n     * Represents either an exit outcome (with an exit code) or a timeout outcome for a\n     * shell call output chunk.\n     */\n    outcome: Output.Timeout | Output.Exit;\n\n    /**\n     * The standard error output that was captured.\n     */\n    stderr: string;\n\n    /**\n     * The standard output that was captured.\n     */\n    stdout: string;\n\n    /**\n     * The identifier of the actor that created the item.\n     */\n    created_by?: string;\n  }\n\n  export namespace Output {\n    /**\n     * Indicates that the shell call exceeded its configured time limit.\n     */\n    export interface Timeout {\n      /**\n       * The outcome type. Always `timeout`.\n       */\n      type: 'timeout';\n    }\n\n    /**\n     * Indicates that the shell commands finished and returned an exit code.\n     */\n    export interface Exit {\n      /**\n       * Exit code from the shell process.\n       */\n      exit_code: number;\n\n      /**\n       * The outcome type. Always `exit`.\n       */\n      type: 'exit';\n    }\n  }\n}\n\n/**\n * A tool call to run a function. See the\n * [function calling guide](https://platform.openai.com/docs/guides/function-calling)\n * for more information.\n */\nexport interface ResponseFunctionToolCall {\n  /**\n   * A JSON string of the arguments to pass to the function.\n   */\n  arguments: string;\n\n  /**\n   * The unique ID of the function tool call generated by the model.\n   */\n  call_id: string;\n\n  /**\n   * The name of the function to run.\n   */\n  name: string;\n\n  /**\n   * The type of the function tool call. Always `function_call`.\n   */\n  type: 'function_call';\n\n  /**\n   * The unique ID of the function tool call.\n   */\n  id?: string;\n\n  /**\n   * The namespace of the function to run.\n   */\n  namespace?: string;\n\n  /**\n   * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n   * Populated when items are returned via API.\n   */\n  status?: 'in_progress' | 'completed' | 'incomplete';\n}\n\n/**\n * A tool call to run a function. See the\n * [function calling guide](https://platform.openai.com/docs/guides/function-calling)\n * for more information.\n */\nexport interface ResponseFunctionToolCallItem extends ResponseFunctionToolCall {\n  /**\n   * The unique ID of the function tool call.\n   */\n  id: string;\n}\n\nexport interface ResponseFunctionToolCallOutputItem {\n  /**\n   * The unique ID of the function call tool output.\n   */\n  id: string;\n\n  /**\n   * The unique ID of the function tool call generated by the model.\n   */\n  call_id: string;\n\n  /**\n   * The output from the function call generated by your code. Can be a string or an\n   * list of output content.\n   */\n  output: string | Array<ResponseInputText | ResponseInputImage | ResponseInputFile>;\n\n  /**\n   * The type of the function tool call output. Always `function_call_output`.\n   */\n  type: 'function_call_output';\n\n  /**\n   * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n   * Populated when items are returned via API.\n   */\n  status?: 'in_progress' | 'completed' | 'incomplete';\n}\n\n/**\n * The results of a web search tool call. See the\n * [web search guide](https://platform.openai.com/docs/guides/tools-web-search) for\n * more information.\n */\nexport interface ResponseFunctionWebSearch {\n  /**\n   * The unique ID of the web search tool call.\n   */\n  id: string;\n\n  /**\n   * An object describing the specific action taken in this web search call. Includes\n   * details on how the model used the web (search, open_page, find_in_page).\n   */\n  action:\n    | ResponseFunctionWebSearch.Search\n    | ResponseFunctionWebSearch.OpenPage\n    | ResponseFunctionWebSearch.Find;\n\n  /**\n   * The status of the web search tool call.\n   */\n  status: 'in_progress' | 'searching' | 'completed' | 'failed';\n\n  /**\n   * The type of the web search tool call. Always `web_search_call`.\n   */\n  type: 'web_search_call';\n}\n\nexport namespace ResponseFunctionWebSearch {\n  /**\n   * Action type \"search\" - Performs a web search query.\n   */\n  export interface Search {\n    /**\n     * [DEPRECATED] The search query.\n     */\n    query: string;\n\n    /**\n     * The action type.\n     */\n    type: 'search';\n\n    /**\n     * The search queries.\n     */\n    queries?: Array<string>;\n\n    /**\n     * The sources used in the search.\n     */\n    sources?: Array<Search.Source>;\n  }\n\n  export namespace Search {\n    /**\n     * A source used in the search.\n     */\n    export interface Source {\n      /**\n       * The type of source. Always `url`.\n       */\n      type: 'url';\n\n      /**\n       * The URL of the source.\n       */\n      url: string;\n    }\n  }\n\n  /**\n   * Action type \"open_page\" - Opens a specific URL from search results.\n   */\n  export interface OpenPage {\n    /**\n     * The action type.\n     */\n    type: 'open_page';\n\n    /**\n     * The URL opened by the model.\n     */\n    url?: string | null;\n  }\n\n  /**\n   * Action type \"find_in_page\": Searches for a pattern within a loaded page.\n   */\n  export interface Find {\n    /**\n     * The pattern or text to search for within the page.\n     */\n    pattern: string;\n\n    /**\n     * The action type.\n     */\n    type: 'find_in_page';\n\n    /**\n     * The URL of the page searched for the pattern.\n     */\n    url: string;\n  }\n}\n\n/**\n * Emitted when an image generation tool call has completed and the final image is\n * available.\n */\nexport interface ResponseImageGenCallCompletedEvent {\n  /**\n   * The unique identifier of the image generation item being processed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response's output array.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.image_generation_call.completed'.\n   */\n  type: 'response.image_generation_call.completed';\n}\n\n/**\n * Emitted when an image generation tool call is actively generating an image\n * (intermediate state).\n */\nexport interface ResponseImageGenCallGeneratingEvent {\n  /**\n   * The unique identifier of the image generation item being processed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response's output array.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of the image generation item being processed.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.image_generation_call.generating'.\n   */\n  type: 'response.image_generation_call.generating';\n}\n\n/**\n * Emitted when an image generation tool call is in progress.\n */\nexport interface ResponseImageGenCallInProgressEvent {\n  /**\n   * The unique identifier of the image generation item being processed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response's output array.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of the image generation item being processed.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.image_generation_call.in_progress'.\n   */\n  type: 'response.image_generation_call.in_progress';\n}\n\n/**\n * Emitted when a partial image is available during image generation streaming.\n */\nexport interface ResponseImageGenCallPartialImageEvent {\n  /**\n   * The unique identifier of the image generation item being processed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response's output array.\n   */\n  output_index: number;\n\n  /**\n   * Base64-encoded partial image data, suitable for rendering as an image.\n   */\n  partial_image_b64: string;\n\n  /**\n   * 0-based index for the partial image (backend is 1-based, but this is 0-based for\n   * the user).\n   */\n  partial_image_index: number;\n\n  /**\n   * The sequence number of the image generation item being processed.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.image_generation_call.partial_image'.\n   */\n  type: 'response.image_generation_call.partial_image';\n}\n\n/**\n * Emitted when the response is in progress.\n */\nexport interface ResponseInProgressEvent {\n  /**\n   * The response that is in progress.\n   */\n  response: Response;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.in_progress`.\n   */\n  type: 'response.in_progress';\n}\n\n/**\n * Specify additional output data to include in the model response. Currently\n * supported values are:\n *\n * - `web_search_call.action.sources`: Include the sources of the web search tool\n *   call.\n * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n *   in code interpreter tool call items.\n * - `computer_call_output.output.image_url`: Include image urls from the computer\n *   call output.\n * - `file_search_call.results`: Include the search results of the file search tool\n *   call.\n * - `message.input_image.image_url`: Include image urls from the input message.\n * - `computer_call_output.output.image_url`: Include image urls from the computer\n *   call output.\n * - `reasoning.encrypted_content`: Includes an encrypted version of reasoning\n *   tokens in reasoning item outputs. This enables reasoning items to be used in\n *   multi-turn conversations when using the Responses API statelessly (like when\n *   the `store` parameter is set to `false`, or when an organization is enrolled\n *   in the zero data retention program).\n * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n *   in code interpreter tool call items.\n */\nexport type ResponseIncludable =\n  | 'file_search_call.results'\n  | 'web_search_call.results'\n  | 'web_search_call.action.sources'\n  | 'message.input_image.image_url'\n  | 'computer_call_output.output.image_url'\n  | 'code_interpreter_call.outputs'\n  | 'reasoning.encrypted_content'\n  | 'message.output_text.logprobs';\n\n/**\n * An event that is emitted when a response finishes as incomplete.\n */\nexport interface ResponseIncompleteEvent {\n  /**\n   * The response that was incomplete.\n   */\n  response: Response;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.incomplete`.\n   */\n  type: 'response.incomplete';\n}\n\n/**\n * A list of one or many input items to the model, containing different content\n * types.\n */\nexport type ResponseInput = Array<ResponseInputItem>;\n\n/**\n * An audio input to the model.\n */\nexport interface ResponseInputAudio {\n  input_audio: ResponseInputAudio.InputAudio;\n\n  /**\n   * The type of the input item. Always `input_audio`.\n   */\n  type: 'input_audio';\n}\n\nexport namespace ResponseInputAudio {\n  export interface InputAudio {\n    /**\n     * Base64-encoded audio data.\n     */\n    data: string;\n\n    /**\n     * The format of the audio data. Currently supported formats are `mp3` and `wav`.\n     */\n    format: 'mp3' | 'wav';\n  }\n}\n\n/**\n * A text input to the model.\n */\nexport type ResponseInputContent = ResponseInputText | ResponseInputImage | ResponseInputFile;\n\n/**\n * A file input to the model.\n */\nexport interface ResponseInputFile {\n  /**\n   * The type of the input item. Always `input_file`.\n   */\n  type: 'input_file';\n\n  /**\n   * The content of the file to be sent to the model.\n   */\n  file_data?: string;\n\n  /**\n   * The ID of the file to be sent to the model.\n   */\n  file_id?: string | null;\n\n  /**\n   * The URL of the file to be sent to the model.\n   */\n  file_url?: string;\n\n  /**\n   * The name of the file to be sent to the model.\n   */\n  filename?: string;\n}\n\n/**\n * A file input to the model.\n */\nexport interface ResponseInputFileContent {\n  /**\n   * The type of the input item. Always `input_file`.\n   */\n  type: 'input_file';\n\n  /**\n   * The base64-encoded data of the file to be sent to the model.\n   */\n  file_data?: string | null;\n\n  /**\n   * The ID of the file to be sent to the model.\n   */\n  file_id?: string | null;\n\n  /**\n   * The URL of the file to be sent to the model.\n   */\n  file_url?: string | null;\n\n  /**\n   * The name of the file to be sent to the model.\n   */\n  filename?: string | null;\n}\n\n/**\n * An image input to the model. Learn about\n * [image inputs](https://platform.openai.com/docs/guides/vision).\n */\nexport interface ResponseInputImage {\n  /**\n   * The detail level of the image to be sent to the model. One of `high`, `low`,\n   * `auto`, or `original`. Defaults to `auto`.\n   */\n  detail: 'low' | 'high' | 'auto' | 'original';\n\n  /**\n   * The type of the input item. Always `input_image`.\n   */\n  type: 'input_image';\n\n  /**\n   * The ID of the file to be sent to the model.\n   */\n  file_id?: string | null;\n\n  /**\n   * The URL of the image to be sent to the model. A fully qualified URL or base64\n   * encoded image in a data URL.\n   */\n  image_url?: string | null;\n}\n\n/**\n * An image input to the model. Learn about\n * [image inputs](https://platform.openai.com/docs/guides/vision)\n */\nexport interface ResponseInputImageContent {\n  /**\n   * The type of the input item. Always `input_image`.\n   */\n  type: 'input_image';\n\n  /**\n   * The detail level of the image to be sent to the model. One of `high`, `low`,\n   * `auto`, or `original`. Defaults to `auto`.\n   */\n  detail?: 'low' | 'high' | 'auto' | 'original' | null;\n\n  /**\n   * The ID of the file to be sent to the model.\n   */\n  file_id?: string | null;\n\n  /**\n   * The URL of the image to be sent to the model. A fully qualified URL or base64\n   * encoded image in a data URL.\n   */\n  image_url?: string | null;\n}\n\n/**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\nexport type ResponseInputItem =\n  | EasyInputMessage\n  | ResponseInputItem.Message\n  | ResponseOutputMessage\n  | ResponseFileSearchToolCall\n  | ResponseComputerToolCall\n  | ResponseInputItem.ComputerCallOutput\n  | ResponseFunctionWebSearch\n  | ResponseFunctionToolCall\n  | ResponseInputItem.FunctionCallOutput\n  | ResponseInputItem.ToolSearchCall\n  | ResponseToolSearchOutputItemParam\n  | ResponseReasoningItem\n  | ResponseCompactionItemParam\n  | ResponseInputItem.ImageGenerationCall\n  | ResponseCodeInterpreterToolCall\n  | ResponseInputItem.LocalShellCall\n  | ResponseInputItem.LocalShellCallOutput\n  | ResponseInputItem.ShellCall\n  | ResponseInputItem.ShellCallOutput\n  | ResponseInputItem.ApplyPatchCall\n  | ResponseInputItem.ApplyPatchCallOutput\n  | ResponseInputItem.McpListTools\n  | ResponseInputItem.McpApprovalRequest\n  | ResponseInputItem.McpApprovalResponse\n  | ResponseInputItem.McpCall\n  | ResponseCustomToolCallOutput\n  | ResponseCustomToolCall\n  | ResponseInputItem.ItemReference;\n\nexport namespace ResponseInputItem {\n  /**\n   * A message input to the model with a role indicating instruction following\n   * hierarchy. Instructions given with the `developer` or `system` role take\n   * precedence over instructions given with the `user` role.\n   */\n  export interface Message {\n    /**\n     * A list of one or many input items to the model, containing different content\n     * types.\n     */\n    content: ResponsesAPI.ResponseInputMessageContentList;\n\n    /**\n     * The role of the message input. One of `user`, `system`, or `developer`.\n     */\n    role: 'user' | 'system' | 'developer';\n\n    /**\n     * The status of item. One of `in_progress`, `completed`, or `incomplete`.\n     * Populated when items are returned via API.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete';\n\n    /**\n     * The type of the message input. Always set to `message`.\n     */\n    type?: 'message';\n  }\n\n  /**\n   * The output of a computer tool call.\n   */\n  export interface ComputerCallOutput {\n    /**\n     * The ID of the computer tool call that produced the output.\n     */\n    call_id: string;\n\n    /**\n     * A computer screenshot image used with the computer use tool.\n     */\n    output: ResponsesAPI.ResponseComputerToolCallOutputScreenshot;\n\n    /**\n     * The type of the computer tool call output. Always `computer_call_output`.\n     */\n    type: 'computer_call_output';\n\n    /**\n     * The ID of the computer tool call output.\n     */\n    id?: string | null;\n\n    /**\n     * The safety checks reported by the API that have been acknowledged by the\n     * developer.\n     */\n    acknowledged_safety_checks?: Array<ComputerCallOutput.AcknowledgedSafetyCheck> | null;\n\n    /**\n     * The status of the message input. One of `in_progress`, `completed`, or\n     * `incomplete`. Populated when input items are returned via API.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | null;\n  }\n\n  export namespace ComputerCallOutput {\n    /**\n     * A pending safety check for the computer call.\n     */\n    export interface AcknowledgedSafetyCheck {\n      /**\n       * The ID of the pending safety check.\n       */\n      id: string;\n\n      /**\n       * The type of the pending safety check.\n       */\n      code?: string | null;\n\n      /**\n       * Details about the pending safety check.\n       */\n      message?: string | null;\n    }\n  }\n\n  /**\n   * The output of a function tool call.\n   */\n  export interface FunctionCallOutput {\n    /**\n     * The unique ID of the function tool call generated by the model.\n     */\n    call_id: string;\n\n    /**\n     * Text, image, or file output of the function tool call.\n     */\n    output: string | ResponsesAPI.ResponseFunctionCallOutputItemList;\n\n    /**\n     * The type of the function tool call output. Always `function_call_output`.\n     */\n    type: 'function_call_output';\n\n    /**\n     * The unique ID of the function tool call output. Populated when this item is\n     * returned via API.\n     */\n    id?: string | null;\n\n    /**\n     * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n     * Populated when items are returned via API.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | null;\n  }\n\n  export interface ToolSearchCall {\n    /**\n     * The arguments supplied to the tool search call.\n     */\n    arguments: unknown;\n\n    /**\n     * The item type. Always `tool_search_call`.\n     */\n    type: 'tool_search_call';\n\n    /**\n     * The unique ID of this tool search call.\n     */\n    id?: string | null;\n\n    /**\n     * The unique ID of the tool search call generated by the model.\n     */\n    call_id?: string | null;\n\n    /**\n     * Whether tool search was executed by the server or by the client.\n     */\n    execution?: 'server' | 'client';\n\n    /**\n     * The status of the tool search call.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | null;\n  }\n\n  /**\n   * An image generation request made by the model.\n   */\n  export interface ImageGenerationCall {\n    /**\n     * The unique ID of the image generation call.\n     */\n    id: string;\n\n    /**\n     * The generated image encoded in base64.\n     */\n    result: string | null;\n\n    /**\n     * The status of the image generation call.\n     */\n    status: 'in_progress' | 'completed' | 'generating' | 'failed';\n\n    /**\n     * The type of the image generation call. Always `image_generation_call`.\n     */\n    type: 'image_generation_call';\n  }\n\n  /**\n   * A tool call to run a command on the local shell.\n   */\n  export interface LocalShellCall {\n    /**\n     * The unique ID of the local shell call.\n     */\n    id: string;\n\n    /**\n     * Execute a shell command on the server.\n     */\n    action: LocalShellCall.Action;\n\n    /**\n     * The unique ID of the local shell tool call generated by the model.\n     */\n    call_id: string;\n\n    /**\n     * The status of the local shell call.\n     */\n    status: 'in_progress' | 'completed' | 'incomplete';\n\n    /**\n     * The type of the local shell call. Always `local_shell_call`.\n     */\n    type: 'local_shell_call';\n  }\n\n  export namespace LocalShellCall {\n    /**\n     * Execute a shell command on the server.\n     */\n    export interface Action {\n      /**\n       * The command to run.\n       */\n      command: Array<string>;\n\n      /**\n       * Environment variables to set for the command.\n       */\n      env: { [key: string]: string };\n\n      /**\n       * The type of the local shell action. Always `exec`.\n       */\n      type: 'exec';\n\n      /**\n       * Optional timeout in milliseconds for the command.\n       */\n      timeout_ms?: number | null;\n\n      /**\n       * Optional user to run the command as.\n       */\n      user?: string | null;\n\n      /**\n       * Optional working directory to run the command in.\n       */\n      working_directory?: string | null;\n    }\n  }\n\n  /**\n   * The output of a local shell tool call.\n   */\n  export interface LocalShellCallOutput {\n    /**\n     * The unique ID of the local shell tool call generated by the model.\n     */\n    id: string;\n\n    /**\n     * A JSON string of the output of the local shell tool call.\n     */\n    output: string;\n\n    /**\n     * The type of the local shell tool call output. Always `local_shell_call_output`.\n     */\n    type: 'local_shell_call_output';\n\n    /**\n     * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | null;\n  }\n\n  /**\n   * A tool representing a request to execute one or more shell commands.\n   */\n  export interface ShellCall {\n    /**\n     * The shell commands and limits that describe how to run the tool call.\n     */\n    action: ShellCall.Action;\n\n    /**\n     * The unique ID of the shell tool call generated by the model.\n     */\n    call_id: string;\n\n    /**\n     * The type of the item. Always `shell_call`.\n     */\n    type: 'shell_call';\n\n    /**\n     * The unique ID of the shell tool call. Populated when this item is returned via\n     * API.\n     */\n    id?: string | null;\n\n    /**\n     * The environment to execute the shell commands in.\n     */\n    environment?: ResponsesAPI.LocalEnvironment | ResponsesAPI.ContainerReference | null;\n\n    /**\n     * The status of the shell call. One of `in_progress`, `completed`, or\n     * `incomplete`.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | null;\n  }\n\n  export namespace ShellCall {\n    /**\n     * The shell commands and limits that describe how to run the tool call.\n     */\n    export interface Action {\n      /**\n       * Ordered shell commands for the execution environment to run.\n       */\n      commands: Array<string>;\n\n      /**\n       * Maximum number of UTF-8 characters to capture from combined stdout and stderr\n       * output.\n       */\n      max_output_length?: number | null;\n\n      /**\n       * Maximum wall-clock time in milliseconds to allow the shell commands to run.\n       */\n      timeout_ms?: number | null;\n    }\n  }\n\n  /**\n   * The streamed output items emitted by a shell tool call.\n   */\n  export interface ShellCallOutput {\n    /**\n     * The unique ID of the shell tool call generated by the model.\n     */\n    call_id: string;\n\n    /**\n     * Captured chunks of stdout and stderr output, along with their associated\n     * outcomes.\n     */\n    output: Array<ResponsesAPI.ResponseFunctionShellCallOutputContent>;\n\n    /**\n     * The type of the item. Always `shell_call_output`.\n     */\n    type: 'shell_call_output';\n\n    /**\n     * The unique ID of the shell tool call output. Populated when this item is\n     * returned via API.\n     */\n    id?: string | null;\n\n    /**\n     * The maximum number of UTF-8 characters captured for this shell call's combined\n     * output.\n     */\n    max_output_length?: number | null;\n\n    /**\n     * The status of the shell call output.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | null;\n  }\n\n  /**\n   * A tool call representing a request to create, delete, or update files using diff\n   * patches.\n   */\n  export interface ApplyPatchCall {\n    /**\n     * The unique ID of the apply patch tool call generated by the model.\n     */\n    call_id: string;\n\n    /**\n     * The specific create, delete, or update instruction for the apply_patch tool\n     * call.\n     */\n    operation: ApplyPatchCall.CreateFile | ApplyPatchCall.DeleteFile | ApplyPatchCall.UpdateFile;\n\n    /**\n     * The status of the apply patch tool call. One of `in_progress` or `completed`.\n     */\n    status: 'in_progress' | 'completed';\n\n    /**\n     * The type of the item. Always `apply_patch_call`.\n     */\n    type: 'apply_patch_call';\n\n    /**\n     * The unique ID of the apply patch tool call. Populated when this item is returned\n     * via API.\n     */\n    id?: string | null;\n  }\n\n  export namespace ApplyPatchCall {\n    /**\n     * Instruction for creating a new file via the apply_patch tool.\n     */\n    export interface CreateFile {\n      /**\n       * Unified diff content to apply when creating the file.\n       */\n      diff: string;\n\n      /**\n       * Path of the file to create relative to the workspace root.\n       */\n      path: string;\n\n      /**\n       * The operation type. Always `create_file`.\n       */\n      type: 'create_file';\n    }\n\n    /**\n     * Instruction for deleting an existing file via the apply_patch tool.\n     */\n    export interface DeleteFile {\n      /**\n       * Path of the file to delete relative to the workspace root.\n       */\n      path: string;\n\n      /**\n       * The operation type. Always `delete_file`.\n       */\n      type: 'delete_file';\n    }\n\n    /**\n     * Instruction for updating an existing file via the apply_patch tool.\n     */\n    export interface UpdateFile {\n      /**\n       * Unified diff content to apply to the existing file.\n       */\n      diff: string;\n\n      /**\n       * Path of the file to update relative to the workspace root.\n       */\n      path: string;\n\n      /**\n       * The operation type. Always `update_file`.\n       */\n      type: 'update_file';\n    }\n  }\n\n  /**\n   * The streamed output emitted by an apply patch tool call.\n   */\n  export interface ApplyPatchCallOutput {\n    /**\n     * The unique ID of the apply patch tool call generated by the model.\n     */\n    call_id: string;\n\n    /**\n     * The status of the apply patch tool call output. One of `completed` or `failed`.\n     */\n    status: 'completed' | 'failed';\n\n    /**\n     * The type of the item. Always `apply_patch_call_output`.\n     */\n    type: 'apply_patch_call_output';\n\n    /**\n     * The unique ID of the apply patch tool call output. Populated when this item is\n     * returned via API.\n     */\n    id?: string | null;\n\n    /**\n     * Optional human-readable log text from the apply patch tool (e.g., patch results\n     * or errors).\n     */\n    output?: string | null;\n  }\n\n  /**\n   * A list of tools available on an MCP server.\n   */\n  export interface McpListTools {\n    /**\n     * The unique ID of the list.\n     */\n    id: string;\n\n    /**\n     * The label of the MCP server.\n     */\n    server_label: string;\n\n    /**\n     * The tools available on the server.\n     */\n    tools: Array<McpListTools.Tool>;\n\n    /**\n     * The type of the item. Always `mcp_list_tools`.\n     */\n    type: 'mcp_list_tools';\n\n    /**\n     * Error message if the server could not list tools.\n     */\n    error?: string | null;\n  }\n\n  export namespace McpListTools {\n    /**\n     * A tool available on an MCP server.\n     */\n    export interface Tool {\n      /**\n       * The JSON schema describing the tool's input.\n       */\n      input_schema: unknown;\n\n      /**\n       * The name of the tool.\n       */\n      name: string;\n\n      /**\n       * Additional annotations about the tool.\n       */\n      annotations?: unknown | null;\n\n      /**\n       * The description of the tool.\n       */\n      description?: string | null;\n    }\n  }\n\n  /**\n   * A request for human approval of a tool invocation.\n   */\n  export interface McpApprovalRequest {\n    /**\n     * The unique ID of the approval request.\n     */\n    id: string;\n\n    /**\n     * A JSON string of arguments for the tool.\n     */\n    arguments: string;\n\n    /**\n     * The name of the tool to run.\n     */\n    name: string;\n\n    /**\n     * The label of the MCP server making the request.\n     */\n    server_label: string;\n\n    /**\n     * The type of the item. Always `mcp_approval_request`.\n     */\n    type: 'mcp_approval_request';\n  }\n\n  /**\n   * A response to an MCP approval request.\n   */\n  export interface McpApprovalResponse {\n    /**\n     * The ID of the approval request being answered.\n     */\n    approval_request_id: string;\n\n    /**\n     * Whether the request was approved.\n     */\n    approve: boolean;\n\n    /**\n     * The type of the item. Always `mcp_approval_response`.\n     */\n    type: 'mcp_approval_response';\n\n    /**\n     * The unique ID of the approval response\n     */\n    id?: string | null;\n\n    /**\n     * Optional reason for the decision.\n     */\n    reason?: string | null;\n  }\n\n  /**\n   * An invocation of a tool on an MCP server.\n   */\n  export interface McpCall {\n    /**\n     * The unique ID of the tool call.\n     */\n    id: string;\n\n    /**\n     * A JSON string of the arguments passed to the tool.\n     */\n    arguments: string;\n\n    /**\n     * The name of the tool that was run.\n     */\n    name: string;\n\n    /**\n     * The label of the MCP server running the tool.\n     */\n    server_label: string;\n\n    /**\n     * The type of the item. Always `mcp_call`.\n     */\n    type: 'mcp_call';\n\n    /**\n     * Unique identifier for the MCP tool call approval request. Include this value in\n     * a subsequent `mcp_approval_response` input to approve or reject the\n     * corresponding tool call.\n     */\n    approval_request_id?: string | null;\n\n    /**\n     * The error from the tool call, if any.\n     */\n    error?: string | null;\n\n    /**\n     * The output from the tool call.\n     */\n    output?: string | null;\n\n    /**\n     * The status of the tool call. One of `in_progress`, `completed`, `incomplete`,\n     * `calling`, or `failed`.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | 'calling' | 'failed';\n  }\n\n  /**\n   * An internal identifier for an item to reference.\n   */\n  export interface ItemReference {\n    /**\n     * The ID of the item to reference.\n     */\n    id: string;\n\n    /**\n     * The type of item to reference. Always `item_reference`.\n     */\n    type?: 'item_reference' | null;\n  }\n}\n\n/**\n * A list of one or many input items to the model, containing different content\n * types.\n */\nexport type ResponseInputMessageContentList = Array<ResponseInputContent>;\n\nexport interface ResponseInputMessageItem {\n  /**\n   * The unique ID of the message input.\n   */\n  id: string;\n\n  /**\n   * A list of one or many input items to the model, containing different content\n   * types.\n   */\n  content: ResponseInputMessageContentList;\n\n  /**\n   * The role of the message input. One of `user`, `system`, or `developer`.\n   */\n  role: 'user' | 'system' | 'developer';\n\n  /**\n   * The status of item. One of `in_progress`, `completed`, or `incomplete`.\n   * Populated when items are returned via API.\n   */\n  status?: 'in_progress' | 'completed' | 'incomplete';\n\n  /**\n   * The type of the message input. Always set to `message`.\n   */\n  type?: 'message';\n}\n\n/**\n * A text input to the model.\n */\nexport interface ResponseInputText {\n  /**\n   * The text input to the model.\n   */\n  text: string;\n\n  /**\n   * The type of the input item. Always `input_text`.\n   */\n  type: 'input_text';\n}\n\n/**\n * A text input to the model.\n */\nexport interface ResponseInputTextContent {\n  /**\n   * The text input to the model.\n   */\n  text: string;\n\n  /**\n   * The type of the input item. Always `input_text`.\n   */\n  type: 'input_text';\n}\n\n/**\n * Content item used to generate a response.\n */\nexport type ResponseItem =\n  | ResponseInputMessageItem\n  | ResponseOutputMessage\n  | ResponseFileSearchToolCall\n  | ResponseComputerToolCall\n  | ResponseComputerToolCallOutputItem\n  | ResponseFunctionWebSearch\n  | ResponseFunctionToolCallItem\n  | ResponseFunctionToolCallOutputItem\n  | ResponseToolSearchCall\n  | ResponseToolSearchOutputItem\n  | ResponseItem.ImageGenerationCall\n  | ResponseCodeInterpreterToolCall\n  | ResponseItem.LocalShellCall\n  | ResponseItem.LocalShellCallOutput\n  | ResponseFunctionShellToolCall\n  | ResponseFunctionShellToolCallOutput\n  | ResponseApplyPatchToolCall\n  | ResponseApplyPatchToolCallOutput\n  | ResponseItem.McpListTools\n  | ResponseItem.McpApprovalRequest\n  | ResponseItem.McpApprovalResponse\n  | ResponseItem.McpCall;\n\nexport namespace ResponseItem {\n  /**\n   * An image generation request made by the model.\n   */\n  export interface ImageGenerationCall {\n    /**\n     * The unique ID of the image generation call.\n     */\n    id: string;\n\n    /**\n     * The generated image encoded in base64.\n     */\n    result: string | null;\n\n    /**\n     * The status of the image generation call.\n     */\n    status: 'in_progress' | 'completed' | 'generating' | 'failed';\n\n    /**\n     * The type of the image generation call. Always `image_generation_call`.\n     */\n    type: 'image_generation_call';\n  }\n\n  /**\n   * A tool call to run a command on the local shell.\n   */\n  export interface LocalShellCall {\n    /**\n     * The unique ID of the local shell call.\n     */\n    id: string;\n\n    /**\n     * Execute a shell command on the server.\n     */\n    action: LocalShellCall.Action;\n\n    /**\n     * The unique ID of the local shell tool call generated by the model.\n     */\n    call_id: string;\n\n    /**\n     * The status of the local shell call.\n     */\n    status: 'in_progress' | 'completed' | 'incomplete';\n\n    /**\n     * The type of the local shell call. Always `local_shell_call`.\n     */\n    type: 'local_shell_call';\n  }\n\n  export namespace LocalShellCall {\n    /**\n     * Execute a shell command on the server.\n     */\n    export interface Action {\n      /**\n       * The command to run.\n       */\n      command: Array<string>;\n\n      /**\n       * Environment variables to set for the command.\n       */\n      env: { [key: string]: string };\n\n      /**\n       * The type of the local shell action. Always `exec`.\n       */\n      type: 'exec';\n\n      /**\n       * Optional timeout in milliseconds for the command.\n       */\n      timeout_ms?: number | null;\n\n      /**\n       * Optional user to run the command as.\n       */\n      user?: string | null;\n\n      /**\n       * Optional working directory to run the command in.\n       */\n      working_directory?: string | null;\n    }\n  }\n\n  /**\n   * The output of a local shell tool call.\n   */\n  export interface LocalShellCallOutput {\n    /**\n     * The unique ID of the local shell tool call generated by the model.\n     */\n    id: string;\n\n    /**\n     * A JSON string of the output of the local shell tool call.\n     */\n    output: string;\n\n    /**\n     * The type of the local shell tool call output. Always `local_shell_call_output`.\n     */\n    type: 'local_shell_call_output';\n\n    /**\n     * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | null;\n  }\n\n  /**\n   * A list of tools available on an MCP server.\n   */\n  export interface McpListTools {\n    /**\n     * The unique ID of the list.\n     */\n    id: string;\n\n    /**\n     * The label of the MCP server.\n     */\n    server_label: string;\n\n    /**\n     * The tools available on the server.\n     */\n    tools: Array<McpListTools.Tool>;\n\n    /**\n     * The type of the item. Always `mcp_list_tools`.\n     */\n    type: 'mcp_list_tools';\n\n    /**\n     * Error message if the server could not list tools.\n     */\n    error?: string | null;\n  }\n\n  export namespace McpListTools {\n    /**\n     * A tool available on an MCP server.\n     */\n    export interface Tool {\n      /**\n       * The JSON schema describing the tool's input.\n       */\n      input_schema: unknown;\n\n      /**\n       * The name of the tool.\n       */\n      name: string;\n\n      /**\n       * Additional annotations about the tool.\n       */\n      annotations?: unknown | null;\n\n      /**\n       * The description of the tool.\n       */\n      description?: string | null;\n    }\n  }\n\n  /**\n   * A request for human approval of a tool invocation.\n   */\n  export interface McpApprovalRequest {\n    /**\n     * The unique ID of the approval request.\n     */\n    id: string;\n\n    /**\n     * A JSON string of arguments for the tool.\n     */\n    arguments: string;\n\n    /**\n     * The name of the tool to run.\n     */\n    name: string;\n\n    /**\n     * The label of the MCP server making the request.\n     */\n    server_label: string;\n\n    /**\n     * The type of the item. Always `mcp_approval_request`.\n     */\n    type: 'mcp_approval_request';\n  }\n\n  /**\n   * A response to an MCP approval request.\n   */\n  export interface McpApprovalResponse {\n    /**\n     * The unique ID of the approval response\n     */\n    id: string;\n\n    /**\n     * The ID of the approval request being answered.\n     */\n    approval_request_id: string;\n\n    /**\n     * Whether the request was approved.\n     */\n    approve: boolean;\n\n    /**\n     * The type of the item. Always `mcp_approval_response`.\n     */\n    type: 'mcp_approval_response';\n\n    /**\n     * Optional reason for the decision.\n     */\n    reason?: string | null;\n  }\n\n  /**\n   * An invocation of a tool on an MCP server.\n   */\n  export interface McpCall {\n    /**\n     * The unique ID of the tool call.\n     */\n    id: string;\n\n    /**\n     * A JSON string of the arguments passed to the tool.\n     */\n    arguments: string;\n\n    /**\n     * The name of the tool that was run.\n     */\n    name: string;\n\n    /**\n     * The label of the MCP server running the tool.\n     */\n    server_label: string;\n\n    /**\n     * The type of the item. Always `mcp_call`.\n     */\n    type: 'mcp_call';\n\n    /**\n     * Unique identifier for the MCP tool call approval request. Include this value in\n     * a subsequent `mcp_approval_response` input to approve or reject the\n     * corresponding tool call.\n     */\n    approval_request_id?: string | null;\n\n    /**\n     * The error from the tool call, if any.\n     */\n    error?: string | null;\n\n    /**\n     * The output from the tool call.\n     */\n    output?: string | null;\n\n    /**\n     * The status of the tool call. One of `in_progress`, `completed`, `incomplete`,\n     * `calling`, or `failed`.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | 'calling' | 'failed';\n  }\n}\n\n/**\n * Represents the use of a local environment to perform shell actions.\n */\nexport interface ResponseLocalEnvironment {\n  /**\n   * The environment type. Always `local`.\n   */\n  type: 'local';\n}\n\n/**\n * Emitted when there is a delta (partial update) to the arguments of an MCP tool\n * call.\n */\nexport interface ResponseMcpCallArgumentsDeltaEvent {\n  /**\n   * A JSON string containing the partial update to the arguments for the MCP tool\n   * call.\n   */\n  delta: string;\n\n  /**\n   * The unique identifier of the MCP tool call item being processed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response's output array.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.mcp_call_arguments.delta'.\n   */\n  type: 'response.mcp_call_arguments.delta';\n}\n\n/**\n * Emitted when the arguments for an MCP tool call are finalized.\n */\nexport interface ResponseMcpCallArgumentsDoneEvent {\n  /**\n   * A JSON string containing the finalized arguments for the MCP tool call.\n   */\n  arguments: string;\n\n  /**\n   * The unique identifier of the MCP tool call item being processed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response's output array.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.mcp_call_arguments.done'.\n   */\n  type: 'response.mcp_call_arguments.done';\n}\n\n/**\n * Emitted when an MCP tool call has completed successfully.\n */\nexport interface ResponseMcpCallCompletedEvent {\n  /**\n   * The ID of the MCP tool call item that completed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that completed.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.mcp_call.completed'.\n   */\n  type: 'response.mcp_call.completed';\n}\n\n/**\n * Emitted when an MCP tool call has failed.\n */\nexport interface ResponseMcpCallFailedEvent {\n  /**\n   * The ID of the MCP tool call item that failed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that failed.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.mcp_call.failed'.\n   */\n  type: 'response.mcp_call.failed';\n}\n\n/**\n * Emitted when an MCP tool call is in progress.\n */\nexport interface ResponseMcpCallInProgressEvent {\n  /**\n   * The unique identifier of the MCP tool call item being processed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response's output array.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.mcp_call.in_progress'.\n   */\n  type: 'response.mcp_call.in_progress';\n}\n\n/**\n * Emitted when the list of available MCP tools has been successfully retrieved.\n */\nexport interface ResponseMcpListToolsCompletedEvent {\n  /**\n   * The ID of the MCP tool call item that produced this output.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that was processed.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.mcp_list_tools.completed'.\n   */\n  type: 'response.mcp_list_tools.completed';\n}\n\n/**\n * Emitted when the attempt to list available MCP tools has failed.\n */\nexport interface ResponseMcpListToolsFailedEvent {\n  /**\n   * The ID of the MCP tool call item that failed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that failed.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.mcp_list_tools.failed'.\n   */\n  type: 'response.mcp_list_tools.failed';\n}\n\n/**\n * Emitted when the system is in the process of retrieving the list of available\n * MCP tools.\n */\nexport interface ResponseMcpListToolsInProgressEvent {\n  /**\n   * The ID of the MCP tool call item that is being processed.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that is being processed.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.mcp_list_tools.in_progress'.\n   */\n  type: 'response.mcp_list_tools.in_progress';\n}\n\n/**\n * An audio output from the model.\n */\nexport interface ResponseOutputAudio {\n  /**\n   * Base64-encoded audio data from the model.\n   */\n  data: string;\n\n  /**\n   * The transcript of the audio data from the model.\n   */\n  transcript: string;\n\n  /**\n   * The type of the output audio. Always `output_audio`.\n   */\n  type: 'output_audio';\n}\n\n/**\n * An output message from the model.\n */\nexport type ResponseOutputItem =\n  | ResponseOutputMessage\n  | ResponseFileSearchToolCall\n  | ResponseFunctionToolCall\n  | ResponseFunctionWebSearch\n  | ResponseComputerToolCall\n  | ResponseReasoningItem\n  | ResponseToolSearchCall\n  | ResponseToolSearchOutputItem\n  | ResponseCompactionItem\n  | ResponseOutputItem.ImageGenerationCall\n  | ResponseCodeInterpreterToolCall\n  | ResponseOutputItem.LocalShellCall\n  | ResponseFunctionShellToolCall\n  | ResponseFunctionShellToolCallOutput\n  | ResponseApplyPatchToolCall\n  | ResponseApplyPatchToolCallOutput\n  | ResponseOutputItem.McpCall\n  | ResponseOutputItem.McpListTools\n  | ResponseOutputItem.McpApprovalRequest\n  | ResponseCustomToolCall;\n\nexport namespace ResponseOutputItem {\n  /**\n   * An image generation request made by the model.\n   */\n  export interface ImageGenerationCall {\n    /**\n     * The unique ID of the image generation call.\n     */\n    id: string;\n\n    /**\n     * The generated image encoded in base64.\n     */\n    result: string | null;\n\n    /**\n     * The status of the image generation call.\n     */\n    status: 'in_progress' | 'completed' | 'generating' | 'failed';\n\n    /**\n     * The type of the image generation call. Always `image_generation_call`.\n     */\n    type: 'image_generation_call';\n  }\n\n  /**\n   * A tool call to run a command on the local shell.\n   */\n  export interface LocalShellCall {\n    /**\n     * The unique ID of the local shell call.\n     */\n    id: string;\n\n    /**\n     * Execute a shell command on the server.\n     */\n    action: LocalShellCall.Action;\n\n    /**\n     * The unique ID of the local shell tool call generated by the model.\n     */\n    call_id: string;\n\n    /**\n     * The status of the local shell call.\n     */\n    status: 'in_progress' | 'completed' | 'incomplete';\n\n    /**\n     * The type of the local shell call. Always `local_shell_call`.\n     */\n    type: 'local_shell_call';\n  }\n\n  export namespace LocalShellCall {\n    /**\n     * Execute a shell command on the server.\n     */\n    export interface Action {\n      /**\n       * The command to run.\n       */\n      command: Array<string>;\n\n      /**\n       * Environment variables to set for the command.\n       */\n      env: { [key: string]: string };\n\n      /**\n       * The type of the local shell action. Always `exec`.\n       */\n      type: 'exec';\n\n      /**\n       * Optional timeout in milliseconds for the command.\n       */\n      timeout_ms?: number | null;\n\n      /**\n       * Optional user to run the command as.\n       */\n      user?: string | null;\n\n      /**\n       * Optional working directory to run the command in.\n       */\n      working_directory?: string | null;\n    }\n  }\n\n  /**\n   * An invocation of a tool on an MCP server.\n   */\n  export interface McpCall {\n    /**\n     * The unique ID of the tool call.\n     */\n    id: string;\n\n    /**\n     * A JSON string of the arguments passed to the tool.\n     */\n    arguments: string;\n\n    /**\n     * The name of the tool that was run.\n     */\n    name: string;\n\n    /**\n     * The label of the MCP server running the tool.\n     */\n    server_label: string;\n\n    /**\n     * The type of the item. Always `mcp_call`.\n     */\n    type: 'mcp_call';\n\n    /**\n     * Unique identifier for the MCP tool call approval request. Include this value in\n     * a subsequent `mcp_approval_response` input to approve or reject the\n     * corresponding tool call.\n     */\n    approval_request_id?: string | null;\n\n    /**\n     * The error from the tool call, if any.\n     */\n    error?: string | null;\n\n    /**\n     * The output from the tool call.\n     */\n    output?: string | null;\n\n    /**\n     * The status of the tool call. One of `in_progress`, `completed`, `incomplete`,\n     * `calling`, or `failed`.\n     */\n    status?: 'in_progress' | 'completed' | 'incomplete' | 'calling' | 'failed';\n  }\n\n  /**\n   * A list of tools available on an MCP server.\n   */\n  export interface McpListTools {\n    /**\n     * The unique ID of the list.\n     */\n    id: string;\n\n    /**\n     * The label of the MCP server.\n     */\n    server_label: string;\n\n    /**\n     * The tools available on the server.\n     */\n    tools: Array<McpListTools.Tool>;\n\n    /**\n     * The type of the item. Always `mcp_list_tools`.\n     */\n    type: 'mcp_list_tools';\n\n    /**\n     * Error message if the server could not list tools.\n     */\n    error?: string | null;\n  }\n\n  export namespace McpListTools {\n    /**\n     * A tool available on an MCP server.\n     */\n    export interface Tool {\n      /**\n       * The JSON schema describing the tool's input.\n       */\n      input_schema: unknown;\n\n      /**\n       * The name of the tool.\n       */\n      name: string;\n\n      /**\n       * Additional annotations about the tool.\n       */\n      annotations?: unknown | null;\n\n      /**\n       * The description of the tool.\n       */\n      description?: string | null;\n    }\n  }\n\n  /**\n   * A request for human approval of a tool invocation.\n   */\n  export interface McpApprovalRequest {\n    /**\n     * The unique ID of the approval request.\n     */\n    id: string;\n\n    /**\n     * A JSON string of arguments for the tool.\n     */\n    arguments: string;\n\n    /**\n     * The name of the tool to run.\n     */\n    name: string;\n\n    /**\n     * The label of the MCP server making the request.\n     */\n    server_label: string;\n\n    /**\n     * The type of the item. Always `mcp_approval_request`.\n     */\n    type: 'mcp_approval_request';\n  }\n}\n\n/**\n * Emitted when a new output item is added.\n */\nexport interface ResponseOutputItemAddedEvent {\n  /**\n   * The output item that was added.\n   */\n  item: ResponseOutputItem;\n\n  /**\n   * The index of the output item that was added.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.output_item.added`.\n   */\n  type: 'response.output_item.added';\n}\n\n/**\n * Emitted when an output item is marked done.\n */\nexport interface ResponseOutputItemDoneEvent {\n  /**\n   * The output item that was marked done.\n   */\n  item: ResponseOutputItem;\n\n  /**\n   * The index of the output item that was marked done.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.output_item.done`.\n   */\n  type: 'response.output_item.done';\n}\n\n/**\n * An output message from the model.\n */\nexport interface ResponseOutputMessage {\n  /**\n   * The unique ID of the output message.\n   */\n  id: string;\n\n  /**\n   * The content of the output message.\n   */\n  content: Array<ResponseOutputText | ResponseOutputRefusal>;\n\n  /**\n   * The role of the output message. Always `assistant`.\n   */\n  role: 'assistant';\n\n  /**\n   * The status of the message input. One of `in_progress`, `completed`, or\n   * `incomplete`. Populated when input items are returned via API.\n   */\n  status: 'in_progress' | 'completed' | 'incomplete';\n\n  /**\n   * The type of the output message. Always `message`.\n   */\n  type: 'message';\n\n  /**\n   * Labels an `assistant` message as intermediate commentary (`commentary`) or the\n   * final answer (`final_answer`). For models like `gpt-5.3-codex` and beyond, when\n   * sending follow-up requests, preserve and resend phase on all assistant messages\n   * — dropping it can degrade performance. Not used for user messages.\n   */\n  phase?: 'commentary' | 'final_answer' | null;\n}\n\n/**\n * A refusal from the model.\n */\nexport interface ResponseOutputRefusal {\n  /**\n   * The refusal explanation from the model.\n   */\n  refusal: string;\n\n  /**\n   * The type of the refusal. Always `refusal`.\n   */\n  type: 'refusal';\n}\n\n/**\n * A text output from the model.\n */\nexport interface ResponseOutputText {\n  /**\n   * The annotations of the text output.\n   */\n  annotations: Array<\n    | ResponseOutputText.FileCitation\n    | ResponseOutputText.URLCitation\n    | ResponseOutputText.ContainerFileCitation\n    | ResponseOutputText.FilePath\n  >;\n\n  /**\n   * The text output from the model.\n   */\n  text: string;\n\n  /**\n   * The type of the output text. Always `output_text`.\n   */\n  type: 'output_text';\n\n  logprobs?: Array<ResponseOutputText.Logprob>;\n}\n\nexport namespace ResponseOutputText {\n  /**\n   * A citation to a file.\n   */\n  export interface FileCitation {\n    /**\n     * The ID of the file.\n     */\n    file_id: string;\n\n    /**\n     * The filename of the file cited.\n     */\n    filename: string;\n\n    /**\n     * The index of the file in the list of files.\n     */\n    index: number;\n\n    /**\n     * The type of the file citation. Always `file_citation`.\n     */\n    type: 'file_citation';\n  }\n\n  /**\n   * A citation for a web resource used to generate a model response.\n   */\n  export interface URLCitation {\n    /**\n     * The index of the last character of the URL citation in the message.\n     */\n    end_index: number;\n\n    /**\n     * The index of the first character of the URL citation in the message.\n     */\n    start_index: number;\n\n    /**\n     * The title of the web resource.\n     */\n    title: string;\n\n    /**\n     * The type of the URL citation. Always `url_citation`.\n     */\n    type: 'url_citation';\n\n    /**\n     * The URL of the web resource.\n     */\n    url: string;\n  }\n\n  /**\n   * A citation for a container file used to generate a model response.\n   */\n  export interface ContainerFileCitation {\n    /**\n     * The ID of the container file.\n     */\n    container_id: string;\n\n    /**\n     * The index of the last character of the container file citation in the message.\n     */\n    end_index: number;\n\n    /**\n     * The ID of the file.\n     */\n    file_id: string;\n\n    /**\n     * The filename of the container file cited.\n     */\n    filename: string;\n\n    /**\n     * The index of the first character of the container file citation in the message.\n     */\n    start_index: number;\n\n    /**\n     * The type of the container file citation. Always `container_file_citation`.\n     */\n    type: 'container_file_citation';\n  }\n\n  /**\n   * A path to a file.\n   */\n  export interface FilePath {\n    /**\n     * The ID of the file.\n     */\n    file_id: string;\n\n    /**\n     * The index of the file in the list of files.\n     */\n    index: number;\n\n    /**\n     * The type of the file path. Always `file_path`.\n     */\n    type: 'file_path';\n  }\n\n  /**\n   * The log probability of a token.\n   */\n  export interface Logprob {\n    token: string;\n\n    bytes: Array<number>;\n\n    logprob: number;\n\n    top_logprobs: Array<Logprob.TopLogprob>;\n  }\n\n  export namespace Logprob {\n    /**\n     * The top log probability of a token.\n     */\n    export interface TopLogprob {\n      token: string;\n\n      bytes: Array<number>;\n\n      logprob: number;\n    }\n  }\n}\n\n/**\n * Emitted when an annotation is added to output text content.\n */\nexport interface ResponseOutputTextAnnotationAddedEvent {\n  /**\n   * The annotation object being added. (See annotation schema for details.)\n   */\n  annotation: unknown;\n\n  /**\n   * The index of the annotation within the content part.\n   */\n  annotation_index: number;\n\n  /**\n   * The index of the content part within the output item.\n   */\n  content_index: number;\n\n  /**\n   * The unique identifier of the item to which the annotation is being added.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item in the response's output array.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.output_text.annotation.added'.\n   */\n  type: 'response.output_text.annotation.added';\n}\n\n/**\n * Reference to a prompt template and its variables.\n * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n */\nexport interface ResponsePrompt {\n  /**\n   * The unique identifier of the prompt template to use.\n   */\n  id: string;\n\n  /**\n   * Optional map of values to substitute in for variables in your prompt. The\n   * substitution values can either be strings, or other Response input types like\n   * images or files.\n   */\n  variables?: { [key: string]: string | ResponseInputText | ResponseInputImage | ResponseInputFile } | null;\n\n  /**\n   * Optional version of the prompt template.\n   */\n  version?: string | null;\n}\n\n/**\n * Emitted when a response is queued and waiting to be processed.\n */\nexport interface ResponseQueuedEvent {\n  /**\n   * The full response object that is queued.\n   */\n  response: Response;\n\n  /**\n   * The sequence number for this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always 'response.queued'.\n   */\n  type: 'response.queued';\n}\n\n/**\n * A description of the chain of thought used by a reasoning model while generating\n * a response. Be sure to include these items in your `input` to the Responses API\n * for subsequent turns of a conversation if you are manually\n * [managing context](https://platform.openai.com/docs/guides/conversation-state).\n */\nexport interface ResponseReasoningItem {\n  /**\n   * The unique identifier of the reasoning content.\n   */\n  id: string;\n\n  /**\n   * Reasoning summary content.\n   */\n  summary: Array<ResponseReasoningItem.Summary>;\n\n  /**\n   * The type of the object. Always `reasoning`.\n   */\n  type: 'reasoning';\n\n  /**\n   * Reasoning text content.\n   */\n  content?: Array<ResponseReasoningItem.Content>;\n\n  /**\n   * The encrypted content of the reasoning item - populated when a response is\n   * generated with `reasoning.encrypted_content` in the `include` parameter.\n   */\n  encrypted_content?: string | null;\n\n  /**\n   * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n   * Populated when items are returned via API.\n   */\n  status?: 'in_progress' | 'completed' | 'incomplete';\n}\n\nexport namespace ResponseReasoningItem {\n  /**\n   * A summary text from the model.\n   */\n  export interface Summary {\n    /**\n     * A summary of the reasoning output from the model so far.\n     */\n    text: string;\n\n    /**\n     * The type of the object. Always `summary_text`.\n     */\n    type: 'summary_text';\n  }\n\n  /**\n   * Reasoning text from the model.\n   */\n  export interface Content {\n    /**\n     * The reasoning text from the model.\n     */\n    text: string;\n\n    /**\n     * The type of the reasoning text. Always `reasoning_text`.\n     */\n    type: 'reasoning_text';\n  }\n}\n\n/**\n * Emitted when a new reasoning summary part is added.\n */\nexport interface ResponseReasoningSummaryPartAddedEvent {\n  /**\n   * The ID of the item this summary part is associated with.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item this summary part is associated with.\n   */\n  output_index: number;\n\n  /**\n   * The summary part that was added.\n   */\n  part: ResponseReasoningSummaryPartAddedEvent.Part;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The index of the summary part within the reasoning summary.\n   */\n  summary_index: number;\n\n  /**\n   * The type of the event. Always `response.reasoning_summary_part.added`.\n   */\n  type: 'response.reasoning_summary_part.added';\n}\n\nexport namespace ResponseReasoningSummaryPartAddedEvent {\n  /**\n   * The summary part that was added.\n   */\n  export interface Part {\n    /**\n     * The text of the summary part.\n     */\n    text: string;\n\n    /**\n     * The type of the summary part. Always `summary_text`.\n     */\n    type: 'summary_text';\n  }\n}\n\n/**\n * Emitted when a reasoning summary part is completed.\n */\nexport interface ResponseReasoningSummaryPartDoneEvent {\n  /**\n   * The ID of the item this summary part is associated with.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item this summary part is associated with.\n   */\n  output_index: number;\n\n  /**\n   * The completed summary part.\n   */\n  part: ResponseReasoningSummaryPartDoneEvent.Part;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The index of the summary part within the reasoning summary.\n   */\n  summary_index: number;\n\n  /**\n   * The type of the event. Always `response.reasoning_summary_part.done`.\n   */\n  type: 'response.reasoning_summary_part.done';\n}\n\nexport namespace ResponseReasoningSummaryPartDoneEvent {\n  /**\n   * The completed summary part.\n   */\n  export interface Part {\n    /**\n     * The text of the summary part.\n     */\n    text: string;\n\n    /**\n     * The type of the summary part. Always `summary_text`.\n     */\n    type: 'summary_text';\n  }\n}\n\n/**\n * Emitted when a delta is added to a reasoning summary text.\n */\nexport interface ResponseReasoningSummaryTextDeltaEvent {\n  /**\n   * The text delta that was added to the summary.\n   */\n  delta: string;\n\n  /**\n   * The ID of the item this summary text delta is associated with.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item this summary text delta is associated with.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The index of the summary part within the reasoning summary.\n   */\n  summary_index: number;\n\n  /**\n   * The type of the event. Always `response.reasoning_summary_text.delta`.\n   */\n  type: 'response.reasoning_summary_text.delta';\n}\n\n/**\n * Emitted when a reasoning summary text is completed.\n */\nexport interface ResponseReasoningSummaryTextDoneEvent {\n  /**\n   * The ID of the item this summary text is associated with.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item this summary text is associated with.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The index of the summary part within the reasoning summary.\n   */\n  summary_index: number;\n\n  /**\n   * The full text of the completed reasoning summary.\n   */\n  text: string;\n\n  /**\n   * The type of the event. Always `response.reasoning_summary_text.done`.\n   */\n  type: 'response.reasoning_summary_text.done';\n}\n\n/**\n * Emitted when a delta is added to a reasoning text.\n */\nexport interface ResponseReasoningTextDeltaEvent {\n  /**\n   * The index of the reasoning content part this delta is associated with.\n   */\n  content_index: number;\n\n  /**\n   * The text delta that was added to the reasoning content.\n   */\n  delta: string;\n\n  /**\n   * The ID of the item this reasoning text delta is associated with.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item this reasoning text delta is associated with.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.reasoning_text.delta`.\n   */\n  type: 'response.reasoning_text.delta';\n}\n\n/**\n * Emitted when a reasoning text is completed.\n */\nexport interface ResponseReasoningTextDoneEvent {\n  /**\n   * The index of the reasoning content part.\n   */\n  content_index: number;\n\n  /**\n   * The ID of the item this reasoning text is associated with.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item this reasoning text is associated with.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The full text of the completed reasoning content.\n   */\n  text: string;\n\n  /**\n   * The type of the event. Always `response.reasoning_text.done`.\n   */\n  type: 'response.reasoning_text.done';\n}\n\n/**\n * Emitted when there is a partial refusal text.\n */\nexport interface ResponseRefusalDeltaEvent {\n  /**\n   * The index of the content part that the refusal text is added to.\n   */\n  content_index: number;\n\n  /**\n   * The refusal text that is added.\n   */\n  delta: string;\n\n  /**\n   * The ID of the output item that the refusal text is added to.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the refusal text is added to.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.refusal.delta`.\n   */\n  type: 'response.refusal.delta';\n}\n\n/**\n * Emitted when refusal text is finalized.\n */\nexport interface ResponseRefusalDoneEvent {\n  /**\n   * The index of the content part that the refusal text is finalized.\n   */\n  content_index: number;\n\n  /**\n   * The ID of the output item that the refusal text is finalized.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the refusal text is finalized.\n   */\n  output_index: number;\n\n  /**\n   * The refusal text that is finalized.\n   */\n  refusal: string;\n\n  /**\n   * The sequence number of this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.refusal.done`.\n   */\n  type: 'response.refusal.done';\n}\n\n/**\n * The status of the response generation. One of `completed`, `failed`,\n * `in_progress`, `cancelled`, `queued`, or `incomplete`.\n */\nexport type ResponseStatus = 'completed' | 'failed' | 'in_progress' | 'cancelled' | 'queued' | 'incomplete';\n\n/**\n * Emitted when there is a partial audio response.\n */\nexport type ResponseStreamEvent =\n  | ResponseAudioDeltaEvent\n  | ResponseAudioDoneEvent\n  | ResponseAudioTranscriptDeltaEvent\n  | ResponseAudioTranscriptDoneEvent\n  | ResponseCodeInterpreterCallCodeDeltaEvent\n  | ResponseCodeInterpreterCallCodeDoneEvent\n  | ResponseCodeInterpreterCallCompletedEvent\n  | ResponseCodeInterpreterCallInProgressEvent\n  | ResponseCodeInterpreterCallInterpretingEvent\n  | ResponseCompletedEvent\n  | ResponseContentPartAddedEvent\n  | ResponseContentPartDoneEvent\n  | ResponseCreatedEvent\n  | ResponseErrorEvent\n  | ResponseFileSearchCallCompletedEvent\n  | ResponseFileSearchCallInProgressEvent\n  | ResponseFileSearchCallSearchingEvent\n  | ResponseFunctionCallArgumentsDeltaEvent\n  | ResponseFunctionCallArgumentsDoneEvent\n  | ResponseInProgressEvent\n  | ResponseFailedEvent\n  | ResponseIncompleteEvent\n  | ResponseOutputItemAddedEvent\n  | ResponseOutputItemDoneEvent\n  | ResponseReasoningSummaryPartAddedEvent\n  | ResponseReasoningSummaryPartDoneEvent\n  | ResponseReasoningSummaryTextDeltaEvent\n  | ResponseReasoningSummaryTextDoneEvent\n  | ResponseReasoningTextDeltaEvent\n  | ResponseReasoningTextDoneEvent\n  | ResponseRefusalDeltaEvent\n  | ResponseRefusalDoneEvent\n  | ResponseTextDeltaEvent\n  | ResponseTextDoneEvent\n  | ResponseWebSearchCallCompletedEvent\n  | ResponseWebSearchCallInProgressEvent\n  | ResponseWebSearchCallSearchingEvent\n  | ResponseImageGenCallCompletedEvent\n  | ResponseImageGenCallGeneratingEvent\n  | ResponseImageGenCallInProgressEvent\n  | ResponseImageGenCallPartialImageEvent\n  | ResponseMcpCallArgumentsDeltaEvent\n  | ResponseMcpCallArgumentsDoneEvent\n  | ResponseMcpCallCompletedEvent\n  | ResponseMcpCallFailedEvent\n  | ResponseMcpCallInProgressEvent\n  | ResponseMcpListToolsCompletedEvent\n  | ResponseMcpListToolsFailedEvent\n  | ResponseMcpListToolsInProgressEvent\n  | ResponseOutputTextAnnotationAddedEvent\n  | ResponseQueuedEvent\n  | ResponseCustomToolCallInputDeltaEvent\n  | ResponseCustomToolCallInputDoneEvent;\n\n/**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\nexport interface ResponseTextConfig {\n  /**\n   * An object specifying the format that the model must output.\n   *\n   * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n   * ensures the model will match your supplied JSON schema. Learn more in the\n   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n   *\n   * The default format is `{ \"type\": \"text\" }` with no additional options.\n   *\n   * **Not recommended for gpt-4o and newer models:**\n   *\n   * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n   * ensures the message the model generates is valid JSON. Using `json_schema` is\n   * preferred for models that support it.\n   */\n  format?: ResponseFormatTextConfig;\n\n  /**\n   * Constrains the verbosity of the model's response. Lower values will result in\n   * more concise responses, while higher values will result in more verbose\n   * responses. Currently supported values are `low`, `medium`, and `high`.\n   */\n  verbosity?: 'low' | 'medium' | 'high' | null;\n}\n\n/**\n * Emitted when there is an additional text delta.\n */\nexport interface ResponseTextDeltaEvent {\n  /**\n   * The index of the content part that the text delta was added to.\n   */\n  content_index: number;\n\n  /**\n   * The text delta that was added.\n   */\n  delta: string;\n\n  /**\n   * The ID of the output item that the text delta was added to.\n   */\n  item_id: string;\n\n  /**\n   * The log probabilities of the tokens in the delta.\n   */\n  logprobs: Array<ResponseTextDeltaEvent.Logprob>;\n\n  /**\n   * The index of the output item that the text delta was added to.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number for this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.output_text.delta`.\n   */\n  type: 'response.output_text.delta';\n}\n\nexport namespace ResponseTextDeltaEvent {\n  /**\n   * A logprob is the logarithmic probability that the model assigns to producing a\n   * particular token at a given position in the sequence. Less-negative (higher)\n   * logprob values indicate greater model confidence in that token choice.\n   */\n  export interface Logprob {\n    /**\n     * A possible text token.\n     */\n    token: string;\n\n    /**\n     * The log probability of this token.\n     */\n    logprob: number;\n\n    /**\n     * The log probability of the top 20 most likely tokens.\n     */\n    top_logprobs?: Array<Logprob.TopLogprob>;\n  }\n\n  export namespace Logprob {\n    export interface TopLogprob {\n      /**\n       * A possible text token.\n       */\n      token?: string;\n\n      /**\n       * The log probability of this token.\n       */\n      logprob?: number;\n    }\n  }\n}\n\n/**\n * Emitted when text content is finalized.\n */\nexport interface ResponseTextDoneEvent {\n  /**\n   * The index of the content part that the text content is finalized.\n   */\n  content_index: number;\n\n  /**\n   * The ID of the output item that the text content is finalized.\n   */\n  item_id: string;\n\n  /**\n   * The log probabilities of the tokens in the delta.\n   */\n  logprobs: Array<ResponseTextDoneEvent.Logprob>;\n\n  /**\n   * The index of the output item that the text content is finalized.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number for this event.\n   */\n  sequence_number: number;\n\n  /**\n   * The text content that is finalized.\n   */\n  text: string;\n\n  /**\n   * The type of the event. Always `response.output_text.done`.\n   */\n  type: 'response.output_text.done';\n}\n\nexport namespace ResponseTextDoneEvent {\n  /**\n   * A logprob is the logarithmic probability that the model assigns to producing a\n   * particular token at a given position in the sequence. Less-negative (higher)\n   * logprob values indicate greater model confidence in that token choice.\n   */\n  export interface Logprob {\n    /**\n     * A possible text token.\n     */\n    token: string;\n\n    /**\n     * The log probability of this token.\n     */\n    logprob: number;\n\n    /**\n     * The log probability of the top 20 most likely tokens.\n     */\n    top_logprobs?: Array<Logprob.TopLogprob>;\n  }\n\n  export namespace Logprob {\n    export interface TopLogprob {\n      /**\n       * A possible text token.\n       */\n      token?: string;\n\n      /**\n       * The log probability of this token.\n       */\n      logprob?: number;\n    }\n  }\n}\n\nexport interface ResponseToolSearchCall {\n  /**\n   * The unique ID of the tool search call item.\n   */\n  id: string;\n\n  /**\n   * Arguments used for the tool search call.\n   */\n  arguments: unknown;\n\n  /**\n   * The unique ID of the tool search call generated by the model.\n   */\n  call_id: string | null;\n\n  /**\n   * Whether tool search was executed by the server or by the client.\n   */\n  execution: 'server' | 'client';\n\n  /**\n   * The status of the tool search call item that was recorded.\n   */\n  status: 'in_progress' | 'completed' | 'incomplete';\n\n  /**\n   * The type of the item. Always `tool_search_call`.\n   */\n  type: 'tool_search_call';\n\n  /**\n   * The identifier of the actor that created the item.\n   */\n  created_by?: string;\n}\n\nexport interface ResponseToolSearchOutputItem {\n  /**\n   * The unique ID of the tool search output item.\n   */\n  id: string;\n\n  /**\n   * The unique ID of the tool search call generated by the model.\n   */\n  call_id: string | null;\n\n  /**\n   * Whether tool search was executed by the server or by the client.\n   */\n  execution: 'server' | 'client';\n\n  /**\n   * The status of the tool search output item that was recorded.\n   */\n  status: 'in_progress' | 'completed' | 'incomplete';\n\n  /**\n   * The loaded tool definitions returned by tool search.\n   */\n  tools: Array<Tool>;\n\n  /**\n   * The type of the item. Always `tool_search_output`.\n   */\n  type: 'tool_search_output';\n\n  /**\n   * The identifier of the actor that created the item.\n   */\n  created_by?: string;\n}\n\nexport interface ResponseToolSearchOutputItemParam {\n  /**\n   * The loaded tool definitions returned by the tool search output.\n   */\n  tools: Array<Tool>;\n\n  /**\n   * The item type. Always `tool_search_output`.\n   */\n  type: 'tool_search_output';\n\n  /**\n   * The unique ID of this tool search output.\n   */\n  id?: string | null;\n\n  /**\n   * The unique ID of the tool search call generated by the model.\n   */\n  call_id?: string | null;\n\n  /**\n   * Whether tool search was executed by the server or by the client.\n   */\n  execution?: 'server' | 'client';\n\n  /**\n   * The status of the tool search output.\n   */\n  status?: 'in_progress' | 'completed' | 'incomplete' | null;\n}\n\n/**\n * Represents token usage details including input tokens, output tokens, a\n * breakdown of output tokens, and the total tokens used.\n */\nexport interface ResponseUsage {\n  /**\n   * The number of input tokens.\n   */\n  input_tokens: number;\n\n  /**\n   * A detailed breakdown of the input tokens.\n   */\n  input_tokens_details: ResponseUsage.InputTokensDetails;\n\n  /**\n   * The number of output tokens.\n   */\n  output_tokens: number;\n\n  /**\n   * A detailed breakdown of the output tokens.\n   */\n  output_tokens_details: ResponseUsage.OutputTokensDetails;\n\n  /**\n   * The total number of tokens used.\n   */\n  total_tokens: number;\n}\n\nexport namespace ResponseUsage {\n  /**\n   * A detailed breakdown of the input tokens.\n   */\n  export interface InputTokensDetails {\n    /**\n     * The number of tokens that were retrieved from the cache.\n     * [More on prompt caching](https://platform.openai.com/docs/guides/prompt-caching).\n     */\n    cached_tokens: number;\n  }\n\n  /**\n   * A detailed breakdown of the output tokens.\n   */\n  export interface OutputTokensDetails {\n    /**\n     * The number of reasoning tokens.\n     */\n    reasoning_tokens: number;\n  }\n}\n\n/**\n * Emitted when a web search call is completed.\n */\nexport interface ResponseWebSearchCallCompletedEvent {\n  /**\n   * Unique ID for the output item associated with the web search call.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the web search call is associated with.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of the web search call being processed.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.web_search_call.completed`.\n   */\n  type: 'response.web_search_call.completed';\n}\n\n/**\n * Emitted when a web search call is initiated.\n */\nexport interface ResponseWebSearchCallInProgressEvent {\n  /**\n   * Unique ID for the output item associated with the web search call.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the web search call is associated with.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of the web search call being processed.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.web_search_call.in_progress`.\n   */\n  type: 'response.web_search_call.in_progress';\n}\n\n/**\n * Emitted when a web search call is executing.\n */\nexport interface ResponseWebSearchCallSearchingEvent {\n  /**\n   * Unique ID for the output item associated with the web search call.\n   */\n  item_id: string;\n\n  /**\n   * The index of the output item that the web search call is associated with.\n   */\n  output_index: number;\n\n  /**\n   * The sequence number of the web search call being processed.\n   */\n  sequence_number: number;\n\n  /**\n   * The type of the event. Always `response.web_search_call.searching`.\n   */\n  type: 'response.web_search_call.searching';\n}\n\nexport interface ResponsesClientEvent {\n  /**\n   * The type of the client event. Always `response.create`.\n   */\n  type: 'response.create';\n\n  /**\n   * Whether to run the model response in the background.\n   * [Learn more](https://platform.openai.com/docs/guides/background).\n   */\n  background?: boolean | null;\n\n  /**\n   * Context management configuration for this request.\n   */\n  context_management?: Array<ResponsesClientEvent.ContextManagement> | null;\n\n  /**\n   * The conversation that this response belongs to. Items from this conversation are\n   * prepended to `input_items` for this response request. Input items and output\n   * items from this response are automatically added to this conversation after this\n   * response completes.\n   */\n  conversation?: string | ResponseConversationParam | null;\n\n  /**\n   * Specify additional output data to include in the model response. Currently\n   * supported values are:\n   *\n   * - `web_search_call.action.sources`: Include the sources of the web search tool\n   *   call.\n   * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n   *   in code interpreter tool call items.\n   * - `computer_call_output.output.image_url`: Include image urls from the computer\n   *   call output.\n   * - `file_search_call.results`: Include the search results of the file search tool\n   *   call.\n   * - `message.input_image.image_url`: Include image urls from the input message.\n   * - `message.output_text.logprobs`: Include logprobs with assistant messages.\n   * - `reasoning.encrypted_content`: Includes an encrypted version of reasoning\n   *   tokens in reasoning item outputs. This enables reasoning items to be used in\n   *   multi-turn conversations when using the Responses API statelessly (like when\n   *   the `store` parameter is set to `false`, or when an organization is enrolled\n   *   in the zero data retention program).\n   */\n  include?: Array<ResponseIncludable> | null;\n\n  /**\n   * Text, image, or file inputs to the model, used to generate a response.\n   *\n   * Learn more:\n   *\n   * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n   * - [Image inputs](https://platform.openai.com/docs/guides/images)\n   * - [File inputs](https://platform.openai.com/docs/guides/pdf-files)\n   * - [Conversation state](https://platform.openai.com/docs/guides/conversation-state)\n   * - [Function calling](https://platform.openai.com/docs/guides/function-calling)\n   */\n  input?: string | ResponseInput;\n\n  /**\n   * A system (or developer) message inserted into the model's context.\n   *\n   * When using along with `previous_response_id`, the instructions from a previous\n   * response will not be carried over to the next response. This makes it simple to\n   * swap out system (or developer) messages in new responses.\n   */\n  instructions?: string | null;\n\n  /**\n   * An upper bound for the number of tokens that can be generated for a response,\n   * including visible output tokens and\n   * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).\n   */\n  max_output_tokens?: number | null;\n\n  /**\n   * The maximum number of total calls to built-in tools that can be processed in a\n   * response. This maximum number applies across all built-in tool calls, not per\n   * individual tool. Any further attempts to call a tool by the model will be\n   * ignored.\n   */\n  max_tool_calls?: number | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a\n   * wide range of models with different capabilities, performance characteristics,\n   * and price points. Refer to the\n   * [model guide](https://platform.openai.com/docs/models) to browse and compare\n   * available models.\n   */\n  model?: Shared.ResponsesModel;\n\n  /**\n   * Whether to allow the model to run tool calls in parallel.\n   */\n  parallel_tool_calls?: boolean | null;\n\n  /**\n   * The unique ID of the previous response to the model. Use this to create\n   * multi-turn conversations. Learn more about\n   * [conversation state](https://platform.openai.com/docs/guides/conversation-state).\n   * Cannot be used in conjunction with `conversation`.\n   */\n  previous_response_id?: string | null;\n\n  /**\n   * Reference to a prompt template and its variables.\n   * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n   */\n  prompt?: ResponsePrompt | null;\n\n  /**\n   * Used by OpenAI to cache responses for similar requests to optimize your cache\n   * hit rates. Replaces the `user` field.\n   * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n   */\n  prompt_cache_key?: string;\n\n  /**\n   * The retention policy for the prompt cache. Set to `24h` to enable extended\n   * prompt caching, which keeps cached prefixes active for longer, up to a maximum\n   * of 24 hours.\n   * [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).\n   */\n  prompt_cache_retention?: 'in-memory' | '24h' | null;\n\n  /**\n   * **gpt-5 and o-series models only**\n   *\n   * Configuration options for\n   * [reasoning models](https://platform.openai.com/docs/guides/reasoning).\n   */\n  reasoning?: Shared.Reasoning | null;\n\n  /**\n   * A stable identifier used to help detect users of your application that may be\n   * violating OpenAI's usage policies. The IDs should be a string that uniquely\n   * identifies each user, with a maximum length of 64 characters. We recommend\n   * hashing their username or email address, in order to avoid sending us any\n   * identifying information.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n   */\n  safety_identifier?: string;\n\n  /**\n   * Specifies the processing type used for serving the request.\n   *\n   * - If set to 'auto', then the request will be processed with the service tier\n   *   configured in the Project settings. Unless otherwise configured, the Project\n   *   will use 'default'.\n   * - If set to 'default', then the request will be processed with the standard\n   *   pricing and performance for the selected model.\n   * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n   *   '[priority](https://openai.com/api-priority-processing/)', then the request\n   *   will be processed with the corresponding service tier.\n   * - When not set, the default behavior is 'auto'.\n   *\n   * When the `service_tier` parameter is set, the response body will include the\n   * `service_tier` value based on the processing mode actually used to serve the\n   * request. This response value may be different from the value set in the\n   * parameter.\n   */\n  service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n  /**\n   * Whether to store the generated model response for later retrieval via API.\n   */\n  store?: boolean | null;\n\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n   * for more information.\n   */\n  stream?: boolean | null;\n\n  /**\n   * Options for streaming responses. Only set this when you set `stream: true`.\n   */\n  stream_options?: ResponsesClientEvent.StreamOptions | null;\n\n  /**\n   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n   * make the output more random, while lower values like 0.2 will make it more\n   * focused and deterministic. We generally recommend altering this or `top_p` but\n   * not both.\n   */\n  temperature?: number | null;\n\n  /**\n   * Configuration options for a text response from the model. Can be plain text or\n   * structured JSON data. Learn more:\n   *\n   * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n   * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n   */\n  text?: ResponseTextConfig;\n\n  /**\n   * How the model should select which tool (or tools) to use when generating a\n   * response. See the `tools` parameter to see how to specify which tools the model\n   * can call.\n   */\n  tool_choice?:\n    | ToolChoiceOptions\n    | ToolChoiceAllowed\n    | ToolChoiceTypes\n    | ToolChoiceFunction\n    | ToolChoiceMcp\n    | ToolChoiceCustom\n    | ToolChoiceApplyPatch\n    | ToolChoiceShell;\n\n  /**\n   * An array of tools the model may call while generating a response. You can\n   * specify which tool to use by setting the `tool_choice` parameter.\n   *\n   * We support the following categories of tools:\n   *\n   * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n   *   capabilities, like\n   *   [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n   *   [file search](https://platform.openai.com/docs/guides/tools-file-search).\n   *   Learn more about\n   *   [built-in tools](https://platform.openai.com/docs/guides/tools).\n   * - **MCP Tools**: Integrations with third-party systems via custom MCP servers or\n   *   predefined connectors such as Google Drive and SharePoint. Learn more about\n   *   [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).\n   * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n   *   the model to call your own code with strongly typed arguments and outputs.\n   *   Learn more about\n   *   [function calling](https://platform.openai.com/docs/guides/function-calling).\n   *   You can also use custom tools to call your own code.\n   */\n  tools?: Array<Tool>;\n\n  /**\n   * An integer between 0 and 20 specifying the number of most likely tokens to\n   * return at each token position, each with an associated log probability.\n   */\n  top_logprobs?: number | null;\n\n  /**\n   * An alternative to sampling with temperature, called nucleus sampling, where the\n   * model considers the results of the tokens with top_p probability mass. So 0.1\n   * means only the tokens comprising the top 10% probability mass are considered.\n   *\n   * We generally recommend altering this or `temperature` but not both.\n   */\n  top_p?: number | null;\n\n  /**\n   * The truncation strategy to use for the model response.\n   *\n   * - `auto`: If the input to this Response exceeds the model's context window size,\n   *   the model will truncate the response to fit the context window by dropping\n   *   items from the beginning of the conversation.\n   * - `disabled` (default): If the input size will exceed the context window size\n   *   for a model, the request will fail with a 400 error.\n   */\n  truncation?: 'auto' | 'disabled' | null;\n\n  /**\n   * @deprecated This field is being replaced by `safety_identifier` and\n   * `prompt_cache_key`. Use `prompt_cache_key` instead to maintain caching\n   * optimizations. A stable identifier for your end-users. Used to boost cache hit\n   * rates by better bucketing similar requests and to help OpenAI detect and prevent\n   * abuse.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n   */\n  user?: string;\n}\n\nexport namespace ResponsesClientEvent {\n  export interface ContextManagement {\n    /**\n     * The context management entry type. Currently only 'compaction' is supported.\n     */\n    type: string;\n\n    /**\n     * Token threshold at which compaction should be triggered for this entry.\n     */\n    compact_threshold?: number | null;\n  }\n\n  /**\n   * Options for streaming responses. Only set this when you set `stream: true`.\n   */\n  export interface StreamOptions {\n    /**\n     * When true, stream obfuscation will be enabled. Stream obfuscation adds random\n     * characters to an `obfuscation` field on streaming delta events to normalize\n     * payload sizes as a mitigation to certain side-channel attacks. These obfuscation\n     * fields are included by default, but add a small amount of overhead to the data\n     * stream. You can set `include_obfuscation` to false to optimize for bandwidth if\n     * you trust the network links between your application and the OpenAI API.\n     */\n    include_obfuscation?: boolean;\n  }\n}\n\n/**\n * Server events emitted by the Responses WebSocket server.\n */\nexport type ResponsesServerEvent =\n  | ResponseAudioDeltaEvent\n  | ResponseAudioDoneEvent\n  | ResponseAudioTranscriptDeltaEvent\n  | ResponseAudioTranscriptDoneEvent\n  | ResponseCodeInterpreterCallCodeDeltaEvent\n  | ResponseCodeInterpreterCallCodeDoneEvent\n  | ResponseCodeInterpreterCallCompletedEvent\n  | ResponseCodeInterpreterCallInProgressEvent\n  | ResponseCodeInterpreterCallInterpretingEvent\n  | ResponseCompletedEvent\n  | ResponseContentPartAddedEvent\n  | ResponseContentPartDoneEvent\n  | ResponseCreatedEvent\n  | ResponseErrorEvent\n  | ResponseFileSearchCallCompletedEvent\n  | ResponseFileSearchCallInProgressEvent\n  | ResponseFileSearchCallSearchingEvent\n  | ResponseFunctionCallArgumentsDeltaEvent\n  | ResponseFunctionCallArgumentsDoneEvent\n  | ResponseInProgressEvent\n  | ResponseFailedEvent\n  | ResponseIncompleteEvent\n  | ResponseOutputItemAddedEvent\n  | ResponseOutputItemDoneEvent\n  | ResponseReasoningSummaryPartAddedEvent\n  | ResponseReasoningSummaryPartDoneEvent\n  | ResponseReasoningSummaryTextDeltaEvent\n  | ResponseReasoningSummaryTextDoneEvent\n  | ResponseReasoningTextDeltaEvent\n  | ResponseReasoningTextDoneEvent\n  | ResponseRefusalDeltaEvent\n  | ResponseRefusalDoneEvent\n  | ResponseTextDeltaEvent\n  | ResponseTextDoneEvent\n  | ResponseWebSearchCallCompletedEvent\n  | ResponseWebSearchCallInProgressEvent\n  | ResponseWebSearchCallSearchingEvent\n  | ResponseImageGenCallCompletedEvent\n  | ResponseImageGenCallGeneratingEvent\n  | ResponseImageGenCallInProgressEvent\n  | ResponseImageGenCallPartialImageEvent\n  | ResponseMcpCallArgumentsDeltaEvent\n  | ResponseMcpCallArgumentsDoneEvent\n  | ResponseMcpCallCompletedEvent\n  | ResponseMcpCallFailedEvent\n  | ResponseMcpCallInProgressEvent\n  | ResponseMcpListToolsCompletedEvent\n  | ResponseMcpListToolsFailedEvent\n  | ResponseMcpListToolsInProgressEvent\n  | ResponseOutputTextAnnotationAddedEvent\n  | ResponseQueuedEvent\n  | ResponseCustomToolCallInputDeltaEvent\n  | ResponseCustomToolCallInputDoneEvent;\n\nexport interface SkillReference {\n  /**\n   * The ID of the referenced skill.\n   */\n  skill_id: string;\n\n  /**\n   * References a skill created with the /v1/skills endpoint.\n   */\n  type: 'skill_reference';\n\n  /**\n   * Optional skill version. Use a positive integer or 'latest'. Omit for default.\n   */\n  version?: string;\n}\n\n/**\n * A tool that can be used to generate a response.\n */\nexport type Tool =\n  | FunctionTool\n  | FileSearchTool\n  | ComputerTool\n  | ComputerUsePreviewTool\n  | WebSearchTool\n  | Tool.Mcp\n  | Tool.CodeInterpreter\n  | Tool.ImageGeneration\n  | Tool.LocalShell\n  | FunctionShellTool\n  | CustomTool\n  | NamespaceTool\n  | ToolSearchTool\n  | WebSearchPreviewTool\n  | ApplyPatchTool;\n\nexport namespace Tool {\n  /**\n   * Give the model access to additional tools via remote Model Context Protocol\n   * (MCP) servers.\n   * [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).\n   */\n  export interface Mcp {\n    /**\n     * A label for this MCP server, used to identify it in tool calls.\n     */\n    server_label: string;\n\n    /**\n     * The type of the MCP tool. Always `mcp`.\n     */\n    type: 'mcp';\n\n    /**\n     * List of allowed tool names or a filter object.\n     */\n    allowed_tools?: Array<string> | Mcp.McpToolFilter | null;\n\n    /**\n     * An OAuth access token that can be used with a remote MCP server, either with a\n     * custom MCP server URL or a service connector. Your application must handle the\n     * OAuth authorization flow and provide the token here.\n     */\n    authorization?: string;\n\n    /**\n     * Identifier for service connectors, like those available in ChatGPT. One of\n     * `server_url` or `connector_id` must be provided. Learn more about service\n     * connectors\n     * [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).\n     *\n     * Currently supported `connector_id` values are:\n     *\n     * - Dropbox: `connector_dropbox`\n     * - Gmail: `connector_gmail`\n     * - Google Calendar: `connector_googlecalendar`\n     * - Google Drive: `connector_googledrive`\n     * - Microsoft Teams: `connector_microsoftteams`\n     * - Outlook Calendar: `connector_outlookcalendar`\n     * - Outlook Email: `connector_outlookemail`\n     * - SharePoint: `connector_sharepoint`\n     */\n    connector_id?:\n      | 'connector_dropbox'\n      | 'connector_gmail'\n      | 'connector_googlecalendar'\n      | 'connector_googledrive'\n      | 'connector_microsoftteams'\n      | 'connector_outlookcalendar'\n      | 'connector_outlookemail'\n      | 'connector_sharepoint';\n\n    /**\n     * Whether this MCP tool is deferred and discovered via tool search.\n     */\n    defer_loading?: boolean;\n\n    /**\n     * Optional HTTP headers to send to the MCP server. Use for authentication or other\n     * purposes.\n     */\n    headers?: { [key: string]: string } | null;\n\n    /**\n     * Specify which of the MCP server's tools require approval.\n     */\n    require_approval?: Mcp.McpToolApprovalFilter | 'always' | 'never' | null;\n\n    /**\n     * Optional description of the MCP server, used to provide more context.\n     */\n    server_description?: string;\n\n    /**\n     * The URL for the MCP server. One of `server_url` or `connector_id` must be\n     * provided.\n     */\n    server_url?: string;\n  }\n\n  export namespace Mcp {\n    /**\n     * A filter object to specify which tools are allowed.\n     */\n    export interface McpToolFilter {\n      /**\n       * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n       * is\n       * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n       * it will match this filter.\n       */\n      read_only?: boolean;\n\n      /**\n       * List of allowed tool names.\n       */\n      tool_names?: Array<string>;\n    }\n\n    /**\n     * Specify which of the MCP server's tools require approval. Can be `always`,\n     * `never`, or a filter object associated with tools that require approval.\n     */\n    export interface McpToolApprovalFilter {\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      always?: McpToolApprovalFilter.Always;\n\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      never?: McpToolApprovalFilter.Never;\n    }\n\n    export namespace McpToolApprovalFilter {\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      export interface Always {\n        /**\n         * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n         * is\n         * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n         * it will match this filter.\n         */\n        read_only?: boolean;\n\n        /**\n         * List of allowed tool names.\n         */\n        tool_names?: Array<string>;\n      }\n\n      /**\n       * A filter object to specify which tools are allowed.\n       */\n      export interface Never {\n        /**\n         * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n         * is\n         * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n         * it will match this filter.\n         */\n        read_only?: boolean;\n\n        /**\n         * List of allowed tool names.\n         */\n        tool_names?: Array<string>;\n      }\n    }\n  }\n\n  /**\n   * A tool that runs Python code to help generate a response to a prompt.\n   */\n  export interface CodeInterpreter {\n    /**\n     * The code interpreter container. Can be a container ID or an object that\n     * specifies uploaded file IDs to make available to your code, along with an\n     * optional `memory_limit` setting.\n     */\n    container: string | CodeInterpreter.CodeInterpreterToolAuto;\n\n    /**\n     * The type of the code interpreter tool. Always `code_interpreter`.\n     */\n    type: 'code_interpreter';\n  }\n\n  export namespace CodeInterpreter {\n    /**\n     * Configuration for a code interpreter container. Optionally specify the IDs of\n     * the files to run the code on.\n     */\n    export interface CodeInterpreterToolAuto {\n      /**\n       * Always `auto`.\n       */\n      type: 'auto';\n\n      /**\n       * An optional list of uploaded files to make available to your code.\n       */\n      file_ids?: Array<string>;\n\n      /**\n       * The memory limit for the code interpreter container.\n       */\n      memory_limit?: '1g' | '4g' | '16g' | '64g' | null;\n\n      /**\n       * Network access policy for the container.\n       */\n      network_policy?:\n        | ResponsesAPI.ContainerNetworkPolicyDisabled\n        | ResponsesAPI.ContainerNetworkPolicyAllowlist;\n    }\n  }\n\n  /**\n   * A tool that generates images using the GPT image models.\n   */\n  export interface ImageGeneration {\n    /**\n     * The type of the image generation tool. Always `image_generation`.\n     */\n    type: 'image_generation';\n\n    /**\n     * Whether to generate a new image or edit an existing image. Default: `auto`.\n     */\n    action?: 'generate' | 'edit' | 'auto';\n\n    /**\n     * Background type for the generated image. One of `transparent`, `opaque`, or\n     * `auto`. Default: `auto`.\n     */\n    background?: 'transparent' | 'opaque' | 'auto';\n\n    /**\n     * Control how much effort the model will exert to match the style and features,\n     * especially facial features, of input images. This parameter is only supported\n     * for `gpt-image-1` and `gpt-image-1.5` and later models, unsupported for\n     * `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`.\n     */\n    input_fidelity?: 'high' | 'low' | null;\n\n    /**\n     * Optional mask for inpainting. Contains `image_url` (string, optional) and\n     * `file_id` (string, optional).\n     */\n    input_image_mask?: ImageGeneration.InputImageMask;\n\n    /**\n     * The image generation model to use. Default: `gpt-image-1`.\n     */\n    model?: (string & {}) | 'gpt-image-1' | 'gpt-image-1-mini' | 'gpt-image-1.5';\n\n    /**\n     * Moderation level for the generated image. Default: `auto`.\n     */\n    moderation?: 'auto' | 'low';\n\n    /**\n     * Compression level for the output image. Default: 100.\n     */\n    output_compression?: number;\n\n    /**\n     * The output format of the generated image. One of `png`, `webp`, or `jpeg`.\n     * Default: `png`.\n     */\n    output_format?: 'png' | 'webp' | 'jpeg';\n\n    /**\n     * Number of partial images to generate in streaming mode, from 0 (default value)\n     * to 3.\n     */\n    partial_images?: number;\n\n    /**\n     * The quality of the generated image. One of `low`, `medium`, `high`, or `auto`.\n     * Default: `auto`.\n     */\n    quality?: 'low' | 'medium' | 'high' | 'auto';\n\n    /**\n     * The size of the generated image. One of `1024x1024`, `1024x1536`, `1536x1024`,\n     * or `auto`. Default: `auto`.\n     */\n    size?: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';\n  }\n\n  export namespace ImageGeneration {\n    /**\n     * Optional mask for inpainting. Contains `image_url` (string, optional) and\n     * `file_id` (string, optional).\n     */\n    export interface InputImageMask {\n      /**\n       * File ID for the mask image.\n       */\n      file_id?: string;\n\n      /**\n       * Base64-encoded mask image.\n       */\n      image_url?: string;\n    }\n  }\n\n  /**\n   * A tool that allows the model to execute shell commands in a local environment.\n   */\n  export interface LocalShell {\n    /**\n     * The type of the local shell tool. Always `local_shell`.\n     */\n    type: 'local_shell';\n  }\n}\n\n/**\n * Constrains the tools available to the model to a pre-defined set.\n */\nexport interface ToolChoiceAllowed {\n  /**\n   * Constrains the tools available to the model to a pre-defined set.\n   *\n   * `auto` allows the model to pick from among the allowed tools and generate a\n   * message.\n   *\n   * `required` requires the model to call one or more of the allowed tools.\n   */\n  mode: 'auto' | 'required';\n\n  /**\n   * A list of tool definitions that the model should be allowed to call.\n   *\n   * For the Responses API, the list of tool definitions might look like:\n   *\n   * ```json\n   * [\n   *   { \"type\": \"function\", \"name\": \"get_weather\" },\n   *   { \"type\": \"mcp\", \"server_label\": \"deepwiki\" },\n   *   { \"type\": \"image_generation\" }\n   * ]\n   * ```\n   */\n  tools: Array<{ [key: string]: unknown }>;\n\n  /**\n   * Allowed tool configuration type. Always `allowed_tools`.\n   */\n  type: 'allowed_tools';\n}\n\n/**\n * Forces the model to call the apply_patch tool when executing a tool call.\n */\nexport interface ToolChoiceApplyPatch {\n  /**\n   * The tool to call. Always `apply_patch`.\n   */\n  type: 'apply_patch';\n}\n\n/**\n * Use this option to force the model to call a specific custom tool.\n */\nexport interface ToolChoiceCustom {\n  /**\n   * The name of the custom tool to call.\n   */\n  name: string;\n\n  /**\n   * For custom tool calling, the type is always `custom`.\n   */\n  type: 'custom';\n}\n\n/**\n * Use this option to force the model to call a specific function.\n */\nexport interface ToolChoiceFunction {\n  /**\n   * The name of the function to call.\n   */\n  name: string;\n\n  /**\n   * For function calling, the type is always `function`.\n   */\n  type: 'function';\n}\n\n/**\n * Use this option to force the model to call a specific tool on a remote MCP\n * server.\n */\nexport interface ToolChoiceMcp {\n  /**\n   * The label of the MCP server to use.\n   */\n  server_label: string;\n\n  /**\n   * For MCP tools, the type is always `mcp`.\n   */\n  type: 'mcp';\n\n  /**\n   * The name of the tool to call on the server.\n   */\n  name?: string | null;\n}\n\n/**\n * Controls which (if any) tool is called by the model.\n *\n * `none` means the model will not call any tool and instead generates a message.\n *\n * `auto` means the model can pick between generating a message or calling one or\n * more tools.\n *\n * `required` means the model must call one or more tools.\n */\nexport type ToolChoiceOptions = 'none' | 'auto' | 'required';\n\n/**\n * Forces the model to call the shell tool when a tool call is required.\n */\nexport interface ToolChoiceShell {\n  /**\n   * The tool to call. Always `shell`.\n   */\n  type: 'shell';\n}\n\n/**\n * Indicates that the model should use a built-in tool to generate a response.\n * [Learn more about built-in tools](https://platform.openai.com/docs/guides/tools).\n */\nexport interface ToolChoiceTypes {\n  /**\n   * The type of hosted tool the model should to use. Learn more about\n   * [built-in tools](https://platform.openai.com/docs/guides/tools).\n   *\n   * Allowed values are:\n   *\n   * - `file_search`\n   * - `web_search_preview`\n   * - `computer`\n   * - `computer_use_preview`\n   * - `computer_use`\n   * - `code_interpreter`\n   * - `mcp`\n   * - `image_generation`\n   */\n  type:\n    | 'file_search'\n    | 'web_search_preview'\n    | 'computer'\n    | 'computer_use_preview'\n    | 'computer_use'\n    | 'web_search_preview_2025_03_11'\n    | 'image_generation'\n    | 'code_interpreter'\n    | 'mcp';\n}\n\n/**\n * Hosted or BYOT tool search configuration for deferred tools.\n */\nexport interface ToolSearchTool {\n  /**\n   * The type of the tool. Always `tool_search`.\n   */\n  type: 'tool_search';\n\n  /**\n   * Description shown to the model for a client-executed tool search tool.\n   */\n  description?: string | null;\n\n  /**\n   * Whether tool search is executed by the server or by the client.\n   */\n  execution?: 'server' | 'client';\n\n  /**\n   * Parameter schema for a client-executed tool search tool.\n   */\n  parameters?: unknown | null;\n}\n\n/**\n * This tool searches the web for relevant results to use in a response. Learn more\n * about the\n * [web search tool](https://platform.openai.com/docs/guides/tools-web-search).\n */\nexport interface WebSearchPreviewTool {\n  /**\n   * The type of the web search tool. One of `web_search_preview` or\n   * `web_search_preview_2025_03_11`.\n   */\n  type: 'web_search_preview' | 'web_search_preview_2025_03_11';\n\n  search_content_types?: Array<'text' | 'image'>;\n\n  /**\n   * High level guidance for the amount of context window space to use for the\n   * search. One of `low`, `medium`, or `high`. `medium` is the default.\n   */\n  search_context_size?: 'low' | 'medium' | 'high';\n\n  /**\n   * The user's location.\n   */\n  user_location?: WebSearchPreviewTool.UserLocation | null;\n}\n\nexport namespace WebSearchPreviewTool {\n  /**\n   * The user's location.\n   */\n  export interface UserLocation {\n    /**\n     * The type of location approximation. Always `approximate`.\n     */\n    type: 'approximate';\n\n    /**\n     * Free text input for the city of the user, e.g. `San Francisco`.\n     */\n    city?: string | null;\n\n    /**\n     * The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of\n     * the user, e.g. `US`.\n     */\n    country?: string | null;\n\n    /**\n     * Free text input for the region of the user, e.g. `California`.\n     */\n    region?: string | null;\n\n    /**\n     * The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the\n     * user, e.g. `America/Los_Angeles`.\n     */\n    timezone?: string | null;\n  }\n}\n\n/**\n * Search the Internet for sources related to the prompt. Learn more about the\n * [web search tool](https://platform.openai.com/docs/guides/tools-web-search).\n */\nexport interface WebSearchTool {\n  /**\n   * The type of the web search tool. One of `web_search` or `web_search_2025_08_26`.\n   */\n  type: 'web_search' | 'web_search_2025_08_26';\n\n  /**\n   * Filters for the search.\n   */\n  filters?: WebSearchTool.Filters | null;\n\n  /**\n   * High level guidance for the amount of context window space to use for the\n   * search. One of `low`, `medium`, or `high`. `medium` is the default.\n   */\n  search_context_size?: 'low' | 'medium' | 'high';\n\n  /**\n   * The approximate location of the user.\n   */\n  user_location?: WebSearchTool.UserLocation | null;\n}\n\nexport namespace WebSearchTool {\n  /**\n   * Filters for the search.\n   */\n  export interface Filters {\n    /**\n     * Allowed domains for the search. If not provided, all domains are allowed.\n     * Subdomains of the provided domains are allowed as well.\n     *\n     * Example: `[\"pubmed.ncbi.nlm.nih.gov\"]`\n     */\n    allowed_domains?: Array<string> | null;\n  }\n\n  /**\n   * The approximate location of the user.\n   */\n  export interface UserLocation {\n    /**\n     * Free text input for the city of the user, e.g. `San Francisco`.\n     */\n    city?: string | null;\n\n    /**\n     * The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of\n     * the user, e.g. `US`.\n     */\n    country?: string | null;\n\n    /**\n     * Free text input for the region of the user, e.g. `California`.\n     */\n    region?: string | null;\n\n    /**\n     * The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the\n     * user, e.g. `America/Los_Angeles`.\n     */\n    timezone?: string | null;\n\n    /**\n     * The type of location approximation. Always `approximate`.\n     */\n    type?: 'approximate';\n  }\n}\n\nexport type ResponseCreateParams = ResponseCreateParamsNonStreaming | ResponseCreateParamsStreaming;\n\nexport interface ResponseCreateParamsBase {\n  /**\n   * Whether to run the model response in the background.\n   * [Learn more](https://platform.openai.com/docs/guides/background).\n   */\n  background?: boolean | null;\n\n  /**\n   * Context management configuration for this request.\n   */\n  context_management?: Array<ResponseCreateParams.ContextManagement> | null;\n\n  /**\n   * The conversation that this response belongs to. Items from this conversation are\n   * prepended to `input_items` for this response request. Input items and output\n   * items from this response are automatically added to this conversation after this\n   * response completes.\n   */\n  conversation?: string | ResponseConversationParam | null;\n\n  /**\n   * Specify additional output data to include in the model response. Currently\n   * supported values are:\n   *\n   * - `web_search_call.action.sources`: Include the sources of the web search tool\n   *   call.\n   * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n   *   in code interpreter tool call items.\n   * - `computer_call_output.output.image_url`: Include image urls from the computer\n   *   call output.\n   * - `file_search_call.results`: Include the search results of the file search tool\n   *   call.\n   * - `message.input_image.image_url`: Include image urls from the input message.\n   * - `computer_call_output.output.image_url`: Include image urls from the computer\n   *   call output.\n   * - `reasoning.encrypted_content`: Includes an encrypted version of reasoning\n   *   tokens in reasoning item outputs. This enables reasoning items to be used in\n   *   multi-turn conversations when using the Responses API statelessly (like when\n   *   the `store` parameter is set to `false`, or when an organization is enrolled\n   *   in the zero data retention program).\n   * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n   *   in code interpreter tool call items.\n   */\n  include?: Array<ResponseIncludable> | null;\n\n  /**\n   * Text, image, or file inputs to the model, used to generate a response.\n   *\n   * Learn more:\n   *\n   * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n   * - [Image inputs](https://platform.openai.com/docs/guides/images)\n   * - [File inputs](https://platform.openai.com/docs/guides/pdf-files)\n   * - [Conversation state](https://platform.openai.com/docs/guides/conversation-state)\n   * - [Function calling](https://platform.openai.com/docs/guides/function-calling)\n   */\n  input?: string | ResponseInput;\n\n  /**\n   * A system (or developer) message inserted into the model's context.\n   *\n   * When using along with `previous_response_id`, the instructions from a previous\n   * response will not be carried over to the next response. This makes it simple to\n   * swap out system (or developer) messages in new responses.\n   */\n  instructions?: string | null;\n\n  /**\n   * An upper bound for the number of tokens that can be generated for a response,\n   * including visible output tokens and\n   * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).\n   */\n  max_output_tokens?: number | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a\n   * wide range of models with different capabilities, performance characteristics,\n   * and price points. Refer to the\n   * [model guide](https://platform.openai.com/docs/models) to browse and compare\n   * available models.\n   */\n  model?: Shared.ResponsesModel;\n\n  /**\n   * Whether to allow the model to run tool calls in parallel.\n   */\n  parallel_tool_calls?: boolean | null;\n\n  /**\n   * The unique ID of the previous response to the model. Use this to create\n   * multi-turn conversations. Learn more about\n   * [conversation state](https://platform.openai.com/docs/guides/conversation-state).\n   * Cannot be used in conjunction with `conversation`.\n   */\n  previous_response_id?: string | null;\n\n  /**\n   * Reference to a prompt template and its variables.\n   * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n   */\n  prompt?: ResponsePrompt | null;\n\n  /**\n   * Used by OpenAI to cache responses for similar requests to optimize your cache\n   * hit rates. Replaces the `user` field.\n   * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n   */\n  prompt_cache_key?: string;\n\n  /**\n   * The retention policy for the prompt cache. Set to `24h` to enable extended\n   * prompt caching, which keeps cached prefixes active for longer, up to a maximum\n   * of 24 hours.\n   * [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).\n   */\n  prompt_cache_retention?: 'in-memory' | '24h' | null;\n\n  /**\n   * **gpt-5 and o-series models only**\n   *\n   * Configuration options for\n   * [reasoning models](https://platform.openai.com/docs/guides/reasoning).\n   */\n  reasoning?: Shared.Reasoning | null;\n\n  /**\n   * A stable identifier used to help detect users of your application that may be\n   * violating OpenAI's usage policies. The IDs should be a string that uniquely\n   * identifies each user, with a maximum length of 64 characters. We recommend\n   * hashing their username or email address, in order to avoid sending us any\n   * identifying information.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n   */\n  safety_identifier?: string;\n\n  /**\n   * Specifies the latency tier to use for processing the request. This parameter is\n   * relevant for customers subscribed to the scale tier service:\n   *\n   * - If set to 'auto', then the request will be processed with the service tier\n   *   configured in the Project settings. Unless otherwise configured, the Project\n   *   will use 'default'.\n   * - If set to 'default', then the request will be processed with the standard\n   *   pricing and performance for the selected model.\n   * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n   *   '[priority](https://openai.com/api-priority-processing/)', then the request\n   *   will be processed with the corresponding service tier.\n   * - When not set, the default behavior is 'auto'.\n   *\n   * When this parameter is set, the response body will include the `service_tier`\n   * utilized.\n   */\n  service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n  /**\n   * Whether to store the generated model response for later retrieval via API.\n   */\n  store?: boolean | null;\n\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n   * for more information.\n   */\n  stream?: boolean | null;\n\n  /**\n   * Options for streaming responses. Only set this when you set `stream: true`.\n   */\n  stream_options?: ResponseCreateParams.StreamOptions | null;\n\n  /**\n   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n   * make the output more random, while lower values like 0.2 will make it more\n   * focused and deterministic. We generally recommend altering this or `top_p` but\n   * not both.\n   */\n  temperature?: number | null;\n\n  /**\n   * Configuration options for a text response from the model. Can be plain text or\n   * structured JSON data. Learn more:\n   *\n   * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n   * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n   */\n  text?: ResponseTextConfig;\n\n  /**\n   * How the model should select which tool (or tools) to use when generating a\n   * response. See the `tools` parameter to see how to specify which tools the model\n   * can call.\n   */\n  tool_choice?:\n    | ToolChoiceOptions\n    | ToolChoiceAllowed\n    | ToolChoiceTypes\n    | ToolChoiceFunction\n    | ToolChoiceMcp\n    | ToolChoiceCustom\n    | ToolChoiceApplyPatch\n    | ToolChoiceShell;\n\n  /**\n   * An array of tools the model may call while generating a response. You can\n   * specify which tool to use by setting the `tool_choice` parameter.\n   *\n   * We support the following categories of tools:\n   *\n   * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n   *   capabilities, like\n   *   [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n   *   [file search](https://platform.openai.com/docs/guides/tools-file-search).\n   *   Learn more about\n   *   [built-in tools](https://platform.openai.com/docs/guides/tools).\n   * - **MCP Tools**: Integrations with third-party systems via custom MCP servers or\n   *   predefined connectors such as Google Drive and SharePoint. Learn more about\n   *   [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).\n   * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n   *   the model to call your own code with strongly typed arguments and outputs.\n   *   Learn more about\n   *   [function calling](https://platform.openai.com/docs/guides/function-calling).\n   *   You can also use custom tools to call your own code.\n   */\n  tools?: Array<Tool>;\n\n  /**\n   * An alternative to sampling with temperature, called nucleus sampling, where the\n   * model considers the results of the tokens with top_p probability mass. So 0.1\n   * means only the tokens comprising the top 10% probability mass are considered.\n   *\n   * We generally recommend altering this or `temperature` but not both.\n   */\n  top_p?: number | null;\n\n  /**\n   * The truncation strategy to use for the model response.\n   *\n   * - `auto`: If the input to this Response exceeds the model's context window size,\n   *   the model will truncate the response to fit the context window by dropping\n   *   items from the beginning of the conversation.\n   * - `disabled` (default): If the input size will exceed the context window size\n   *   for a model, the request will fail with a 400 error.\n   */\n  truncation?: 'auto' | 'disabled' | null;\n\n  /**\n   * @deprecated This field is being replaced by `safety_identifier` and\n   * `prompt_cache_key`. Use `prompt_cache_key` instead to maintain caching\n   * optimizations. A stable identifier for your end-users. Used to boost cache hit\n   * rates by better bucketing similar requests and to help OpenAI detect and prevent\n   * abuse.\n   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n   */\n  user?: string;\n}\n\nexport namespace ResponseCreateParams {\n  export interface ContextManagement {\n    /**\n     * The context management entry type. Currently only 'compaction' is supported.\n     */\n    type: string;\n\n    /**\n     * Token threshold at which compaction should be triggered for this entry.\n     */\n    compact_threshold?: number | null;\n  }\n\n  /**\n   * Options for streaming responses. Only set this when you set `stream: true`.\n   */\n  export interface StreamOptions {\n    /**\n     * When true, stream obfuscation will be enabled. Stream obfuscation adds random\n     * characters to an `obfuscation` field on streaming delta events to normalize\n     * payload sizes as a mitigation to certain side-channel attacks. These obfuscation\n     * fields are included by default, but add a small amount of overhead to the data\n     * stream. You can set `include_obfuscation` to false to optimize for bandwidth if\n     * you trust the network links between your application and the OpenAI API.\n     */\n    include_obfuscation?: boolean;\n  }\n\n  export type ResponseCreateParamsNonStreaming = ResponsesAPI.ResponseCreateParamsNonStreaming;\n  export type ResponseCreateParamsStreaming = ResponsesAPI.ResponseCreateParamsStreaming;\n}\n\nexport interface ResponseCreateParamsNonStreaming extends ResponseCreateParamsBase {\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n   * for more information.\n   */\n  stream?: false | null;\n}\n\nexport interface ResponseCreateParamsStreaming extends ResponseCreateParamsBase {\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n   * for more information.\n   */\n  stream: true;\n}\n\nexport type ResponseRetrieveParams = ResponseRetrieveParamsNonStreaming | ResponseRetrieveParamsStreaming;\n\nexport interface ResponseRetrieveParamsBase {\n  /**\n   * Additional fields to include in the response. See the `include` parameter for\n   * Response creation above for more information.\n   */\n  include?: Array<ResponseIncludable>;\n\n  /**\n   * When true, stream obfuscation will be enabled. Stream obfuscation adds random\n   * characters to an `obfuscation` field on streaming delta events to normalize\n   * payload sizes as a mitigation to certain side-channel attacks. These obfuscation\n   * fields are included by default, but add a small amount of overhead to the data\n   * stream. You can set `include_obfuscation` to false to optimize for bandwidth if\n   * you trust the network links between your application and the OpenAI API.\n   */\n  include_obfuscation?: boolean;\n\n  /**\n   * The sequence number of the event after which to start streaming.\n   */\n  starting_after?: number;\n\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n   * for more information.\n   */\n  stream?: boolean;\n}\n\nexport namespace ResponseRetrieveParams {\n  export type ResponseRetrieveParamsNonStreaming = ResponsesAPI.ResponseRetrieveParamsNonStreaming;\n  export type ResponseRetrieveParamsStreaming = ResponsesAPI.ResponseRetrieveParamsStreaming;\n}\n\nexport interface ResponseRetrieveParamsNonStreaming extends ResponseRetrieveParamsBase {\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n   * for more information.\n   */\n  stream?: false;\n}\n\nexport interface ResponseRetrieveParamsStreaming extends ResponseRetrieveParamsBase {\n  /**\n   * If set to true, the model response data will be streamed to the client as it is\n   * generated using\n   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n   * See the\n   * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n   * for more information.\n   */\n  stream: true;\n}\n\nexport interface ResponseCompactParams {\n  /**\n   * Model ID used to generate the response, like `gpt-5` or `o3`. OpenAI offers a\n   * wide range of models with different capabilities, performance characteristics,\n   * and price points. Refer to the\n   * [model guide](https://platform.openai.com/docs/models) to browse and compare\n   * available models.\n   */\n  model:\n    | 'gpt-5.4'\n    | 'gpt-5.4-mini'\n    | 'gpt-5.4-nano'\n    | 'gpt-5.4-mini-2026-03-17'\n    | 'gpt-5.4-nano-2026-03-17'\n    | 'gpt-5.3-chat-latest'\n    | 'gpt-5.2'\n    | 'gpt-5.2-2025-12-11'\n    | 'gpt-5.2-chat-latest'\n    | 'gpt-5.2-pro'\n    | 'gpt-5.2-pro-2025-12-11'\n    | 'gpt-5.1'\n    | 'gpt-5.1-2025-11-13'\n    | 'gpt-5.1-codex'\n    | 'gpt-5.1-mini'\n    | 'gpt-5.1-chat-latest'\n    | 'gpt-5'\n    | 'gpt-5-mini'\n    | 'gpt-5-nano'\n    | 'gpt-5-2025-08-07'\n    | 'gpt-5-mini-2025-08-07'\n    | 'gpt-5-nano-2025-08-07'\n    | 'gpt-5-chat-latest'\n    | 'gpt-4.1'\n    | 'gpt-4.1-mini'\n    | 'gpt-4.1-nano'\n    | 'gpt-4.1-2025-04-14'\n    | 'gpt-4.1-mini-2025-04-14'\n    | 'gpt-4.1-nano-2025-04-14'\n    | 'o4-mini'\n    | 'o4-mini-2025-04-16'\n    | 'o3'\n    | 'o3-2025-04-16'\n    | 'o3-mini'\n    | 'o3-mini-2025-01-31'\n    | 'o1'\n    | 'o1-2024-12-17'\n    | 'o1-preview'\n    | 'o1-preview-2024-09-12'\n    | 'o1-mini'\n    | 'o1-mini-2024-09-12'\n    | 'gpt-4o'\n    | 'gpt-4o-2024-11-20'\n    | 'gpt-4o-2024-08-06'\n    | 'gpt-4o-2024-05-13'\n    | 'gpt-4o-audio-preview'\n    | 'gpt-4o-audio-preview-2024-10-01'\n    | 'gpt-4o-audio-preview-2024-12-17'\n    | 'gpt-4o-audio-preview-2025-06-03'\n    | 'gpt-4o-mini-audio-preview'\n    | 'gpt-4o-mini-audio-preview-2024-12-17'\n    | 'gpt-4o-search-preview'\n    | 'gpt-4o-mini-search-preview'\n    | 'gpt-4o-search-preview-2025-03-11'\n    | 'gpt-4o-mini-search-preview-2025-03-11'\n    | 'chatgpt-4o-latest'\n    | 'codex-mini-latest'\n    | 'gpt-4o-mini'\n    | 'gpt-4o-mini-2024-07-18'\n    | 'gpt-4-turbo'\n    | 'gpt-4-turbo-2024-04-09'\n    | 'gpt-4-0125-preview'\n    | 'gpt-4-turbo-preview'\n    | 'gpt-4-1106-preview'\n    | 'gpt-4-vision-preview'\n    | 'gpt-4'\n    | 'gpt-4-0314'\n    | 'gpt-4-0613'\n    | 'gpt-4-32k'\n    | 'gpt-4-32k-0314'\n    | 'gpt-4-32k-0613'\n    | 'gpt-3.5-turbo'\n    | 'gpt-3.5-turbo-16k'\n    | 'gpt-3.5-turbo-0301'\n    | 'gpt-3.5-turbo-0613'\n    | 'gpt-3.5-turbo-1106'\n    | 'gpt-3.5-turbo-0125'\n    | 'gpt-3.5-turbo-16k-0613'\n    | 'o1-pro'\n    | 'o1-pro-2025-03-19'\n    | 'o3-pro'\n    | 'o3-pro-2025-06-10'\n    | 'o3-deep-research'\n    | 'o3-deep-research-2025-06-26'\n    | 'o4-mini-deep-research'\n    | 'o4-mini-deep-research-2025-06-26'\n    | 'computer-use-preview'\n    | 'computer-use-preview-2025-03-11'\n    | 'gpt-5-codex'\n    | 'gpt-5-pro'\n    | 'gpt-5-pro-2025-10-06'\n    | 'gpt-5.1-codex-max'\n    | (string & {})\n    | null;\n\n  /**\n   * Text, image, or file inputs to the model, used to generate a response\n   */\n  input?: string | Array<ResponseInputItem> | null;\n\n  /**\n   * A system (or developer) message inserted into the model's context. When used\n   * along with `previous_response_id`, the instructions from a previous response\n   * will not be carried over to the next response. This makes it simple to swap out\n   * system (or developer) messages in new responses.\n   */\n  instructions?: string | null;\n\n  /**\n   * The unique ID of the previous response to the model. Use this to create\n   * multi-turn conversations. Learn more about\n   * [conversation state](https://platform.openai.com/docs/guides/conversation-state).\n   * Cannot be used in conjunction with `conversation`.\n   */\n  previous_response_id?: string | null;\n\n  /**\n   * A key to use when reading from or writing to the prompt cache.\n   */\n  prompt_cache_key?: string | null;\n}\n\nResponses.InputItems = InputItems;\nResponses.InputTokens = InputTokens;\n\nexport declare namespace Responses {\n  export {\n    type ApplyPatchTool as ApplyPatchTool,\n    type CompactedResponse as CompactedResponse,\n    type ComputerAction as ComputerAction,\n    type ComputerActionList as ComputerActionList,\n    type ComputerTool as ComputerTool,\n    type ComputerUsePreviewTool as ComputerUsePreviewTool,\n    type ContainerAuto as ContainerAuto,\n    type ContainerNetworkPolicyAllowlist as ContainerNetworkPolicyAllowlist,\n    type ContainerNetworkPolicyDisabled as ContainerNetworkPolicyDisabled,\n    type ContainerNetworkPolicyDomainSecret as ContainerNetworkPolicyDomainSecret,\n    type ContainerReference as ContainerReference,\n    type CustomTool as CustomTool,\n    type EasyInputMessage as EasyInputMessage,\n    type FileSearchTool as FileSearchTool,\n    type FunctionShellTool as FunctionShellTool,\n    type FunctionTool as FunctionTool,\n    type InlineSkill as InlineSkill,\n    type InlineSkillSource as InlineSkillSource,\n    type LocalEnvironment as LocalEnvironment,\n    type LocalSkill as LocalSkill,\n    type NamespaceTool as NamespaceTool,\n    type Response as Response,\n    type ResponseApplyPatchToolCall as ResponseApplyPatchToolCall,\n    type ResponseApplyPatchToolCallOutput as ResponseApplyPatchToolCallOutput,\n    type ResponseAudioDeltaEvent as ResponseAudioDeltaEvent,\n    type ResponseAudioDoneEvent as ResponseAudioDoneEvent,\n    type ResponseAudioTranscriptDeltaEvent as ResponseAudioTranscriptDeltaEvent,\n    type ResponseAudioTranscriptDoneEvent as ResponseAudioTranscriptDoneEvent,\n    type ResponseCodeInterpreterCallCodeDeltaEvent as ResponseCodeInterpreterCallCodeDeltaEvent,\n    type ResponseCodeInterpreterCallCodeDoneEvent as ResponseCodeInterpreterCallCodeDoneEvent,\n    type ResponseCodeInterpreterCallCompletedEvent as ResponseCodeInterpreterCallCompletedEvent,\n    type ResponseCodeInterpreterCallInProgressEvent as ResponseCodeInterpreterCallInProgressEvent,\n    type ResponseCodeInterpreterCallInterpretingEvent as ResponseCodeInterpreterCallInterpretingEvent,\n    type ResponseCodeInterpreterToolCall as ResponseCodeInterpreterToolCall,\n    type ResponseCompactionItem as ResponseCompactionItem,\n    type ResponseCompactionItemParam as ResponseCompactionItemParam,\n    type ResponseCompletedEvent as ResponseCompletedEvent,\n    type ResponseComputerToolCall as ResponseComputerToolCall,\n    type ResponseComputerToolCallOutputItem as ResponseComputerToolCallOutputItem,\n    type ResponseComputerToolCallOutputScreenshot as ResponseComputerToolCallOutputScreenshot,\n    type ResponseContainerReference as ResponseContainerReference,\n    type ResponseContent as ResponseContent,\n    type ResponseContentPartAddedEvent as ResponseContentPartAddedEvent,\n    type ResponseContentPartDoneEvent as ResponseContentPartDoneEvent,\n    type ResponseConversationParam as ResponseConversationParam,\n    type ResponseCreatedEvent as ResponseCreatedEvent,\n    type ResponseCustomToolCall as ResponseCustomToolCall,\n    type ResponseCustomToolCallInputDeltaEvent as ResponseCustomToolCallInputDeltaEvent,\n    type ResponseCustomToolCallInputDoneEvent as ResponseCustomToolCallInputDoneEvent,\n    type ResponseCustomToolCallOutput as ResponseCustomToolCallOutput,\n    type ResponseError as ResponseError,\n    type ResponseErrorEvent as ResponseErrorEvent,\n    type ResponseFailedEvent as ResponseFailedEvent,\n    type ResponseFileSearchCallCompletedEvent as ResponseFileSearchCallCompletedEvent,\n    type ResponseFileSearchCallInProgressEvent as ResponseFileSearchCallInProgressEvent,\n    type ResponseFileSearchCallSearchingEvent as ResponseFileSearchCallSearchingEvent,\n    type ResponseFileSearchToolCall as ResponseFileSearchToolCall,\n    type ResponseFormatTextConfig as ResponseFormatTextConfig,\n    type ResponseFormatTextJSONSchemaConfig as ResponseFormatTextJSONSchemaConfig,\n    type ResponseFunctionCallArgumentsDeltaEvent as ResponseFunctionCallArgumentsDeltaEvent,\n    type ResponseFunctionCallArgumentsDoneEvent as ResponseFunctionCallArgumentsDoneEvent,\n    type ResponseFunctionCallOutputItem as ResponseFunctionCallOutputItem,\n    type ResponseFunctionCallOutputItemList as ResponseFunctionCallOutputItemList,\n    type ResponseFunctionShellCallOutputContent as ResponseFunctionShellCallOutputContent,\n    type ResponseFunctionShellToolCall as ResponseFunctionShellToolCall,\n    type ResponseFunctionShellToolCallOutput as ResponseFunctionShellToolCallOutput,\n    type ResponseFunctionToolCall as ResponseFunctionToolCall,\n    type ResponseFunctionToolCallItem as ResponseFunctionToolCallItem,\n    type ResponseFunctionToolCallOutputItem as ResponseFunctionToolCallOutputItem,\n    type ResponseFunctionWebSearch as ResponseFunctionWebSearch,\n    type ResponseImageGenCallCompletedEvent as ResponseImageGenCallCompletedEvent,\n    type ResponseImageGenCallGeneratingEvent as ResponseImageGenCallGeneratingEvent,\n    type ResponseImageGenCallInProgressEvent as ResponseImageGenCallInProgressEvent,\n    type ResponseImageGenCallPartialImageEvent as ResponseImageGenCallPartialImageEvent,\n    type ResponseInProgressEvent as ResponseInProgressEvent,\n    type ResponseIncludable as ResponseIncludable,\n    type ResponseIncompleteEvent as ResponseIncompleteEvent,\n    type ResponseInput as ResponseInput,\n    type ResponseInputAudio as ResponseInputAudio,\n    type ResponseInputContent as ResponseInputContent,\n    type ResponseInputFile as ResponseInputFile,\n    type ResponseInputFileContent as ResponseInputFileContent,\n    type ResponseInputImage as ResponseInputImage,\n    type ResponseInputImageContent as ResponseInputImageContent,\n    type ResponseInputItem as ResponseInputItem,\n    type ResponseInputMessageContentList as ResponseInputMessageContentList,\n    type ResponseInputMessageItem as ResponseInputMessageItem,\n    type ResponseInputText as ResponseInputText,\n    type ResponseInputTextContent as ResponseInputTextContent,\n    type ResponseItem as ResponseItem,\n    type ResponseLocalEnvironment as ResponseLocalEnvironment,\n    type ResponseMcpCallArgumentsDeltaEvent as ResponseMcpCallArgumentsDeltaEvent,\n    type ResponseMcpCallArgumentsDoneEvent as ResponseMcpCallArgumentsDoneEvent,\n    type ResponseMcpCallCompletedEvent as ResponseMcpCallCompletedEvent,\n    type ResponseMcpCallFailedEvent as ResponseMcpCallFailedEvent,\n    type ResponseMcpCallInProgressEvent as ResponseMcpCallInProgressEvent,\n    type ResponseMcpListToolsCompletedEvent as ResponseMcpListToolsCompletedEvent,\n    type ResponseMcpListToolsFailedEvent as ResponseMcpListToolsFailedEvent,\n    type ResponseMcpListToolsInProgressEvent as ResponseMcpListToolsInProgressEvent,\n    type ResponseOutputAudio as ResponseOutputAudio,\n    type ResponseOutputItem as ResponseOutputItem,\n    type ResponseOutputItemAddedEvent as ResponseOutputItemAddedEvent,\n    type ResponseOutputItemDoneEvent as ResponseOutputItemDoneEvent,\n    type ResponseOutputMessage as ResponseOutputMessage,\n    type ResponseOutputRefusal as ResponseOutputRefusal,\n    type ResponseOutputText as ResponseOutputText,\n    type ResponseOutputTextAnnotationAddedEvent as ResponseOutputTextAnnotationAddedEvent,\n    type ResponsePrompt as ResponsePrompt,\n    type ResponseQueuedEvent as ResponseQueuedEvent,\n    type ResponseReasoningItem as ResponseReasoningItem,\n    type ResponseReasoningSummaryPartAddedEvent as ResponseReasoningSummaryPartAddedEvent,\n    type ResponseReasoningSummaryPartDoneEvent as ResponseReasoningSummaryPartDoneEvent,\n    type ResponseReasoningSummaryTextDeltaEvent as ResponseReasoningSummaryTextDeltaEvent,\n    type ResponseReasoningSummaryTextDoneEvent as ResponseReasoningSummaryTextDoneEvent,\n    type ResponseReasoningTextDeltaEvent as ResponseReasoningTextDeltaEvent,\n    type ResponseReasoningTextDoneEvent as ResponseReasoningTextDoneEvent,\n    type ResponseRefusalDeltaEvent as ResponseRefusalDeltaEvent,\n    type ResponseRefusalDoneEvent as ResponseRefusalDoneEvent,\n    type ResponseStatus as ResponseStatus,\n    type ResponseStreamEvent as ResponseStreamEvent,\n    type ResponseTextConfig as ResponseTextConfig,\n    type ResponseTextDeltaEvent as ResponseTextDeltaEvent,\n    type ResponseTextDoneEvent as ResponseTextDoneEvent,\n    type ResponseToolSearchCall as ResponseToolSearchCall,\n    type ResponseToolSearchOutputItem as ResponseToolSearchOutputItem,\n    type ResponseToolSearchOutputItemParam as ResponseToolSearchOutputItemParam,\n    type ResponseUsage as ResponseUsage,\n    type ResponseWebSearchCallCompletedEvent as ResponseWebSearchCallCompletedEvent,\n    type ResponseWebSearchCallInProgressEvent as ResponseWebSearchCallInProgressEvent,\n    type ResponseWebSearchCallSearchingEvent as ResponseWebSearchCallSearchingEvent,\n    type ResponsesClientEvent as ResponsesClientEvent,\n    type ResponsesServerEvent as ResponsesServerEvent,\n    type SkillReference as SkillReference,\n    type Tool as Tool,\n    type ToolChoiceAllowed as ToolChoiceAllowed,\n    type ToolChoiceApplyPatch as ToolChoiceApplyPatch,\n    type ToolChoiceCustom as ToolChoiceCustom,\n    type ToolChoiceFunction as ToolChoiceFunction,\n    type ToolChoiceMcp as ToolChoiceMcp,\n    type ToolChoiceOptions as ToolChoiceOptions,\n    type ToolChoiceShell as ToolChoiceShell,\n    type ToolChoiceTypes as ToolChoiceTypes,\n    type ToolSearchTool as ToolSearchTool,\n    type WebSearchPreviewTool as WebSearchPreviewTool,\n    type WebSearchTool as WebSearchTool,\n    type ResponseCreateParams as ResponseCreateParams,\n    type ResponseCreateParamsNonStreaming as ResponseCreateParamsNonStreaming,\n    type ResponseCreateParamsStreaming as ResponseCreateParamsStreaming,\n    type ResponseRetrieveParams as ResponseRetrieveParams,\n    type ResponseRetrieveParamsNonStreaming as ResponseRetrieveParamsNonStreaming,\n    type ResponseRetrieveParamsStreaming as ResponseRetrieveParamsStreaming,\n    type ResponseCompactParams as ResponseCompactParams,\n  };\n\n  export {\n    InputItems as InputItems,\n    type ResponseItemList as ResponseItemList,\n    type InputItemListParams as InputItemListParams,\n  };\n\n  export {\n    InputTokens as InputTokens,\n    type InputTokenCountResponse as InputTokenCountResponse,\n    type InputTokenCountParams as InputTokenCountParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/responses/ws.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport * as WS from 'ws';\nimport { ResponsesEmitter, buildURL } from './internal-base';\nimport * as ResponsesAPI from './responses';\nimport { OpenAI } from '../../client';\n\nexport class ResponsesWS extends ResponsesEmitter {\n  url: URL;\n  socket: WS.WebSocket;\n  private client: OpenAI;\n\n  constructor(client: OpenAI, options?: WS.ClientOptions | null | undefined) {\n    super();\n    this.client = client;\n    this.url = buildURL(client, {});\n    this.socket = new WS.WebSocket(this.url, {\n      ...options,\n      headers: {\n        ...this.authHeaders(),\n        ...options?.headers,\n      },\n    });\n\n    this.socket.on('message', (wsEvent) => {\n      const event = (() => {\n        try {\n          return JSON.parse(wsEvent.toString()) as ResponsesAPI.ResponsesServerEvent;\n        } catch (err) {\n          this._onError(null, 'could not parse websocket event', err);\n          return null;\n        }\n      })();\n\n      if (event) {\n        this._emit('event', event);\n\n        if (event.type === 'error') {\n          this._onError(event);\n        } else {\n          // @ts-ignore TS isn't smart enough to get the relationship right here\n          this._emit(event.type, event);\n        }\n      }\n    });\n\n    this.socket.on('error', (err) => {\n      this._onError(null, err.message, err);\n    });\n  }\n\n  send(event: ResponsesAPI.ResponsesClientEvent) {\n    try {\n      this.socket.send(JSON.stringify(event));\n    } catch (err) {\n      this._onError(null, 'could not send data', err);\n    }\n  }\n\n  close(props?: { code: number; reason: string }) {\n    try {\n      this.socket.close(props?.code ?? 1000, props?.reason ?? 'OK');\n    } catch (err) {\n      this._onError(null, 'could not close the connection', err);\n    }\n  }\n\n  private authHeaders(): Record<string, string> {\n    return { Authorization: `Bearer ${this.client.apiKey}` };\n    return {};\n  }\n}\n"
  },
  {
    "path": "src/resources/responses.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './responses/index';\n"
  },
  {
    "path": "src/resources/shared.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport type AllModels =\n  | (string & {})\n  | ChatModel\n  | 'o1-pro'\n  | 'o1-pro-2025-03-19'\n  | 'o3-pro'\n  | 'o3-pro-2025-06-10'\n  | 'o3-deep-research'\n  | 'o3-deep-research-2025-06-26'\n  | 'o4-mini-deep-research'\n  | 'o4-mini-deep-research-2025-06-26'\n  | 'computer-use-preview'\n  | 'computer-use-preview-2025-03-11'\n  | 'gpt-5-codex'\n  | 'gpt-5-pro'\n  | 'gpt-5-pro-2025-10-06'\n  | 'gpt-5.1-codex-max';\n\nexport type ChatModel =\n  | 'gpt-5.4'\n  | 'gpt-5.4-mini'\n  | 'gpt-5.4-nano'\n  | 'gpt-5.4-mini-2026-03-17'\n  | 'gpt-5.4-nano-2026-03-17'\n  | 'gpt-5.3-chat-latest'\n  | 'gpt-5.2'\n  | 'gpt-5.2-2025-12-11'\n  | 'gpt-5.2-chat-latest'\n  | 'gpt-5.2-pro'\n  | 'gpt-5.2-pro-2025-12-11'\n  | 'gpt-5.1'\n  | 'gpt-5.1-2025-11-13'\n  | 'gpt-5.1-codex'\n  | 'gpt-5.1-mini'\n  | 'gpt-5.1-chat-latest'\n  | 'gpt-5'\n  | 'gpt-5-mini'\n  | 'gpt-5-nano'\n  | 'gpt-5-2025-08-07'\n  | 'gpt-5-mini-2025-08-07'\n  | 'gpt-5-nano-2025-08-07'\n  | 'gpt-5-chat-latest'\n  | 'gpt-4.1'\n  | 'gpt-4.1-mini'\n  | 'gpt-4.1-nano'\n  | 'gpt-4.1-2025-04-14'\n  | 'gpt-4.1-mini-2025-04-14'\n  | 'gpt-4.1-nano-2025-04-14'\n  | 'o4-mini'\n  | 'o4-mini-2025-04-16'\n  | 'o3'\n  | 'o3-2025-04-16'\n  | 'o3-mini'\n  | 'o3-mini-2025-01-31'\n  | 'o1'\n  | 'o1-2024-12-17'\n  | 'o1-preview'\n  | 'o1-preview-2024-09-12'\n  | 'o1-mini'\n  | 'o1-mini-2024-09-12'\n  | 'gpt-4o'\n  | 'gpt-4o-2024-11-20'\n  | 'gpt-4o-2024-08-06'\n  | 'gpt-4o-2024-05-13'\n  | 'gpt-4o-audio-preview'\n  | 'gpt-4o-audio-preview-2024-10-01'\n  | 'gpt-4o-audio-preview-2024-12-17'\n  | 'gpt-4o-audio-preview-2025-06-03'\n  | 'gpt-4o-mini-audio-preview'\n  | 'gpt-4o-mini-audio-preview-2024-12-17'\n  | 'gpt-4o-search-preview'\n  | 'gpt-4o-mini-search-preview'\n  | 'gpt-4o-search-preview-2025-03-11'\n  | 'gpt-4o-mini-search-preview-2025-03-11'\n  | 'chatgpt-4o-latest'\n  | 'codex-mini-latest'\n  | 'gpt-4o-mini'\n  | 'gpt-4o-mini-2024-07-18'\n  | 'gpt-4-turbo'\n  | 'gpt-4-turbo-2024-04-09'\n  | 'gpt-4-0125-preview'\n  | 'gpt-4-turbo-preview'\n  | 'gpt-4-1106-preview'\n  | 'gpt-4-vision-preview'\n  | 'gpt-4'\n  | 'gpt-4-0314'\n  | 'gpt-4-0613'\n  | 'gpt-4-32k'\n  | 'gpt-4-32k-0314'\n  | 'gpt-4-32k-0613'\n  | 'gpt-3.5-turbo'\n  | 'gpt-3.5-turbo-16k'\n  | 'gpt-3.5-turbo-0301'\n  | 'gpt-3.5-turbo-0613'\n  | 'gpt-3.5-turbo-1106'\n  | 'gpt-3.5-turbo-0125'\n  | 'gpt-3.5-turbo-16k-0613';\n\n/**\n * A filter used to compare a specified attribute key to a given value using a\n * defined comparison operation.\n */\nexport interface ComparisonFilter {\n  /**\n   * The key to compare against the value.\n   */\n  key: string;\n\n  /**\n   * Specifies the comparison operator: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `in`,\n   * `nin`.\n   *\n   * - `eq`: equals\n   * - `ne`: not equal\n   * - `gt`: greater than\n   * - `gte`: greater than or equal\n   * - `lt`: less than\n   * - `lte`: less than or equal\n   * - `in`: in\n   * - `nin`: not in\n   */\n  type: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'nin';\n\n  /**\n   * The value to compare against the attribute key; supports string, number, or\n   * boolean types.\n   */\n  value: string | number | boolean | Array<string | number>;\n}\n\n/**\n * Combine multiple filters using `and` or `or`.\n */\nexport interface CompoundFilter {\n  /**\n   * Array of filters to combine. Items can be `ComparisonFilter` or\n   * `CompoundFilter`.\n   */\n  filters: Array<ComparisonFilter | unknown>;\n\n  /**\n   * Type of operation: `and` or `or`.\n   */\n  type: 'and' | 'or';\n}\n\n/**\n * The input format for the custom tool. Default is unconstrained text.\n */\nexport type CustomToolInputFormat = CustomToolInputFormat.Text | CustomToolInputFormat.Grammar;\n\nexport namespace CustomToolInputFormat {\n  /**\n   * Unconstrained free-form text.\n   */\n  export interface Text {\n    /**\n     * Unconstrained text format. Always `text`.\n     */\n    type: 'text';\n  }\n\n  /**\n   * A grammar defined by the user.\n   */\n  export interface Grammar {\n    /**\n     * The grammar definition.\n     */\n    definition: string;\n\n    /**\n     * The syntax of the grammar definition. One of `lark` or `regex`.\n     */\n    syntax: 'lark' | 'regex';\n\n    /**\n     * Grammar format. Always `grammar`.\n     */\n    type: 'grammar';\n  }\n}\n\nexport interface ErrorObject {\n  code: string | null;\n\n  message: string;\n\n  param: string | null;\n\n  type: string;\n}\n\nexport interface FunctionDefinition {\n  /**\n   * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain\n   * underscores and dashes, with a maximum length of 64.\n   */\n  name: string;\n\n  /**\n   * A description of what the function does, used by the model to choose when and\n   * how to call the function.\n   */\n  description?: string;\n\n  /**\n   * The parameters the functions accepts, described as a JSON Schema object. See the\n   * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,\n   * and the\n   * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for\n   * documentation about the format.\n   *\n   * Omitting `parameters` defines a function with an empty parameter list.\n   */\n  parameters?: FunctionParameters;\n\n  /**\n   * Whether to enable strict schema adherence when generating the function call. If\n   * set to true, the model will follow the exact schema defined in the `parameters`\n   * field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn\n   * more about Structured Outputs in the\n   * [function calling guide](https://platform.openai.com/docs/guides/function-calling).\n   */\n  strict?: boolean | null;\n}\n\n/**\n * The parameters the functions accepts, described as a JSON Schema object. See the\n * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,\n * and the\n * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for\n * documentation about the format.\n *\n * Omitting `parameters` defines a function with an empty parameter list.\n */\nexport type FunctionParameters = { [key: string]: unknown };\n\n/**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\nexport type Metadata = { [key: string]: string };\n\n/**\n * **gpt-5 and o-series models only**\n *\n * Configuration options for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning).\n */\nexport interface Reasoning {\n  /**\n   * Constrains effort on reasoning for\n   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n   * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n   * Reducing reasoning effort can result in faster responses and fewer tokens used\n   * on reasoning in a response.\n   *\n   * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n   *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n   *   calls are supported for all reasoning values in gpt-5.1.\n   * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n   *   support `none`.\n   * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n   * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n   */\n  effort?: ReasoningEffort | null;\n\n  /**\n   * @deprecated **Deprecated:** use `summary` instead.\n   *\n   * A summary of the reasoning performed by the model. This can be useful for\n   * debugging and understanding the model's reasoning process. One of `auto`,\n   * `concise`, or `detailed`.\n   */\n  generate_summary?: 'auto' | 'concise' | 'detailed' | null;\n\n  /**\n   * A summary of the reasoning performed by the model. This can be useful for\n   * debugging and understanding the model's reasoning process. One of `auto`,\n   * `concise`, or `detailed`.\n   *\n   * `concise` is supported for `computer-use-preview` models and all reasoning\n   * models after `gpt-5`.\n   */\n  summary?: 'auto' | 'concise' | 'detailed' | null;\n}\n\n/**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n *   reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n *   calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n *   support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\nexport type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | null;\n\n/**\n * JSON object response format. An older method of generating JSON responses. Using\n * `json_schema` is recommended for models that support it. Note that the model\n * will not generate JSON without a system or user message instructing it to do so.\n */\nexport interface ResponseFormatJSONObject {\n  /**\n   * The type of response format being defined. Always `json_object`.\n   */\n  type: 'json_object';\n}\n\n/**\n * JSON Schema response format. Used to generate structured JSON responses. Learn\n * more about\n * [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).\n */\nexport interface ResponseFormatJSONSchema {\n  /**\n   * Structured Outputs configuration options, including a JSON Schema.\n   */\n  json_schema: ResponseFormatJSONSchema.JSONSchema;\n\n  /**\n   * The type of response format being defined. Always `json_schema`.\n   */\n  type: 'json_schema';\n}\n\nexport namespace ResponseFormatJSONSchema {\n  /**\n   * Structured Outputs configuration options, including a JSON Schema.\n   */\n  export interface JSONSchema {\n    /**\n     * The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores\n     * and dashes, with a maximum length of 64.\n     */\n    name: string;\n\n    /**\n     * A description of what the response format is for, used by the model to determine\n     * how to respond in the format.\n     */\n    description?: string;\n\n    /**\n     * The schema for the response format, described as a JSON Schema object. Learn how\n     * to build JSON schemas [here](https://json-schema.org/).\n     */\n    schema?: { [key: string]: unknown };\n\n    /**\n     * Whether to enable strict schema adherence when generating the output. If set to\n     * true, the model will always follow the exact schema defined in the `schema`\n     * field. Only a subset of JSON Schema is supported when `strict` is `true`. To\n     * learn more, read the\n     * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n     */\n    strict?: boolean | null;\n  }\n}\n\n/**\n * Default response format. Used to generate text responses.\n */\nexport interface ResponseFormatText {\n  /**\n   * The type of response format being defined. Always `text`.\n   */\n  type: 'text';\n}\n\n/**\n * A custom grammar for the model to follow when generating text. Learn more in the\n * [custom grammars guide](https://platform.openai.com/docs/guides/custom-grammars).\n */\nexport interface ResponseFormatTextGrammar {\n  /**\n   * The custom grammar for the model to follow.\n   */\n  grammar: string;\n\n  /**\n   * The type of response format being defined. Always `grammar`.\n   */\n  type: 'grammar';\n}\n\n/**\n * Configure the model to generate valid Python code. See the\n * [custom grammars guide](https://platform.openai.com/docs/guides/custom-grammars)\n * for more details.\n */\nexport interface ResponseFormatTextPython {\n  /**\n   * The type of response format being defined. Always `python`.\n   */\n  type: 'python';\n}\n\nexport type ResponsesModel =\n  | (string & {})\n  | ChatModel\n  | 'o1-pro'\n  | 'o1-pro-2025-03-19'\n  | 'o3-pro'\n  | 'o3-pro-2025-06-10'\n  | 'o3-deep-research'\n  | 'o3-deep-research-2025-06-26'\n  | 'o4-mini-deep-research'\n  | 'o4-mini-deep-research-2025-06-26'\n  | 'computer-use-preview'\n  | 'computer-use-preview-2025-03-11'\n  | 'gpt-5-codex'\n  | 'gpt-5-pro'\n  | 'gpt-5-pro-2025-10-06'\n  | 'gpt-5.1-codex-max';\n"
  },
  {
    "path": "src/resources/skills/content.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport { APIPromise } from '../../core/api-promise';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport class Content extends APIResource {\n  /**\n   * Download a skill zip bundle by its ID.\n   */\n  retrieve(skillID: string, options?: RequestOptions): APIPromise<Response> {\n    return this._client.get(path`/skills/${skillID}/content`, {\n      ...options,\n      headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),\n      __binaryResponse: true,\n    });\n  }\n}\n"
  },
  {
    "path": "src/resources/skills/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Content } from './content';\nexport {\n  Skills,\n  type DeletedSkill,\n  type Skill,\n  type SkillList,\n  type SkillCreateParams,\n  type SkillUpdateParams,\n  type SkillListParams,\n  type SkillsPage,\n} from './skills';\nexport {\n  Versions,\n  type DeletedSkillVersion,\n  type SkillVersion,\n  type SkillVersionList,\n  type VersionCreateParams,\n  type VersionRetrieveParams,\n  type VersionListParams,\n  type VersionDeleteParams,\n  type SkillVersionsPage,\n} from './versions/index';\n"
  },
  {
    "path": "src/resources/skills/skills.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as ContentAPI from './content';\nimport { Content } from './content';\nimport * as VersionsAPI from './versions/versions';\nimport {\n  DeletedSkillVersion,\n  SkillVersion,\n  SkillVersionList,\n  SkillVersionsPage,\n  VersionCreateParams,\n  VersionDeleteParams,\n  VersionListParams,\n  VersionRetrieveParams,\n  Versions,\n} from './versions/versions';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { type Uploadable } from '../../core/uploads';\nimport { RequestOptions } from '../../internal/request-options';\nimport { maybeMultipartFormRequestOptions } from '../../internal/uploads';\nimport { path } from '../../internal/utils/path';\n\nexport class Skills extends APIResource {\n  content: ContentAPI.Content = new ContentAPI.Content(this._client);\n  versions: VersionsAPI.Versions = new VersionsAPI.Versions(this._client);\n\n  /**\n   * Create a new skill.\n   */\n  create(body: SkillCreateParams | null | undefined = {}, options?: RequestOptions): APIPromise<Skill> {\n    return this._client.post('/skills', maybeMultipartFormRequestOptions({ body, ...options }, this._client));\n  }\n\n  /**\n   * Get a skill by its ID.\n   */\n  retrieve(skillID: string, options?: RequestOptions): APIPromise<Skill> {\n    return this._client.get(path`/skills/${skillID}`, options);\n  }\n\n  /**\n   * Update the default version pointer for a skill.\n   */\n  update(skillID: string, body: SkillUpdateParams, options?: RequestOptions): APIPromise<Skill> {\n    return this._client.post(path`/skills/${skillID}`, { body, ...options });\n  }\n\n  /**\n   * List all skills for the current project.\n   */\n  list(\n    query: SkillListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<SkillsPage, Skill> {\n    return this._client.getAPIList('/skills', CursorPage<Skill>, { query, ...options });\n  }\n\n  /**\n   * Delete a skill by its ID.\n   */\n  delete(skillID: string, options?: RequestOptions): APIPromise<DeletedSkill> {\n    return this._client.delete(path`/skills/${skillID}`, options);\n  }\n}\n\nexport type SkillsPage = CursorPage<Skill>;\n\nexport interface DeletedSkill {\n  id: string;\n\n  deleted: boolean;\n\n  object: 'skill.deleted';\n}\n\nexport interface Skill {\n  /**\n   * Unique identifier for the skill.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (seconds) for when the skill was created.\n   */\n  created_at: number;\n\n  /**\n   * Default version for the skill.\n   */\n  default_version: string;\n\n  /**\n   * Description of the skill.\n   */\n  description: string;\n\n  /**\n   * Latest version for the skill.\n   */\n  latest_version: string;\n\n  /**\n   * Name of the skill.\n   */\n  name: string;\n\n  /**\n   * The object type, which is `skill`.\n   */\n  object: 'skill';\n}\n\nexport interface SkillList {\n  /**\n   * A list of items\n   */\n  data: Array<Skill>;\n\n  /**\n   * The ID of the first item in the list.\n   */\n  first_id: string | null;\n\n  /**\n   * Whether there are more items available.\n   */\n  has_more: boolean;\n\n  /**\n   * The ID of the last item in the list.\n   */\n  last_id: string | null;\n\n  /**\n   * The type of object returned, must be `list`.\n   */\n  object: 'list';\n}\n\nexport interface SkillCreateParams {\n  /**\n   * Skill files to upload (directory upload) or a single zip file.\n   */\n  files?: Array<Uploadable> | Uploadable;\n}\n\nexport interface SkillUpdateParams {\n  /**\n   * The skill version number to set as default.\n   */\n  default_version: string;\n}\n\nexport interface SkillListParams extends CursorPageParams {\n  /**\n   * Sort order of results by timestamp. Use `asc` for ascending order or `desc` for\n   * descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nSkills.Content = Content;\nSkills.Versions = Versions;\n\nexport declare namespace Skills {\n  export {\n    type DeletedSkill as DeletedSkill,\n    type Skill as Skill,\n    type SkillList as SkillList,\n    type SkillsPage as SkillsPage,\n    type SkillCreateParams as SkillCreateParams,\n    type SkillUpdateParams as SkillUpdateParams,\n    type SkillListParams as SkillListParams,\n  };\n\n  export { Content as Content };\n\n  export {\n    Versions as Versions,\n    type DeletedSkillVersion as DeletedSkillVersion,\n    type SkillVersion as SkillVersion,\n    type SkillVersionList as SkillVersionList,\n    type SkillVersionsPage as SkillVersionsPage,\n    type VersionCreateParams as VersionCreateParams,\n    type VersionRetrieveParams as VersionRetrieveParams,\n    type VersionListParams as VersionListParams,\n    type VersionDeleteParams as VersionDeleteParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/skills/versions/content.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { APIPromise } from '../../../core/api-promise';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\nexport class Content extends APIResource {\n  /**\n   * Download a skill version zip bundle.\n   */\n  retrieve(version: string, params: ContentRetrieveParams, options?: RequestOptions): APIPromise<Response> {\n    const { skill_id } = params;\n    return this._client.get(path`/skills/${skill_id}/versions/${version}/content`, {\n      ...options,\n      headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),\n      __binaryResponse: true,\n    });\n  }\n}\n\nexport interface ContentRetrieveParams {\n  /**\n   * The identifier of the skill.\n   */\n  skill_id: string;\n}\n\nexport declare namespace Content {\n  export { type ContentRetrieveParams as ContentRetrieveParams };\n}\n"
  },
  {
    "path": "src/resources/skills/versions/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Content, type ContentRetrieveParams } from './content';\nexport {\n  Versions,\n  type DeletedSkillVersion,\n  type SkillVersion,\n  type SkillVersionList,\n  type VersionCreateParams,\n  type VersionRetrieveParams,\n  type VersionListParams,\n  type VersionDeleteParams,\n  type SkillVersionsPage,\n} from './versions';\n"
  },
  {
    "path": "src/resources/skills/versions/versions.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ContentAPI from './content';\nimport { Content, ContentRetrieveParams } from './content';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { type Uploadable } from '../../../core/uploads';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { maybeMultipartFormRequestOptions } from '../../../internal/uploads';\nimport { path } from '../../../internal/utils/path';\n\nexport class Versions extends APIResource {\n  content: ContentAPI.Content = new ContentAPI.Content(this._client);\n\n  /**\n   * Create a new immutable skill version.\n   */\n  create(\n    skillID: string,\n    body: VersionCreateParams | null | undefined = {},\n    options?: RequestOptions,\n  ): APIPromise<SkillVersion> {\n    return this._client.post(\n      path`/skills/${skillID}/versions`,\n      maybeMultipartFormRequestOptions({ body, ...options }, this._client),\n    );\n  }\n\n  /**\n   * Get a specific skill version.\n   */\n  retrieve(\n    version: string,\n    params: VersionRetrieveParams,\n    options?: RequestOptions,\n  ): APIPromise<SkillVersion> {\n    const { skill_id } = params;\n    return this._client.get(path`/skills/${skill_id}/versions/${version}`, options);\n  }\n\n  /**\n   * List skill versions for a skill.\n   */\n  list(\n    skillID: string,\n    query: VersionListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<SkillVersionsPage, SkillVersion> {\n    return this._client.getAPIList(path`/skills/${skillID}/versions`, CursorPage<SkillVersion>, {\n      query,\n      ...options,\n    });\n  }\n\n  /**\n   * Delete a skill version.\n   */\n  delete(\n    version: string,\n    params: VersionDeleteParams,\n    options?: RequestOptions,\n  ): APIPromise<DeletedSkillVersion> {\n    const { skill_id } = params;\n    return this._client.delete(path`/skills/${skill_id}/versions/${version}`, options);\n  }\n}\n\nexport type SkillVersionsPage = CursorPage<SkillVersion>;\n\nexport interface DeletedSkillVersion {\n  id: string;\n\n  deleted: boolean;\n\n  object: 'skill.version.deleted';\n\n  /**\n   * The deleted skill version.\n   */\n  version: string;\n}\n\nexport interface SkillVersion {\n  /**\n   * Unique identifier for the skill version.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (seconds) for when the version was created.\n   */\n  created_at: number;\n\n  /**\n   * Description of the skill version.\n   */\n  description: string;\n\n  /**\n   * Name of the skill version.\n   */\n  name: string;\n\n  /**\n   * The object type, which is `skill.version`.\n   */\n  object: 'skill.version';\n\n  /**\n   * Identifier of the skill for this version.\n   */\n  skill_id: string;\n\n  /**\n   * Version number for this skill.\n   */\n  version: string;\n}\n\nexport interface SkillVersionList {\n  /**\n   * A list of items\n   */\n  data: Array<SkillVersion>;\n\n  /**\n   * The ID of the first item in the list.\n   */\n  first_id: string | null;\n\n  /**\n   * Whether there are more items available.\n   */\n  has_more: boolean;\n\n  /**\n   * The ID of the last item in the list.\n   */\n  last_id: string | null;\n\n  /**\n   * The type of object returned, must be `list`.\n   */\n  object: 'list';\n}\n\nexport interface VersionCreateParams {\n  /**\n   * Whether to set this version as the default.\n   */\n  default?: boolean;\n\n  /**\n   * Skill files to upload (directory upload) or a single zip file.\n   */\n  files?: Array<Uploadable> | Uploadable;\n}\n\nexport interface VersionRetrieveParams {\n  /**\n   * The identifier of the skill.\n   */\n  skill_id: string;\n}\n\nexport interface VersionListParams extends CursorPageParams {\n  /**\n   * Sort order of results by version number.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport interface VersionDeleteParams {\n  /**\n   * The identifier of the skill.\n   */\n  skill_id: string;\n}\n\nVersions.Content = Content;\n\nexport declare namespace Versions {\n  export {\n    type DeletedSkillVersion as DeletedSkillVersion,\n    type SkillVersion as SkillVersion,\n    type SkillVersionList as SkillVersionList,\n    type SkillVersionsPage as SkillVersionsPage,\n    type VersionCreateParams as VersionCreateParams,\n    type VersionRetrieveParams as VersionRetrieveParams,\n    type VersionListParams as VersionListParams,\n    type VersionDeleteParams as VersionDeleteParams,\n  };\n\n  export { Content as Content, type ContentRetrieveParams as ContentRetrieveParams };\n}\n"
  },
  {
    "path": "src/resources/skills/versions.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './versions/index';\n"
  },
  {
    "path": "src/resources/skills.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './skills/index';\n"
  },
  {
    "path": "src/resources/uploads/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport { Parts, type UploadPart, type PartCreateParams } from './parts';\nexport { Uploads, type Upload, type UploadCreateParams, type UploadCompleteParams } from './uploads';\n"
  },
  {
    "path": "src/resources/uploads/parts.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport { APIPromise } from '../../core/api-promise';\nimport { type Uploadable } from '../../core/uploads';\nimport { RequestOptions } from '../../internal/request-options';\nimport { multipartFormRequestOptions } from '../../internal/uploads';\nimport { path } from '../../internal/utils/path';\n\n/**\n * Use Uploads to upload large files in multiple parts.\n */\nexport class Parts extends APIResource {\n  /**\n   * Adds a\n   * [Part](https://platform.openai.com/docs/api-reference/uploads/part-object) to an\n   * [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object.\n   * A Part represents a chunk of bytes from the file you are trying to upload.\n   *\n   * Each Part can be at most 64 MB, and you can add Parts until you hit the Upload\n   * maximum of 8 GB.\n   *\n   * It is possible to add multiple Parts in parallel. You can decide the intended\n   * order of the Parts when you\n   * [complete the Upload](https://platform.openai.com/docs/api-reference/uploads/complete).\n   */\n  create(uploadID: string, body: PartCreateParams, options?: RequestOptions): APIPromise<UploadPart> {\n    return this._client.post(\n      path`/uploads/${uploadID}/parts`,\n      multipartFormRequestOptions({ body, ...options }, this._client),\n    );\n  }\n}\n\n/**\n * The upload Part represents a chunk of bytes we can add to an Upload object.\n */\nexport interface UploadPart {\n  /**\n   * The upload Part unique identifier, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the Part was created.\n   */\n  created_at: number;\n\n  /**\n   * The object type, which is always `upload.part`.\n   */\n  object: 'upload.part';\n\n  /**\n   * The ID of the Upload object that this Part was added to.\n   */\n  upload_id: string;\n}\n\nexport interface PartCreateParams {\n  /**\n   * The chunk of bytes for this Part.\n   */\n  data: Uploadable;\n}\n\nexport declare namespace Parts {\n  export { type UploadPart as UploadPart, type PartCreateParams as PartCreateParams };\n}\n"
  },
  {
    "path": "src/resources/uploads/uploads.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as FilesAPI from '../files';\nimport * as PartsAPI from './parts';\nimport { PartCreateParams, Parts, UploadPart } from './parts';\nimport { APIPromise } from '../../core/api-promise';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\n/**\n * Use Uploads to upload large files in multiple parts.\n */\nexport class Uploads extends APIResource {\n  parts: PartsAPI.Parts = new PartsAPI.Parts(this._client);\n\n  /**\n   * Creates an intermediate\n   * [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object\n   * that you can add\n   * [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to.\n   * Currently, an Upload can accept at most 8 GB in total and expires after an hour\n   * after you create it.\n   *\n   * Once you complete the Upload, we will create a\n   * [File](https://platform.openai.com/docs/api-reference/files/object) object that\n   * contains all the parts you uploaded. This File is usable in the rest of our\n   * platform as a regular File object.\n   *\n   * For certain `purpose` values, the correct `mime_type` must be specified. Please\n   * refer to documentation for the\n   * [supported MIME types for your use case](https://platform.openai.com/docs/assistants/tools/file-search#supported-files).\n   *\n   * For guidance on the proper filename extensions for each purpose, please follow\n   * the documentation on\n   * [creating a File](https://platform.openai.com/docs/api-reference/files/create).\n   *\n   * Returns the Upload object with status `pending`.\n   */\n  create(body: UploadCreateParams, options?: RequestOptions): APIPromise<Upload> {\n    return this._client.post('/uploads', { body, ...options });\n  }\n\n  /**\n   * Cancels the Upload. No Parts may be added after an Upload is cancelled.\n   *\n   * Returns the Upload object with status `cancelled`.\n   */\n  cancel(uploadID: string, options?: RequestOptions): APIPromise<Upload> {\n    return this._client.post(path`/uploads/${uploadID}/cancel`, options);\n  }\n\n  /**\n   * Completes the\n   * [Upload](https://platform.openai.com/docs/api-reference/uploads/object).\n   *\n   * Within the returned Upload object, there is a nested\n   * [File](https://platform.openai.com/docs/api-reference/files/object) object that\n   * is ready to use in the rest of the platform.\n   *\n   * You can specify the order of the Parts by passing in an ordered list of the Part\n   * IDs.\n   *\n   * The number of bytes uploaded upon completion must match the number of bytes\n   * initially specified when creating the Upload object. No Parts may be added after\n   * an Upload is completed. Returns the Upload object with status `completed`,\n   * including an additional `file` property containing the created usable File\n   * object.\n   */\n  complete(uploadID: string, body: UploadCompleteParams, options?: RequestOptions): APIPromise<Upload> {\n    return this._client.post(path`/uploads/${uploadID}/complete`, { body, ...options });\n  }\n}\n\n/**\n * The Upload object can accept byte chunks in the form of Parts.\n */\nexport interface Upload {\n  /**\n   * The Upload unique identifier, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The intended number of bytes to be uploaded.\n   */\n  bytes: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the Upload was created.\n   */\n  created_at: number;\n\n  /**\n   * The Unix timestamp (in seconds) for when the Upload will expire.\n   */\n  expires_at: number;\n\n  /**\n   * The name of the file to be uploaded.\n   */\n  filename: string;\n\n  /**\n   * The object type, which is always \"upload\".\n   */\n  object: 'upload';\n\n  /**\n   * The intended purpose of the file.\n   * [Please refer here](https://platform.openai.com/docs/api-reference/files/object#files/object-purpose)\n   * for acceptable values.\n   */\n  purpose: string;\n\n  /**\n   * The status of the Upload.\n   */\n  status: 'pending' | 'completed' | 'cancelled' | 'expired';\n\n  /**\n   * The `File` object represents a document that has been uploaded to OpenAI.\n   */\n  file?: FilesAPI.FileObject | null;\n}\n\nexport interface UploadCreateParams {\n  /**\n   * The number of bytes in the file you are uploading.\n   */\n  bytes: number;\n\n  /**\n   * The name of the file to upload.\n   */\n  filename: string;\n\n  /**\n   * The MIME type of the file.\n   *\n   * This must fall within the supported MIME types for your file purpose. See the\n   * supported MIME types for assistants and vision.\n   */\n  mime_type: string;\n\n  /**\n   * The intended purpose of the uploaded file.\n   *\n   * See the\n   * [documentation on File purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).\n   */\n  purpose: FilesAPI.FilePurpose;\n\n  /**\n   * The expiration policy for a file. By default, files with `purpose=batch` expire\n   * after 30 days and all other files are persisted until they are manually deleted.\n   */\n  expires_after?: UploadCreateParams.ExpiresAfter;\n}\n\nexport namespace UploadCreateParams {\n  /**\n   * The expiration policy for a file. By default, files with `purpose=batch` expire\n   * after 30 days and all other files are persisted until they are manually deleted.\n   */\n  export interface ExpiresAfter {\n    /**\n     * Anchor timestamp after which the expiration policy applies. Supported anchors:\n     * `created_at`.\n     */\n    anchor: 'created_at';\n\n    /**\n     * The number of seconds after the anchor time that the file will expire. Must be\n     * between 3600 (1 hour) and 2592000 (30 days).\n     */\n    seconds: number;\n  }\n}\n\nexport interface UploadCompleteParams {\n  /**\n   * The ordered list of Part IDs.\n   */\n  part_ids: Array<string>;\n\n  /**\n   * The optional md5 checksum for the file contents to verify if the bytes uploaded\n   * matches what you expect.\n   */\n  md5?: string;\n}\n\nUploads.Parts = Parts;\n\nexport declare namespace Uploads {\n  export {\n    type Upload as Upload,\n    type UploadCreateParams as UploadCreateParams,\n    type UploadCompleteParams as UploadCompleteParams,\n  };\n\n  export { Parts as Parts, type UploadPart as UploadPart, type PartCreateParams as PartCreateParams };\n}\n"
  },
  {
    "path": "src/resources/uploads.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './uploads/index';\n"
  },
  {
    "path": "src/resources/vector-stores/file-batches.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as FilesAPI from './files';\nimport { VectorStoreFilesPage } from './files';\nimport * as VectorStoresAPI from './vector-stores';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { sleep } from '../../internal/utils/sleep';\nimport { type Uploadable } from '../../uploads';\nimport { allSettledWithThrow } from '../../lib/Util';\nimport { path } from '../../internal/utils/path';\n\nexport class FileBatches extends APIResource {\n  /**\n   * Create a vector store file batch.\n   */\n  create(\n    vectorStoreID: string,\n    body: FileBatchCreateParams,\n    options?: RequestOptions,\n  ): APIPromise<VectorStoreFileBatch> {\n    return this._client.post(path`/vector_stores/${vectorStoreID}/file_batches`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Retrieves a vector store file batch.\n   */\n  retrieve(\n    batchID: string,\n    params: FileBatchRetrieveParams,\n    options?: RequestOptions,\n  ): APIPromise<VectorStoreFileBatch> {\n    const { vector_store_id } = params;\n    return this._client.get(path`/vector_stores/${vector_store_id}/file_batches/${batchID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Cancel a vector store file batch. This attempts to cancel the processing of\n   * files in this batch as soon as possible.\n   */\n  cancel(\n    batchID: string,\n    params: FileBatchCancelParams,\n    options?: RequestOptions,\n  ): APIPromise<VectorStoreFileBatch> {\n    const { vector_store_id } = params;\n    return this._client.post(path`/vector_stores/${vector_store_id}/file_batches/${batchID}/cancel`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Create a vector store batch and poll until all files have been processed.\n   */\n  async createAndPoll(\n    vectorStoreId: string,\n    body: FileBatchCreateParams,\n    options?: RequestOptions & { pollIntervalMs?: number },\n  ): Promise<VectorStoreFileBatch> {\n    const batch = await this.create(vectorStoreId, body);\n    return await this.poll(vectorStoreId, batch.id, options);\n  }\n\n  /**\n   * Returns a list of vector store files in a batch.\n   */\n  listFiles(\n    batchID: string,\n    params: FileBatchListFilesParams,\n    options?: RequestOptions,\n  ): PagePromise<VectorStoreFilesPage, FilesAPI.VectorStoreFile> {\n    const { vector_store_id, ...query } = params;\n    return this._client.getAPIList(\n      path`/vector_stores/${vector_store_id}/file_batches/${batchID}/files`,\n      CursorPage<FilesAPI.VectorStoreFile>,\n      { query, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]) },\n    );\n  }\n\n  /**\n   * Wait for the given file batch to be processed.\n   *\n   * Note: this will return even if one of the files failed to process, you need to\n   * check batch.file_counts.failed_count to handle this case.\n   */\n  async poll(\n    vectorStoreID: string,\n    batchID: string,\n    options?: RequestOptions & { pollIntervalMs?: number },\n  ): Promise<VectorStoreFileBatch> {\n    const headers = buildHeaders([\n      options?.headers,\n      {\n        'X-Stainless-Poll-Helper': 'true',\n        'X-Stainless-Custom-Poll-Interval': options?.pollIntervalMs?.toString() ?? undefined,\n      },\n    ]);\n\n    while (true) {\n      const { data: batch, response } = await this.retrieve(\n        batchID,\n        { vector_store_id: vectorStoreID },\n        {\n          ...options,\n          headers,\n        },\n      ).withResponse();\n\n      switch (batch.status) {\n        case 'in_progress':\n          let sleepInterval = 5000;\n\n          if (options?.pollIntervalMs) {\n            sleepInterval = options.pollIntervalMs;\n          } else {\n            const headerInterval = response.headers.get('openai-poll-after-ms');\n            if (headerInterval) {\n              const headerIntervalMs = parseInt(headerInterval);\n              if (!isNaN(headerIntervalMs)) {\n                sleepInterval = headerIntervalMs;\n              }\n            }\n          }\n          await sleep(sleepInterval);\n          break;\n        case 'failed':\n        case 'cancelled':\n        case 'completed':\n          return batch;\n      }\n    }\n  }\n\n  /**\n   * Uploads the given files concurrently and then creates a vector store file batch.\n   *\n   * The concurrency limit is configurable using the `maxConcurrency` parameter.\n   */\n  async uploadAndPoll(\n    vectorStoreId: string,\n    { files, fileIds = [] }: { files: Uploadable[]; fileIds?: string[] },\n    options?: RequestOptions & { pollIntervalMs?: number; maxConcurrency?: number },\n  ): Promise<VectorStoreFileBatch> {\n    if (files == null || files.length == 0) {\n      throw new Error(\n        `No \\`files\\` provided to process. If you've already uploaded files you should use \\`.createAndPoll()\\` instead`,\n      );\n    }\n\n    const configuredConcurrency = options?.maxConcurrency ?? 5;\n\n    // We cap the number of workers at the number of files (so we don't start any unnecessary workers)\n    const concurrencyLimit = Math.min(configuredConcurrency, files.length);\n\n    const client = this._client;\n    const fileIterator = files.values();\n    const allFileIds: string[] = [...fileIds];\n\n    // This code is based on this design. The libraries don't accommodate our environment limits.\n    // https://stackoverflow.com/questions/40639432/what-is-the-best-way-to-limit-concurrency-when-using-es6s-promise-all\n    async function processFiles(iterator: IterableIterator<Uploadable>) {\n      for (let item of iterator) {\n        const fileObj = await client.files.create({ file: item, purpose: 'assistants' }, options);\n        allFileIds.push(fileObj.id);\n      }\n    }\n\n    // Start workers to process results\n    const workers = Array(concurrencyLimit).fill(fileIterator).map(processFiles);\n\n    // Wait for all processing to complete.\n    await allSettledWithThrow(workers);\n\n    return await this.createAndPoll(vectorStoreId, {\n      file_ids: allFileIds,\n    });\n  }\n}\n\n/**\n * A batch of files attached to a vector store.\n */\nexport interface VectorStoreFileBatch {\n  /**\n   * The identifier, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the vector store files batch was\n   * created.\n   */\n  created_at: number;\n\n  file_counts: VectorStoreFileBatch.FileCounts;\n\n  /**\n   * The object type, which is always `vector_store.file_batch`.\n   */\n  object: 'vector_store.files_batch';\n\n  /**\n   * The status of the vector store files batch, which can be either `in_progress`,\n   * `completed`, `cancelled` or `failed`.\n   */\n  status: 'in_progress' | 'completed' | 'cancelled' | 'failed';\n\n  /**\n   * The ID of the\n   * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n   * that the [File](https://platform.openai.com/docs/api-reference/files) is\n   * attached to.\n   */\n  vector_store_id: string;\n}\n\nexport namespace VectorStoreFileBatch {\n  export interface FileCounts {\n    /**\n     * The number of files that where cancelled.\n     */\n    cancelled: number;\n\n    /**\n     * The number of files that have been processed.\n     */\n    completed: number;\n\n    /**\n     * The number of files that have failed to process.\n     */\n    failed: number;\n\n    /**\n     * The number of files that are currently being processed.\n     */\n    in_progress: number;\n\n    /**\n     * The total number of files.\n     */\n    total: number;\n  }\n}\n\nexport interface FileBatchCreateParams {\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard. Keys are strings with a maximum\n   * length of 64 characters. Values are strings with a maximum length of 512\n   * characters, booleans, or numbers.\n   */\n  attributes?: { [key: string]: string | number | boolean } | null;\n\n  /**\n   * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n   * strategy. Only applicable if `file_ids` is non-empty.\n   */\n  chunking_strategy?: VectorStoresAPI.FileChunkingStrategyParam;\n\n  /**\n   * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that\n   * the vector store should use. Useful for tools like `file_search` that can access\n   * files. If `attributes` or `chunking_strategy` are provided, they will be applied\n   * to all files in the batch. The maximum batch size is 2000 files. Mutually\n   * exclusive with `files`.\n   */\n  file_ids?: Array<string>;\n\n  /**\n   * A list of objects that each include a `file_id` plus optional `attributes` or\n   * `chunking_strategy`. Use this when you need to override metadata for specific\n   * files. The global `attributes` or `chunking_strategy` will be ignored and must\n   * be specified for each file. The maximum batch size is 2000 files. Mutually\n   * exclusive with `file_ids`.\n   */\n  files?: Array<FileBatchCreateParams.File>;\n}\n\nexport namespace FileBatchCreateParams {\n  export interface File {\n    /**\n     * A [File](https://platform.openai.com/docs/api-reference/files) ID that the\n     * vector store should use. Useful for tools like `file_search` that can access\n     * files.\n     */\n    file_id: string;\n\n    /**\n     * Set of 16 key-value pairs that can be attached to an object. This can be useful\n     * for storing additional information about the object in a structured format, and\n     * querying for objects via API or the dashboard. Keys are strings with a maximum\n     * length of 64 characters. Values are strings with a maximum length of 512\n     * characters, booleans, or numbers.\n     */\n    attributes?: { [key: string]: string | number | boolean } | null;\n\n    /**\n     * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n     * strategy. Only applicable if `file_ids` is non-empty.\n     */\n    chunking_strategy?: VectorStoresAPI.FileChunkingStrategyParam;\n  }\n}\n\nexport interface FileBatchRetrieveParams {\n  /**\n   * The ID of the vector store that the file batch belongs to.\n   */\n  vector_store_id: string;\n}\n\nexport interface FileBatchCancelParams {\n  /**\n   * The ID of the vector store that the file batch belongs to.\n   */\n  vector_store_id: string;\n}\n\nexport interface FileBatchListFilesParams extends CursorPageParams {\n  /**\n   * Path param: The ID of the vector store that the files belong to.\n   */\n  vector_store_id: string;\n\n  /**\n   * Query param: A cursor for use in pagination. `before` is an object ID that\n   * defines your place in the list. For instance, if you make a list request and\n   * receive 100 objects, starting with obj_foo, your subsequent call can include\n   * before=obj_foo in order to fetch the previous page of the list.\n   */\n  before?: string;\n\n  /**\n   * Query param: Filter by file status. One of `in_progress`, `completed`, `failed`,\n   * `cancelled`.\n   */\n  filter?: 'in_progress' | 'completed' | 'failed' | 'cancelled';\n\n  /**\n   * Query param: Sort order by the `created_at` timestamp of the objects. `asc` for\n   * ascending order and `desc` for descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport declare namespace FileBatches {\n  export {\n    type VectorStoreFileBatch as VectorStoreFileBatch,\n    type FileBatchCreateParams as FileBatchCreateParams,\n    type FileBatchRetrieveParams as FileBatchRetrieveParams,\n    type FileBatchCancelParams as FileBatchCancelParams,\n    type FileBatchListFilesParams as FileBatchListFilesParams,\n  };\n}\n\nexport { type VectorStoreFilesPage };\n"
  },
  {
    "path": "src/resources/vector-stores/files.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as VectorStoresAPI from './vector-stores';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise, Page } from '../../core/pagination';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { sleep } from '../../internal/utils';\nimport { Uploadable } from '../../uploads';\nimport { path } from '../../internal/utils/path';\n\nexport class Files extends APIResource {\n  /**\n   * Create a vector store file by attaching a\n   * [File](https://platform.openai.com/docs/api-reference/files) to a\n   * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object).\n   */\n  create(\n    vectorStoreID: string,\n    body: FileCreateParams,\n    options?: RequestOptions,\n  ): APIPromise<VectorStoreFile> {\n    return this._client.post(path`/vector_stores/${vectorStoreID}/files`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Retrieves a vector store file.\n   */\n  retrieve(\n    fileID: string,\n    params: FileRetrieveParams,\n    options?: RequestOptions,\n  ): APIPromise<VectorStoreFile> {\n    const { vector_store_id } = params;\n    return this._client.get(path`/vector_stores/${vector_store_id}/files/${fileID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Update attributes on a vector store file.\n   */\n  update(fileID: string, params: FileUpdateParams, options?: RequestOptions): APIPromise<VectorStoreFile> {\n    const { vector_store_id, ...body } = params;\n    return this._client.post(path`/vector_stores/${vector_store_id}/files/${fileID}`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Returns a list of vector store files.\n   */\n  list(\n    vectorStoreID: string,\n    query: FileListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<VectorStoreFilesPage, VectorStoreFile> {\n    return this._client.getAPIList(path`/vector_stores/${vectorStoreID}/files`, CursorPage<VectorStoreFile>, {\n      query,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Delete a vector store file. This will remove the file from the vector store but\n   * the file itself will not be deleted. To delete the file, use the\n   * [delete file](https://platform.openai.com/docs/api-reference/files/delete)\n   * endpoint.\n   */\n  delete(\n    fileID: string,\n    params: FileDeleteParams,\n    options?: RequestOptions,\n  ): APIPromise<VectorStoreFileDeleted> {\n    const { vector_store_id } = params;\n    return this._client.delete(path`/vector_stores/${vector_store_id}/files/${fileID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Attach a file to the given vector store and wait for it to be processed.\n   */\n  async createAndPoll(\n    vectorStoreId: string,\n    body: FileCreateParams,\n    options?: RequestOptions & { pollIntervalMs?: number },\n  ): Promise<VectorStoreFile> {\n    const file = await this.create(vectorStoreId, body, options);\n    return await this.poll(vectorStoreId, file.id, options);\n  }\n  /**\n   * Wait for the vector store file to finish processing.\n   *\n   * Note: this will return even if the file failed to process, you need to check\n   * file.last_error and file.status to handle these cases\n   */\n  async poll(\n    vectorStoreID: string,\n    fileID: string,\n    options?: RequestOptions & { pollIntervalMs?: number },\n  ): Promise<VectorStoreFile> {\n    const headers = buildHeaders([\n      options?.headers,\n      {\n        'X-Stainless-Poll-Helper': 'true',\n        'X-Stainless-Custom-Poll-Interval': options?.pollIntervalMs?.toString() ?? undefined,\n      },\n    ]);\n\n    while (true) {\n      const fileResponse = await this.retrieve(\n        fileID,\n        {\n          vector_store_id: vectorStoreID,\n        },\n        { ...options, headers },\n      ).withResponse();\n\n      const file = fileResponse.data;\n\n      switch (file.status) {\n        case 'in_progress':\n          let sleepInterval = 5000;\n\n          if (options?.pollIntervalMs) {\n            sleepInterval = options.pollIntervalMs;\n          } else {\n            const headerInterval = fileResponse.response.headers.get('openai-poll-after-ms');\n            if (headerInterval) {\n              const headerIntervalMs = parseInt(headerInterval);\n              if (!isNaN(headerIntervalMs)) {\n                sleepInterval = headerIntervalMs;\n              }\n            }\n          }\n          await sleep(sleepInterval);\n          break;\n        case 'failed':\n        case 'completed':\n          return file;\n      }\n    }\n  }\n  /**\n   * Upload a file to the `files` API and then attach it to the given vector store.\n   *\n   * Note the file will be asynchronously processed (you can use the alternative\n   * polling helper method to wait for processing to complete).\n   */\n  async upload(vectorStoreId: string, file: Uploadable, options?: RequestOptions): Promise<VectorStoreFile> {\n    const fileInfo = await this._client.files.create({ file: file, purpose: 'assistants' }, options);\n    return this.create(vectorStoreId, { file_id: fileInfo.id }, options);\n  }\n  /**\n   * Add a file to a vector store and poll until processing is complete.\n   */\n  async uploadAndPoll(\n    vectorStoreId: string,\n    file: Uploadable,\n    options?: RequestOptions & { pollIntervalMs?: number },\n  ): Promise<VectorStoreFile> {\n    const fileInfo = await this.upload(vectorStoreId, file, options);\n    return await this.poll(vectorStoreId, fileInfo.id, options);\n  }\n\n  /**\n   * Retrieve the parsed contents of a vector store file.\n   */\n  content(\n    fileID: string,\n    params: FileContentParams,\n    options?: RequestOptions,\n  ): PagePromise<FileContentResponsesPage, FileContentResponse> {\n    const { vector_store_id } = params;\n    return this._client.getAPIList(\n      path`/vector_stores/${vector_store_id}/files/${fileID}/content`,\n      Page<FileContentResponse>,\n      { ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]) },\n    );\n  }\n}\n\nexport type VectorStoreFilesPage = CursorPage<VectorStoreFile>;\n\n// Note: no pagination actually occurs yet, this is for forwards-compatibility.\nexport type FileContentResponsesPage = Page<FileContentResponse>;\n\n/**\n * A list of files attached to a vector store.\n */\nexport interface VectorStoreFile {\n  /**\n   * The identifier, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the vector store file was created.\n   */\n  created_at: number;\n\n  /**\n   * The last error associated with this vector store file. Will be `null` if there\n   * are no errors.\n   */\n  last_error: VectorStoreFile.LastError | null;\n\n  /**\n   * The object type, which is always `vector_store.file`.\n   */\n  object: 'vector_store.file';\n\n  /**\n   * The status of the vector store file, which can be either `in_progress`,\n   * `completed`, `cancelled`, or `failed`. The status `completed` indicates that the\n   * vector store file is ready for use.\n   */\n  status: 'in_progress' | 'completed' | 'cancelled' | 'failed';\n\n  /**\n   * The total vector store usage in bytes. Note that this may be different from the\n   * original file size.\n   */\n  usage_bytes: number;\n\n  /**\n   * The ID of the\n   * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n   * that the [File](https://platform.openai.com/docs/api-reference/files) is\n   * attached to.\n   */\n  vector_store_id: string;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard. Keys are strings with a maximum\n   * length of 64 characters. Values are strings with a maximum length of 512\n   * characters, booleans, or numbers.\n   */\n  attributes?: { [key: string]: string | number | boolean } | null;\n\n  /**\n   * The strategy used to chunk the file.\n   */\n  chunking_strategy?: VectorStoresAPI.FileChunkingStrategy;\n}\n\nexport namespace VectorStoreFile {\n  /**\n   * The last error associated with this vector store file. Will be `null` if there\n   * are no errors.\n   */\n  export interface LastError {\n    /**\n     * One of `server_error`, `unsupported_file`, or `invalid_file`.\n     */\n    code: 'server_error' | 'unsupported_file' | 'invalid_file';\n\n    /**\n     * A human-readable description of the error.\n     */\n    message: string;\n  }\n}\n\nexport interface VectorStoreFileDeleted {\n  id: string;\n\n  deleted: boolean;\n\n  object: 'vector_store.file.deleted';\n}\n\nexport interface FileContentResponse {\n  /**\n   * The text content\n   */\n  text?: string;\n\n  /**\n   * The content type (currently only `\"text\"`)\n   */\n  type?: string;\n}\n\nexport interface FileCreateParams {\n  /**\n   * A [File](https://platform.openai.com/docs/api-reference/files) ID that the\n   * vector store should use. Useful for tools like `file_search` that can access\n   * files.\n   */\n  file_id: string;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard. Keys are strings with a maximum\n   * length of 64 characters. Values are strings with a maximum length of 512\n   * characters, booleans, or numbers.\n   */\n  attributes?: { [key: string]: string | number | boolean } | null;\n\n  /**\n   * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n   * strategy. Only applicable if `file_ids` is non-empty.\n   */\n  chunking_strategy?: VectorStoresAPI.FileChunkingStrategyParam;\n}\n\nexport interface FileRetrieveParams {\n  /**\n   * The ID of the vector store that the file belongs to.\n   */\n  vector_store_id: string;\n}\n\nexport interface FileUpdateParams {\n  /**\n   * Path param: The ID of the vector store the file belongs to.\n   */\n  vector_store_id: string;\n\n  /**\n   * Body param: Set of 16 key-value pairs that can be attached to an object. This\n   * can be useful for storing additional information about the object in a\n   * structured format, and querying for objects via API or the dashboard. Keys are\n   * strings with a maximum length of 64 characters. Values are strings with a\n   * maximum length of 512 characters, booleans, or numbers.\n   */\n  attributes: { [key: string]: string | number | boolean } | null;\n}\n\nexport interface FileListParams extends CursorPageParams {\n  /**\n   * A cursor for use in pagination. `before` is an object ID that defines your place\n   * in the list. For instance, if you make a list request and receive 100 objects,\n   * starting with obj_foo, your subsequent call can include before=obj_foo in order\n   * to fetch the previous page of the list.\n   */\n  before?: string;\n\n  /**\n   * Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`.\n   */\n  filter?: 'in_progress' | 'completed' | 'failed' | 'cancelled';\n\n  /**\n   * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n   * order and `desc` for descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport interface FileDeleteParams {\n  /**\n   * The ID of the vector store that the file belongs to.\n   */\n  vector_store_id: string;\n}\n\nexport interface FileContentParams {\n  /**\n   * The ID of the vector store.\n   */\n  vector_store_id: string;\n}\n\nexport declare namespace Files {\n  export {\n    type VectorStoreFile as VectorStoreFile,\n    type VectorStoreFileDeleted as VectorStoreFileDeleted,\n    type FileContentResponse as FileContentResponse,\n    type VectorStoreFilesPage as VectorStoreFilesPage,\n    type FileContentResponsesPage as FileContentResponsesPage,\n    type FileCreateParams as FileCreateParams,\n    type FileRetrieveParams as FileRetrieveParams,\n    type FileUpdateParams as FileUpdateParams,\n    type FileListParams as FileListParams,\n    type FileDeleteParams as FileDeleteParams,\n    type FileContentParams as FileContentParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/vector-stores/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport {\n  FileBatches,\n  type VectorStoreFileBatch,\n  type FileBatchCreateParams,\n  type FileBatchRetrieveParams,\n  type FileBatchCancelParams,\n  type FileBatchListFilesParams,\n} from './file-batches';\nexport {\n  Files,\n  type VectorStoreFile,\n  type VectorStoreFileDeleted,\n  type FileContentResponse,\n  type FileCreateParams,\n  type FileRetrieveParams,\n  type FileUpdateParams,\n  type FileListParams,\n  type FileDeleteParams,\n  type FileContentParams,\n  type VectorStoreFilesPage,\n  type FileContentResponsesPage,\n} from './files';\nexport {\n  VectorStores,\n  type AutoFileChunkingStrategyParam,\n  type FileChunkingStrategy,\n  type FileChunkingStrategyParam,\n  type OtherFileChunkingStrategyObject,\n  type StaticFileChunkingStrategy,\n  type StaticFileChunkingStrategyObject,\n  type StaticFileChunkingStrategyObjectParam,\n  type VectorStore,\n  type VectorStoreDeleted,\n  type VectorStoreSearchResponse,\n  type VectorStoreCreateParams,\n  type VectorStoreUpdateParams,\n  type VectorStoreListParams,\n  type VectorStoreSearchParams,\n  type VectorStoresPage,\n  type VectorStoreSearchResponsesPage,\n} from './vector-stores';\n"
  },
  {
    "path": "src/resources/vector-stores/vector-stores.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as FileBatchesAPI from './file-batches';\nimport {\n  FileBatchCancelParams,\n  FileBatchCreateParams,\n  FileBatchListFilesParams,\n  FileBatchRetrieveParams,\n  FileBatches,\n  VectorStoreFileBatch,\n} from './file-batches';\nimport * as FilesAPI from './files';\nimport {\n  FileContentParams,\n  FileContentResponse,\n  FileContentResponsesPage,\n  FileCreateParams,\n  FileDeleteParams,\n  FileListParams,\n  FileRetrieveParams,\n  FileUpdateParams,\n  Files,\n  VectorStoreFile,\n  VectorStoreFileDeleted,\n  VectorStoreFilesPage,\n} from './files';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, Page, PagePromise } from '../../core/pagination';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport class VectorStores extends APIResource {\n  files: FilesAPI.Files = new FilesAPI.Files(this._client);\n  fileBatches: FileBatchesAPI.FileBatches = new FileBatchesAPI.FileBatches(this._client);\n\n  /**\n   * Create a vector store.\n   */\n  create(body: VectorStoreCreateParams, options?: RequestOptions): APIPromise<VectorStore> {\n    return this._client.post('/vector_stores', {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Retrieves a vector store.\n   */\n  retrieve(vectorStoreID: string, options?: RequestOptions): APIPromise<VectorStore> {\n    return this._client.get(path`/vector_stores/${vectorStoreID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Modifies a vector store.\n   */\n  update(\n    vectorStoreID: string,\n    body: VectorStoreUpdateParams,\n    options?: RequestOptions,\n  ): APIPromise<VectorStore> {\n    return this._client.post(path`/vector_stores/${vectorStoreID}`, {\n      body,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Returns a list of vector stores.\n   */\n  list(\n    query: VectorStoreListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<VectorStoresPage, VectorStore> {\n    return this._client.getAPIList('/vector_stores', CursorPage<VectorStore>, {\n      query,\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Delete a vector store.\n   */\n  delete(vectorStoreID: string, options?: RequestOptions): APIPromise<VectorStoreDeleted> {\n    return this._client.delete(path`/vector_stores/${vectorStoreID}`, {\n      ...options,\n      headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n    });\n  }\n\n  /**\n   * Search a vector store for relevant chunks based on a query and file attributes\n   * filter.\n   */\n  search(\n    vectorStoreID: string,\n    body: VectorStoreSearchParams,\n    options?: RequestOptions,\n  ): PagePromise<VectorStoreSearchResponsesPage, VectorStoreSearchResponse> {\n    return this._client.getAPIList(\n      path`/vector_stores/${vectorStoreID}/search`,\n      Page<VectorStoreSearchResponse>,\n      {\n        body,\n        method: 'post',\n        ...options,\n        headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n      },\n    );\n  }\n}\n\nexport type VectorStoresPage = CursorPage<VectorStore>;\n\n// Note: no pagination actually occurs yet, this is for forwards-compatibility.\nexport type VectorStoreSearchResponsesPage = Page<VectorStoreSearchResponse>;\n\n/**\n * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of\n * `800` and `chunk_overlap_tokens` of `400`.\n */\nexport interface AutoFileChunkingStrategyParam {\n  /**\n   * Always `auto`.\n   */\n  type: 'auto';\n}\n\n/**\n * The strategy used to chunk the file.\n */\nexport type FileChunkingStrategy = StaticFileChunkingStrategyObject | OtherFileChunkingStrategyObject;\n\n/**\n * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n * strategy. Only applicable if `file_ids` is non-empty.\n */\nexport type FileChunkingStrategyParam = AutoFileChunkingStrategyParam | StaticFileChunkingStrategyObjectParam;\n\n/**\n * This is returned when the chunking strategy is unknown. Typically, this is\n * because the file was indexed before the `chunking_strategy` concept was\n * introduced in the API.\n */\nexport interface OtherFileChunkingStrategyObject {\n  /**\n   * Always `other`.\n   */\n  type: 'other';\n}\n\nexport interface StaticFileChunkingStrategy {\n  /**\n   * The number of tokens that overlap between chunks. The default value is `400`.\n   *\n   * Note that the overlap must not exceed half of `max_chunk_size_tokens`.\n   */\n  chunk_overlap_tokens: number;\n\n  /**\n   * The maximum number of tokens in each chunk. The default value is `800`. The\n   * minimum value is `100` and the maximum value is `4096`.\n   */\n  max_chunk_size_tokens: number;\n}\n\nexport interface StaticFileChunkingStrategyObject {\n  static: StaticFileChunkingStrategy;\n\n  /**\n   * Always `static`.\n   */\n  type: 'static';\n}\n\n/**\n * Customize your own chunking strategy by setting chunk size and chunk overlap.\n */\nexport interface StaticFileChunkingStrategyObjectParam {\n  static: StaticFileChunkingStrategy;\n\n  /**\n   * Always `static`.\n   */\n  type: 'static';\n}\n\n/**\n * A vector store is a collection of processed files can be used by the\n * `file_search` tool.\n */\nexport interface VectorStore {\n  /**\n   * The identifier, which can be referenced in API endpoints.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) for when the vector store was created.\n   */\n  created_at: number;\n\n  file_counts: VectorStore.FileCounts;\n\n  /**\n   * The Unix timestamp (in seconds) for when the vector store was last active.\n   */\n  last_active_at: number | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata: Shared.Metadata | null;\n\n  /**\n   * The name of the vector store.\n   */\n  name: string;\n\n  /**\n   * The object type, which is always `vector_store`.\n   */\n  object: 'vector_store';\n\n  /**\n   * The status of the vector store, which can be either `expired`, `in_progress`, or\n   * `completed`. A status of `completed` indicates that the vector store is ready\n   * for use.\n   */\n  status: 'expired' | 'in_progress' | 'completed';\n\n  /**\n   * The total number of bytes used by the files in the vector store.\n   */\n  usage_bytes: number;\n\n  /**\n   * The expiration policy for a vector store.\n   */\n  expires_after?: VectorStore.ExpiresAfter;\n\n  /**\n   * The Unix timestamp (in seconds) for when the vector store will expire.\n   */\n  expires_at?: number | null;\n}\n\nexport namespace VectorStore {\n  export interface FileCounts {\n    /**\n     * The number of files that were cancelled.\n     */\n    cancelled: number;\n\n    /**\n     * The number of files that have been successfully processed.\n     */\n    completed: number;\n\n    /**\n     * The number of files that have failed to process.\n     */\n    failed: number;\n\n    /**\n     * The number of files that are currently being processed.\n     */\n    in_progress: number;\n\n    /**\n     * The total number of files.\n     */\n    total: number;\n  }\n\n  /**\n   * The expiration policy for a vector store.\n   */\n  export interface ExpiresAfter {\n    /**\n     * Anchor timestamp after which the expiration policy applies. Supported anchors:\n     * `last_active_at`.\n     */\n    anchor: 'last_active_at';\n\n    /**\n     * The number of days after the anchor time that the vector store will expire.\n     */\n    days: number;\n  }\n}\n\nexport interface VectorStoreDeleted {\n  id: string;\n\n  deleted: boolean;\n\n  object: 'vector_store.deleted';\n}\n\nexport interface VectorStoreSearchResponse {\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard. Keys are strings with a maximum\n   * length of 64 characters. Values are strings with a maximum length of 512\n   * characters, booleans, or numbers.\n   */\n  attributes: { [key: string]: string | number | boolean } | null;\n\n  /**\n   * Content chunks from the file.\n   */\n  content: Array<VectorStoreSearchResponse.Content>;\n\n  /**\n   * The ID of the vector store file.\n   */\n  file_id: string;\n\n  /**\n   * The name of the vector store file.\n   */\n  filename: string;\n\n  /**\n   * The similarity score for the result.\n   */\n  score: number;\n}\n\nexport namespace VectorStoreSearchResponse {\n  export interface Content {\n    /**\n     * The text content returned from search.\n     */\n    text: string;\n\n    /**\n     * The type of content.\n     */\n    type: 'text';\n  }\n}\n\nexport interface VectorStoreCreateParams {\n  /**\n   * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n   * strategy. Only applicable if `file_ids` is non-empty.\n   */\n  chunking_strategy?: FileChunkingStrategyParam;\n\n  /**\n   * A description for the vector store. Can be used to describe the vector store's\n   * purpose.\n   */\n  description?: string;\n\n  /**\n   * The expiration policy for a vector store.\n   */\n  expires_after?: VectorStoreCreateParams.ExpiresAfter;\n\n  /**\n   * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that\n   * the vector store should use. Useful for tools like `file_search` that can access\n   * files.\n   */\n  file_ids?: Array<string>;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The name of the vector store.\n   */\n  name?: string;\n}\n\nexport namespace VectorStoreCreateParams {\n  /**\n   * The expiration policy for a vector store.\n   */\n  export interface ExpiresAfter {\n    /**\n     * Anchor timestamp after which the expiration policy applies. Supported anchors:\n     * `last_active_at`.\n     */\n    anchor: 'last_active_at';\n\n    /**\n     * The number of days after the anchor time that the vector store will expire.\n     */\n    days: number;\n  }\n}\n\nexport interface VectorStoreUpdateParams {\n  /**\n   * The expiration policy for a vector store.\n   */\n  expires_after?: VectorStoreUpdateParams.ExpiresAfter | null;\n\n  /**\n   * Set of 16 key-value pairs that can be attached to an object. This can be useful\n   * for storing additional information about the object in a structured format, and\n   * querying for objects via API or the dashboard.\n   *\n   * Keys are strings with a maximum length of 64 characters. Values are strings with\n   * a maximum length of 512 characters.\n   */\n  metadata?: Shared.Metadata | null;\n\n  /**\n   * The name of the vector store.\n   */\n  name?: string | null;\n}\n\nexport namespace VectorStoreUpdateParams {\n  /**\n   * The expiration policy for a vector store.\n   */\n  export interface ExpiresAfter {\n    /**\n     * Anchor timestamp after which the expiration policy applies. Supported anchors:\n     * `last_active_at`.\n     */\n    anchor: 'last_active_at';\n\n    /**\n     * The number of days after the anchor time that the vector store will expire.\n     */\n    days: number;\n  }\n}\n\nexport interface VectorStoreListParams extends CursorPageParams {\n  /**\n   * A cursor for use in pagination. `before` is an object ID that defines your place\n   * in the list. For instance, if you make a list request and receive 100 objects,\n   * starting with obj_foo, your subsequent call can include before=obj_foo in order\n   * to fetch the previous page of the list.\n   */\n  before?: string;\n\n  /**\n   * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n   * order and `desc` for descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport interface VectorStoreSearchParams {\n  /**\n   * A query string for a search\n   */\n  query: string | Array<string>;\n\n  /**\n   * A filter to apply based on file attributes.\n   */\n  filters?: Shared.ComparisonFilter | Shared.CompoundFilter;\n\n  /**\n   * The maximum number of results to return. This number should be between 1 and 50\n   * inclusive.\n   */\n  max_num_results?: number;\n\n  /**\n   * Ranking options for search.\n   */\n  ranking_options?: VectorStoreSearchParams.RankingOptions;\n\n  /**\n   * Whether to rewrite the natural language query for vector search.\n   */\n  rewrite_query?: boolean;\n}\n\nexport namespace VectorStoreSearchParams {\n  /**\n   * Ranking options for search.\n   */\n  export interface RankingOptions {\n    /**\n     * Enable re-ranking; set to `none` to disable, which can help reduce latency.\n     */\n    ranker?: 'none' | 'auto' | 'default-2024-11-15';\n\n    score_threshold?: number;\n  }\n}\n\nVectorStores.Files = Files;\nVectorStores.FileBatches = FileBatches;\n\nexport declare namespace VectorStores {\n  export {\n    type AutoFileChunkingStrategyParam as AutoFileChunkingStrategyParam,\n    type FileChunkingStrategy as FileChunkingStrategy,\n    type FileChunkingStrategyParam as FileChunkingStrategyParam,\n    type OtherFileChunkingStrategyObject as OtherFileChunkingStrategyObject,\n    type StaticFileChunkingStrategy as StaticFileChunkingStrategy,\n    type StaticFileChunkingStrategyObject as StaticFileChunkingStrategyObject,\n    type StaticFileChunkingStrategyObjectParam as StaticFileChunkingStrategyObjectParam,\n    type VectorStore as VectorStore,\n    type VectorStoreDeleted as VectorStoreDeleted,\n    type VectorStoreSearchResponse as VectorStoreSearchResponse,\n    type VectorStoresPage as VectorStoresPage,\n    type VectorStoreSearchResponsesPage as VectorStoreSearchResponsesPage,\n    type VectorStoreCreateParams as VectorStoreCreateParams,\n    type VectorStoreUpdateParams as VectorStoreUpdateParams,\n    type VectorStoreListParams as VectorStoreListParams,\n    type VectorStoreSearchParams as VectorStoreSearchParams,\n  };\n\n  export {\n    Files as Files,\n    type VectorStoreFile as VectorStoreFile,\n    type VectorStoreFileDeleted as VectorStoreFileDeleted,\n    type FileContentResponse as FileContentResponse,\n    type VectorStoreFilesPage as VectorStoreFilesPage,\n    type FileContentResponsesPage as FileContentResponsesPage,\n    type FileCreateParams as FileCreateParams,\n    type FileRetrieveParams as FileRetrieveParams,\n    type FileUpdateParams as FileUpdateParams,\n    type FileListParams as FileListParams,\n    type FileDeleteParams as FileDeleteParams,\n    type FileContentParams as FileContentParams,\n  };\n\n  export {\n    FileBatches as FileBatches,\n    type VectorStoreFileBatch as VectorStoreFileBatch,\n    type FileBatchCreateParams as FileBatchCreateParams,\n    type FileBatchRetrieveParams as FileBatchRetrieveParams,\n    type FileBatchCancelParams as FileBatchCancelParams,\n    type FileBatchListFilesParams as FileBatchListFilesParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/vector-stores.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './vector-stores/index';\n"
  },
  {
    "path": "src/resources/videos.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport { APIPromise } from '../core/api-promise';\nimport { ConversationCursorPage, type ConversationCursorPageParams, PagePromise } from '../core/pagination';\nimport { type Uploadable } from '../core/uploads';\nimport { buildHeaders } from '../internal/headers';\nimport { RequestOptions } from '../internal/request-options';\nimport { maybeMultipartFormRequestOptions, multipartFormRequestOptions } from '../internal/uploads';\nimport { path } from '../internal/utils/path';\n\nexport class Videos extends APIResource {\n  /**\n   * Create a new video generation job from a prompt and optional reference assets.\n   */\n  create(body: VideoCreateParams, options?: RequestOptions): APIPromise<Video> {\n    return this._client.post('/videos', multipartFormRequestOptions({ body, ...options }, this._client));\n  }\n\n  /**\n   * Fetch the latest metadata for a generated video.\n   */\n  retrieve(videoID: string, options?: RequestOptions): APIPromise<Video> {\n    return this._client.get(path`/videos/${videoID}`, options);\n  }\n\n  /**\n   * List recently generated videos for the current project.\n   */\n  list(\n    query: VideoListParams | null | undefined = {},\n    options?: RequestOptions,\n  ): PagePromise<VideosPage, Video> {\n    return this._client.getAPIList('/videos', ConversationCursorPage<Video>, { query, ...options });\n  }\n\n  /**\n   * Permanently delete a completed or failed video and its stored assets.\n   */\n  delete(videoID: string, options?: RequestOptions): APIPromise<VideoDeleteResponse> {\n    return this._client.delete(path`/videos/${videoID}`, options);\n  }\n\n  /**\n   * Create a character from an uploaded video.\n   */\n  createCharacter(\n    body: VideoCreateCharacterParams,\n    options?: RequestOptions,\n  ): APIPromise<VideoCreateCharacterResponse> {\n    return this._client.post(\n      '/videos/characters',\n      multipartFormRequestOptions({ body, ...options }, this._client),\n    );\n  }\n\n  /**\n   * Download the generated video bytes or a derived preview asset.\n   *\n   * Streams the rendered video content for the specified video job.\n   */\n  downloadContent(\n    videoID: string,\n    query: VideoDownloadContentParams | null | undefined = {},\n    options?: RequestOptions,\n  ): APIPromise<Response> {\n    return this._client.get(path`/videos/${videoID}/content`, {\n      query,\n      ...options,\n      headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),\n      __binaryResponse: true,\n    });\n  }\n\n  /**\n   * Create a new video generation job by editing a source video or existing\n   * generated video.\n   */\n  edit(body: VideoEditParams, options?: RequestOptions): APIPromise<Video> {\n    return this._client.post(\n      '/videos/edits',\n      multipartFormRequestOptions({ body, ...options }, this._client),\n    );\n  }\n\n  /**\n   * Create an extension of a completed video.\n   */\n  extend(body: VideoExtendParams, options?: RequestOptions): APIPromise<Video> {\n    return this._client.post(\n      '/videos/extensions',\n      multipartFormRequestOptions({ body, ...options }, this._client),\n    );\n  }\n\n  /**\n   * Fetch a character.\n   */\n  getCharacter(characterID: string, options?: RequestOptions): APIPromise<VideoGetCharacterResponse> {\n    return this._client.get(path`/videos/characters/${characterID}`, options);\n  }\n\n  /**\n   * Create a remix of a completed video using a refreshed prompt.\n   */\n  remix(videoID: string, body: VideoRemixParams, options?: RequestOptions): APIPromise<Video> {\n    return this._client.post(\n      path`/videos/${videoID}/remix`,\n      maybeMultipartFormRequestOptions({ body, ...options }, this._client),\n    );\n  }\n}\n\nexport type VideosPage = ConversationCursorPage<Video>;\n\nexport interface ImageInputReferenceParam {\n  file_id?: string;\n\n  /**\n   * A fully qualified URL or base64-encoded data URL.\n   */\n  image_url?: string;\n}\n\n/**\n * Structured information describing a generated video job.\n */\nexport interface Video {\n  /**\n   * Unique identifier for the video job.\n   */\n  id: string;\n\n  /**\n   * Unix timestamp (seconds) for when the job completed, if finished.\n   */\n  completed_at: number | null;\n\n  /**\n   * Unix timestamp (seconds) for when the job was created.\n   */\n  created_at: number;\n\n  /**\n   * Error payload that explains why generation failed, if applicable.\n   */\n  error: VideoCreateError | null;\n\n  /**\n   * Unix timestamp (seconds) for when the downloadable assets expire, if set.\n   */\n  expires_at: number | null;\n\n  /**\n   * The video generation model that produced the job.\n   */\n  model: VideoModel;\n\n  /**\n   * The object type, which is always `video`.\n   */\n  object: 'video';\n\n  /**\n   * Approximate completion percentage for the generation task.\n   */\n  progress: number;\n\n  /**\n   * The prompt that was used to generate the video.\n   */\n  prompt: string | null;\n\n  /**\n   * Identifier of the source video if this video is a remix.\n   */\n  remixed_from_video_id: string | null;\n\n  /**\n   * Duration of the generated clip in seconds. For extensions, this is the stitched\n   * total duration.\n   */\n  seconds: (string & {}) | VideoSeconds;\n\n  /**\n   * The resolution of the generated video.\n   */\n  size: VideoSize;\n\n  /**\n   * Current lifecycle status of the video job.\n   */\n  status: 'queued' | 'in_progress' | 'completed' | 'failed';\n}\n\n/**\n * An error that occurred while generating the response.\n */\nexport interface VideoCreateError {\n  /**\n   * A machine-readable error code that was returned.\n   */\n  code: string;\n\n  /**\n   * A human-readable description of the error that was returned.\n   */\n  message: string;\n}\n\nexport type VideoModel =\n  | (string & {})\n  | 'sora-2'\n  | 'sora-2-pro'\n  | 'sora-2-2025-10-06'\n  | 'sora-2-pro-2025-10-06'\n  | 'sora-2-2025-12-08';\n\nexport type VideoSeconds = '4' | '8' | '12';\n\nexport type VideoSize = '720x1280' | '1280x720' | '1024x1792' | '1792x1024';\n\n/**\n * Confirmation payload returned after deleting a video.\n */\nexport interface VideoDeleteResponse {\n  /**\n   * Identifier of the deleted video.\n   */\n  id: string;\n\n  /**\n   * Indicates that the video resource was deleted.\n   */\n  deleted: boolean;\n\n  /**\n   * The object type that signals the deletion response.\n   */\n  object: 'video.deleted';\n}\n\nexport interface VideoCreateCharacterResponse {\n  /**\n   * Identifier for the character creation cameo.\n   */\n  id: string | null;\n\n  /**\n   * Unix timestamp (in seconds) when the character was created.\n   */\n  created_at: number;\n\n  /**\n   * Display name for the character.\n   */\n  name: string | null;\n}\n\nexport interface VideoGetCharacterResponse {\n  /**\n   * Identifier for the character creation cameo.\n   */\n  id: string | null;\n\n  /**\n   * Unix timestamp (in seconds) when the character was created.\n   */\n  created_at: number;\n\n  /**\n   * Display name for the character.\n   */\n  name: string | null;\n}\n\nexport interface VideoCreateParams {\n  /**\n   * Text prompt that describes the video to generate.\n   */\n  prompt: string;\n\n  /**\n   * Optional reference asset upload or reference object that guides generation.\n   */\n  input_reference?: Uploadable | ImageInputReferenceParam;\n\n  /**\n   * The video generation model to use (allowed values: sora-2, sora-2-pro). Defaults\n   * to `sora-2`.\n   */\n  model?: VideoModel;\n\n  /**\n   * Clip duration in seconds (allowed values: 4, 8, 12). Defaults to 4 seconds.\n   */\n  seconds?: VideoSeconds;\n\n  /**\n   * Output resolution formatted as width x height (allowed values: 720x1280,\n   * 1280x720, 1024x1792, 1792x1024). Defaults to 720x1280.\n   */\n  size?: VideoSize;\n}\n\nexport interface VideoListParams extends ConversationCursorPageParams {\n  /**\n   * Sort order of results by timestamp. Use `asc` for ascending order or `desc` for\n   * descending order.\n   */\n  order?: 'asc' | 'desc';\n}\n\nexport interface VideoCreateCharacterParams {\n  /**\n   * Display name for this API character.\n   */\n  name: string;\n\n  /**\n   * Video file used to create a character.\n   */\n  video: Uploadable;\n}\n\nexport interface VideoDownloadContentParams {\n  /**\n   * Which downloadable asset to return. Defaults to the MP4 video.\n   */\n  variant?: 'video' | 'thumbnail' | 'spritesheet';\n}\n\nexport interface VideoEditParams {\n  /**\n   * Text prompt that describes how to edit the source video.\n   */\n  prompt: string;\n\n  /**\n   * Reference to the completed video to edit.\n   */\n  video: Uploadable | VideoEditParams.VideoReferenceInputParam;\n}\n\nexport namespace VideoEditParams {\n  /**\n   * Reference to the completed video.\n   */\n  export interface VideoReferenceInputParam {\n    /**\n     * The identifier of the completed video.\n     */\n    id: string;\n  }\n}\n\nexport interface VideoExtendParams {\n  /**\n   * Updated text prompt that directs the extension generation.\n   */\n  prompt: string;\n\n  /**\n   * Length of the newly generated extension segment in seconds (allowed values: 4,\n   * 8, 12, 16, 20).\n   */\n  seconds: VideoSeconds;\n\n  /**\n   * Reference to the completed video to extend.\n   */\n  video: Uploadable | VideoExtendParams.VideoReferenceInputParam;\n}\n\nexport namespace VideoExtendParams {\n  /**\n   * Reference to the completed video.\n   */\n  export interface VideoReferenceInputParam {\n    /**\n     * The identifier of the completed video.\n     */\n    id: string;\n  }\n}\n\nexport interface VideoRemixParams {\n  /**\n   * Updated text prompt that directs the remix generation.\n   */\n  prompt: string;\n}\n\nexport declare namespace Videos {\n  export {\n    type ImageInputReferenceParam as ImageInputReferenceParam,\n    type Video as Video,\n    type VideoCreateError as VideoCreateError,\n    type VideoModel as VideoModel,\n    type VideoSeconds as VideoSeconds,\n    type VideoSize as VideoSize,\n    type VideoDeleteResponse as VideoDeleteResponse,\n    type VideoCreateCharacterResponse as VideoCreateCharacterResponse,\n    type VideoGetCharacterResponse as VideoGetCharacterResponse,\n    type VideosPage as VideosPage,\n    type VideoCreateParams as VideoCreateParams,\n    type VideoListParams as VideoListParams,\n    type VideoCreateCharacterParams as VideoCreateCharacterParams,\n    type VideoDownloadContentParams as VideoDownloadContentParams,\n    type VideoEditParams as VideoEditParams,\n    type VideoExtendParams as VideoExtendParams,\n    type VideoRemixParams as VideoRemixParams,\n  };\n}\n"
  },
  {
    "path": "src/resources/webhooks/api.md",
    "content": "# Webhooks\n\nTypes:\n\n- <code><a href=\"./src/resources/webhooks.ts\">BatchCancelledWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">BatchCompletedWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">BatchExpiredWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">BatchFailedWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">EvalRunCanceledWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">EvalRunFailedWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">EvalRunSucceededWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">FineTuningJobCancelledWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">FineTuningJobFailedWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">FineTuningJobSucceededWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">RealtimeCallIncomingWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">ResponseCancelledWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">ResponseCompletedWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">ResponseFailedWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">ResponseIncompleteWebhookEvent</a></code>\n- <code><a href=\"./src/resources/webhooks.ts\">UnwrapWebhookEvent</a></code>\n\nMethods:\n\n- <code>client.webhooks.<a href=\"./src/resources/webhooks.ts\">unwrap</a>(body) -> void</code>\n"
  },
  {
    "path": "src/resources/webhooks/index.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './webhooks';\n"
  },
  {
    "path": "src/resources/webhooks/webhooks.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { InvalidWebhookSignatureError } from '../../error';\nimport { APIResource } from '../../core/resource';\nimport { buildHeaders, HeadersLike } from '../../internal/headers';\n\nexport class Webhooks extends APIResource {\n  /**\n   * Validates that the given payload was sent by OpenAI and parses the payload.\n   */\n  async unwrap(\n    payload: string,\n    headers: HeadersLike,\n    secret: string | undefined | null = this._client.webhookSecret,\n    tolerance: number = 300,\n  ): Promise<UnwrapWebhookEvent> {\n    await this.verifySignature(payload, headers, secret, tolerance);\n\n    return JSON.parse(payload) as UnwrapWebhookEvent;\n  }\n\n  /**\n   * Validates whether or not the webhook payload was sent by OpenAI.\n   *\n   * An error will be raised if the webhook payload was not sent by OpenAI.\n   *\n   * @param payload - The webhook payload\n   * @param headers - The webhook headers\n   * @param secret - The webhook secret (optional, will use client secret if not provided)\n   * @param tolerance - Maximum age of the webhook in seconds (default: 300 = 5 minutes)\n   */\n  async verifySignature(\n    payload: string,\n    headers: HeadersLike,\n    secret: string | undefined | null = this._client.webhookSecret,\n    tolerance: number = 300,\n  ): Promise<void> {\n    if (\n      typeof crypto === 'undefined' ||\n      typeof crypto.subtle.importKey !== 'function' ||\n      typeof crypto.subtle.verify !== 'function'\n    ) {\n      throw new Error('Webhook signature verification is only supported when the `crypto` global is defined');\n    }\n\n    this.#validateSecret(secret);\n\n    const headersObj = buildHeaders([headers]).values;\n    const signatureHeader = this.#getRequiredHeader(headersObj, 'webhook-signature');\n    const timestamp = this.#getRequiredHeader(headersObj, 'webhook-timestamp');\n    const webhookId = this.#getRequiredHeader(headersObj, 'webhook-id');\n\n    // Validate timestamp to prevent replay attacks\n    const timestampSeconds = parseInt(timestamp, 10);\n    if (isNaN(timestampSeconds)) {\n      throw new InvalidWebhookSignatureError('Invalid webhook timestamp format');\n    }\n\n    const nowSeconds = Math.floor(Date.now() / 1000);\n\n    if (nowSeconds - timestampSeconds > tolerance) {\n      throw new InvalidWebhookSignatureError('Webhook timestamp is too old');\n    }\n\n    if (timestampSeconds > nowSeconds + tolerance) {\n      throw new InvalidWebhookSignatureError('Webhook timestamp is too new');\n    }\n\n    // Extract signatures from v1,<base64> format\n    // The signature header can have multiple values, separated by spaces.\n    // Each value is in the format v1,<base64>. We should accept if any match.\n    const signatures = signatureHeader\n      .split(' ')\n      .map((part) => (part.startsWith('v1,') ? part.substring(3) : part));\n\n    // Decode the secret if it starts with whsec_\n    const decodedSecret =\n      secret.startsWith('whsec_') ?\n        Buffer.from(secret.replace('whsec_', ''), 'base64')\n      : Buffer.from(secret, 'utf-8');\n\n    // Create the signed payload: {webhook_id}.{timestamp}.{payload}\n    const signedPayload = webhookId ? `${webhookId}.${timestamp}.${payload}` : `${timestamp}.${payload}`;\n\n    // Import the secret as a cryptographic key for HMAC\n    const key = await crypto.subtle.importKey(\n      'raw',\n      decodedSecret,\n      { name: 'HMAC', hash: 'SHA-256' },\n      false,\n      ['verify'],\n    );\n\n    // Check if any signature matches using timing-safe WebCrypto verify\n    for (const signature of signatures) {\n      try {\n        const signatureBytes = Buffer.from(signature, 'base64');\n        const isValid = await crypto.subtle.verify(\n          'HMAC',\n          key,\n          signatureBytes,\n          new TextEncoder().encode(signedPayload),\n        );\n\n        if (isValid) {\n          return; // Valid signature found\n        }\n      } catch {\n        // Invalid base64 or signature format, continue to next signature\n        continue;\n      }\n    }\n\n    throw new InvalidWebhookSignatureError(\n      'The given webhook signature does not match the expected signature',\n    );\n  }\n\n  #validateSecret(secret: string | null | undefined): asserts secret is string {\n    if (typeof secret !== 'string' || secret.length === 0) {\n      throw new Error(\n        `The webhook secret must either be set using the env var, OPENAI_WEBHOOK_SECRET, on the client class, OpenAI({ webhookSecret: '123' }), or passed to this function`,\n      );\n    }\n  }\n\n  #getRequiredHeader(headers: Headers, name: string): string {\n    if (!headers) {\n      throw new Error(`Headers are required`);\n    }\n\n    const value = headers.get(name);\n\n    if (value === null || value === undefined) {\n      throw new Error(`Missing required header: ${name}`);\n    }\n\n    return value;\n  }\n}\n\n/**\n * Sent when a batch API request has been cancelled.\n */\nexport interface BatchCancelledWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the batch API request was cancelled.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: BatchCancelledWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `batch.cancelled`.\n   */\n  type: 'batch.cancelled';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace BatchCancelledWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the batch API request.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when a batch API request has been completed.\n */\nexport interface BatchCompletedWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the batch API request was completed.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: BatchCompletedWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `batch.completed`.\n   */\n  type: 'batch.completed';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace BatchCompletedWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the batch API request.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when a batch API request has expired.\n */\nexport interface BatchExpiredWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the batch API request expired.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: BatchExpiredWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `batch.expired`.\n   */\n  type: 'batch.expired';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace BatchExpiredWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the batch API request.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when a batch API request has failed.\n */\nexport interface BatchFailedWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the batch API request failed.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: BatchFailedWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `batch.failed`.\n   */\n  type: 'batch.failed';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace BatchFailedWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the batch API request.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when an eval run has been canceled.\n */\nexport interface EvalRunCanceledWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the eval run was canceled.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: EvalRunCanceledWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `eval.run.canceled`.\n   */\n  type: 'eval.run.canceled';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace EvalRunCanceledWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the eval run.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when an eval run has failed.\n */\nexport interface EvalRunFailedWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the eval run failed.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: EvalRunFailedWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `eval.run.failed`.\n   */\n  type: 'eval.run.failed';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace EvalRunFailedWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the eval run.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when an eval run has succeeded.\n */\nexport interface EvalRunSucceededWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the eval run succeeded.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: EvalRunSucceededWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `eval.run.succeeded`.\n   */\n  type: 'eval.run.succeeded';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace EvalRunSucceededWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the eval run.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when a fine-tuning job has been cancelled.\n */\nexport interface FineTuningJobCancelledWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the fine-tuning job was cancelled.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: FineTuningJobCancelledWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `fine_tuning.job.cancelled`.\n   */\n  type: 'fine_tuning.job.cancelled';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace FineTuningJobCancelledWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the fine-tuning job.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when a fine-tuning job has failed.\n */\nexport interface FineTuningJobFailedWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the fine-tuning job failed.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: FineTuningJobFailedWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `fine_tuning.job.failed`.\n   */\n  type: 'fine_tuning.job.failed';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace FineTuningJobFailedWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the fine-tuning job.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when a fine-tuning job has succeeded.\n */\nexport interface FineTuningJobSucceededWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the fine-tuning job succeeded.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: FineTuningJobSucceededWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `fine_tuning.job.succeeded`.\n   */\n  type: 'fine_tuning.job.succeeded';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace FineTuningJobSucceededWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the fine-tuning job.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when Realtime API Receives a incoming SIP call.\n */\nexport interface RealtimeCallIncomingWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the model response was completed.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: RealtimeCallIncomingWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `realtime.call.incoming`.\n   */\n  type: 'realtime.call.incoming';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace RealtimeCallIncomingWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of this call.\n     */\n    call_id: string;\n\n    /**\n     * Headers from the SIP Invite.\n     */\n    sip_headers: Array<Data.SipHeader>;\n  }\n\n  export namespace Data {\n    /**\n     * A header from the SIP Invite.\n     */\n    export interface SipHeader {\n      /**\n       * Name of the SIP Header.\n       */\n      name: string;\n\n      /**\n       * Value of the SIP Header.\n       */\n      value: string;\n    }\n  }\n}\n\n/**\n * Sent when a background response has been cancelled.\n */\nexport interface ResponseCancelledWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the model response was cancelled.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: ResponseCancelledWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `response.cancelled`.\n   */\n  type: 'response.cancelled';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace ResponseCancelledWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the model response.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when a background response has been completed.\n */\nexport interface ResponseCompletedWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the model response was completed.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: ResponseCompletedWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `response.completed`.\n   */\n  type: 'response.completed';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace ResponseCompletedWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the model response.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when a background response has failed.\n */\nexport interface ResponseFailedWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the model response failed.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: ResponseFailedWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `response.failed`.\n   */\n  type: 'response.failed';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace ResponseFailedWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the model response.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when a background response has been interrupted.\n */\nexport interface ResponseIncompleteWebhookEvent {\n  /**\n   * The unique ID of the event.\n   */\n  id: string;\n\n  /**\n   * The Unix timestamp (in seconds) of when the model response was interrupted.\n   */\n  created_at: number;\n\n  /**\n   * Event data payload.\n   */\n  data: ResponseIncompleteWebhookEvent.Data;\n\n  /**\n   * The type of the event. Always `response.incomplete`.\n   */\n  type: 'response.incomplete';\n\n  /**\n   * The object of the event. Always `event`.\n   */\n  object?: 'event';\n}\n\nexport namespace ResponseIncompleteWebhookEvent {\n  /**\n   * Event data payload.\n   */\n  export interface Data {\n    /**\n     * The unique ID of the model response.\n     */\n    id: string;\n  }\n}\n\n/**\n * Sent when a batch API request has been cancelled.\n */\nexport type UnwrapWebhookEvent =\n  | BatchCancelledWebhookEvent\n  | BatchCompletedWebhookEvent\n  | BatchExpiredWebhookEvent\n  | BatchFailedWebhookEvent\n  | EvalRunCanceledWebhookEvent\n  | EvalRunFailedWebhookEvent\n  | EvalRunSucceededWebhookEvent\n  | FineTuningJobCancelledWebhookEvent\n  | FineTuningJobFailedWebhookEvent\n  | FineTuningJobSucceededWebhookEvent\n  | RealtimeCallIncomingWebhookEvent\n  | ResponseCancelledWebhookEvent\n  | ResponseCompletedWebhookEvent\n  | ResponseFailedWebhookEvent\n  | ResponseIncompleteWebhookEvent;\n\nexport declare namespace Webhooks {\n  export {\n    type BatchCancelledWebhookEvent as BatchCancelledWebhookEvent,\n    type BatchCompletedWebhookEvent as BatchCompletedWebhookEvent,\n    type BatchExpiredWebhookEvent as BatchExpiredWebhookEvent,\n    type BatchFailedWebhookEvent as BatchFailedWebhookEvent,\n    type EvalRunCanceledWebhookEvent as EvalRunCanceledWebhookEvent,\n    type EvalRunFailedWebhookEvent as EvalRunFailedWebhookEvent,\n    type EvalRunSucceededWebhookEvent as EvalRunSucceededWebhookEvent,\n    type FineTuningJobCancelledWebhookEvent as FineTuningJobCancelledWebhookEvent,\n    type FineTuningJobFailedWebhookEvent as FineTuningJobFailedWebhookEvent,\n    type FineTuningJobSucceededWebhookEvent as FineTuningJobSucceededWebhookEvent,\n    type RealtimeCallIncomingWebhookEvent as RealtimeCallIncomingWebhookEvent,\n    type ResponseCancelledWebhookEvent as ResponseCancelledWebhookEvent,\n    type ResponseCompletedWebhookEvent as ResponseCompletedWebhookEvent,\n    type ResponseFailedWebhookEvent as ResponseFailedWebhookEvent,\n    type ResponseIncompleteWebhookEvent as ResponseIncompleteWebhookEvent,\n    type UnwrapWebhookEvent as UnwrapWebhookEvent,\n  };\n}\n"
  },
  {
    "path": "src/resources/webhooks.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport * from './webhooks/index';\n"
  },
  {
    "path": "src/resources.ts",
    "content": "export * from './resources/index';\n"
  },
  {
    "path": "src/streaming.ts",
    "content": "/** @deprecated Import from ./core/streaming instead */\nexport * from './core/streaming';\n"
  },
  {
    "path": "src/uploads.ts",
    "content": "/** @deprecated Import from ./core/uploads instead */\nexport * from './core/uploads';\n"
  },
  {
    "path": "src/version.ts",
    "content": "export const VERSION = '6.32.0'; // x-release-please-version\n"
  },
  {
    "path": "tests/_vendor/partial-json-parser/partial-json-parsing.test.ts",
    "content": "import fc from 'fast-check';\nimport { MalformedJSON, partialParse } from 'openai/_vendor/partial-json-parser/parser';\n\ndescribe('partial parsing', () => {\n  test('should parse complete json', () => {\n    expect(partialParse('{\"__proto__\": 0}')).toEqual(JSON.parse('{\"__proto__\": 0}'));\n\n    fc.assert(\n      fc.property(fc.json({ depthSize: 'large', noUnicodeString: false }), (jsonString) => {\n        const parsedNormal = JSON.parse(jsonString);\n        const parsedPartial = partialParse(jsonString);\n        expect(parsedPartial).toEqual(parsedNormal);\n      }),\n    );\n  });\n\n  test('should parse partial json', () => {\n    expect(partialParse('{\"field')).toEqual({});\n    expect(partialParse('\"')).toEqual('');\n    expect(partialParse('[2, 3, 4')).toEqual([2, 3]);\n    expect(partialParse('{\"field\": true, \"field2')).toEqual({ field: true });\n    expect(partialParse('{\"field\": true, \"field2\":')).toEqual({ field: true });\n    expect(partialParse('{\"field\": true, \"field2\":{')).toEqual({ field: true, field2: {} });\n    expect(partialParse('{\"field\": true, \"field2\": { \"obj\": \"somestr')).toEqual({\n      field: true,\n      field2: { obj: 'somestr' },\n    });\n    expect(partialParse('{\"field\": true, \"field2\": { \"obj\": \"somestr\",')).toEqual({\n      field: true,\n      field2: { obj: 'somestr' },\n    });\n    expect(partialParse('{\"field\": \"va')).toEqual({ field: 'va' });\n    expect(partialParse('[ \"v1\", 2, \"v2\", 3')).toEqual(['v1', 2, 'v2']);\n    expect(partialParse('[ \"v1\", 2, \"v2\", -')).toEqual(['v1', 2, 'v2']);\n    expect(partialParse('[1, 2e')).toEqual([1]);\n  });\n\n  test('should only throw errors parsing numbers', () =>\n    fc.assert(\n      fc.property(fc.json({ depthSize: 'large', noUnicodeString: false }), (jsonString) => {\n        for (let i = 1; i < jsonString.length; i++) {\n          // speedup\n          i += Math.floor(Math.random() * 3);\n          const substring = jsonString.substring(0, i);\n\n          // since we don't allow partial parsing for numbers\n          if (\n            typeof JSON.parse(jsonString) === 'number' &&\n            'e-+.'.includes(substring[substring.length - 1]!)\n          ) {\n            expect(() => partialParse(substring)).toThrow(MalformedJSON);\n          } else {\n            partialParse(substring);\n          }\n        }\n      }),\n    ));\n});\n"
  },
  {
    "path": "tests/api-resources/audio/speech.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource speech', () => {\n  // binary tests are currently broken\n  test.skip('create: required and optional params', async () => {\n    const response = await client.audio.speech.create({\n      input: 'input',\n      model: 'string',\n      voice: 'string',\n      instructions: 'instructions',\n      response_format: 'mp3',\n      speed: 0.25,\n      stream_format: 'sse',\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/audio/transcriptions.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI, { toFile } from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource transcriptions', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.audio.transcriptions.create({\n      file: await toFile(Buffer.from('Example data'), 'README.md'),\n      model: 'gpt-4o-transcribe',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.audio.transcriptions.create({\n      file: await toFile(Buffer.from('Example data'), 'README.md'),\n      model: 'gpt-4o-transcribe',\n      chunking_strategy: 'auto',\n      include: ['logprobs'],\n      known_speaker_names: ['string'],\n      known_speaker_references: ['string'],\n      language: 'language',\n      prompt: 'prompt',\n      response_format: 'json',\n      stream: false,\n      temperature: 0,\n      timestamp_granularities: ['word'],\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/audio/translations.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI, { toFile } from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource translations', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.audio.translations.create({\n      file: await toFile(Buffer.from('Example data'), 'README.md'),\n      model: 'whisper-1',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.audio.translations.create({\n      file: await toFile(Buffer.from('Example data'), 'README.md'),\n      model: 'whisper-1',\n      prompt: 'prompt',\n      response_format: 'json',\n      temperature: 0,\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/batches.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource batches', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.batches.create({\n      completion_window: '24h',\n      endpoint: '/v1/responses',\n      input_file_id: 'input_file_id',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.batches.create({\n      completion_window: '24h',\n      endpoint: '/v1/responses',\n      input_file_id: 'input_file_id',\n      metadata: { foo: 'string' },\n      output_expires_after: { anchor: 'created_at', seconds: 3600 },\n    });\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.batches.retrieve('batch_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.batches.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.batches.list({ after: 'after', limit: 0 }, { path: '/_stainless_unknown_path' }),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('cancel', async () => {\n    const responsePromise = client.batches.cancel('batch_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/beta/assistants.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource assistants', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.beta.assistants.create({ model: 'gpt-4o' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.beta.assistants.create({\n      model: 'gpt-4o',\n      description: 'description',\n      instructions: 'instructions',\n      metadata: { foo: 'string' },\n      name: 'name',\n      reasoning_effort: 'none',\n      response_format: 'auto',\n      temperature: 1,\n      tool_resources: {\n        code_interpreter: { file_ids: ['string'] },\n        file_search: {\n          vector_store_ids: ['string'],\n          vector_stores: [\n            {\n              chunking_strategy: { type: 'auto' },\n              file_ids: ['string'],\n              metadata: { foo: 'string' },\n            },\n          ],\n        },\n      },\n      tools: [{ type: 'code_interpreter' }],\n      top_p: 1,\n    });\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.beta.assistants.retrieve('assistant_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update', async () => {\n    const responsePromise = client.beta.assistants.update('assistant_id', {});\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.beta.assistants.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.beta.assistants.list(\n        {\n          after: 'after',\n          before: 'before',\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.beta.assistants.delete('assistant_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/beta/chatkit/sessions.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource sessions', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.beta.chatkit.sessions.create({\n      user: 'x',\n      workflow: { id: 'id' },\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.beta.chatkit.sessions.create({\n      user: 'x',\n      workflow: {\n        id: 'id',\n        state_variables: { foo: 'string' },\n        tracing: { enabled: true },\n        version: 'version',\n      },\n      chatkit_configuration: {\n        automatic_thread_titling: { enabled: true },\n        file_upload: {\n          enabled: true,\n          max_file_size: 1,\n          max_files: 1,\n        },\n        history: { enabled: true, recent_threads: 1 },\n      },\n      expires_after: { anchor: 'created_at', seconds: 1 },\n      rate_limits: { max_requests_per_1_minute: 1 },\n    });\n  });\n\n  test('cancel', async () => {\n    const responsePromise = client.beta.chatkit.sessions.cancel('cksess_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/beta/chatkit/threads.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource threads', () => {\n  test('retrieve', async () => {\n    const responsePromise = client.beta.chatkit.threads.retrieve('cthr_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.beta.chatkit.threads.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.beta.chatkit.threads.list(\n        {\n          after: 'after',\n          before: 'before',\n          limit: 0,\n          order: 'asc',\n          user: 'x',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.beta.chatkit.threads.delete('cthr_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('listItems', async () => {\n    const responsePromise = client.beta.chatkit.threads.listItems('cthr_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('listItems: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.beta.chatkit.threads.listItems(\n        'cthr_123',\n        {\n          after: 'after',\n          before: 'before',\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/beta/threads/messages.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource messages', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.beta.threads.messages.create('thread_id', {\n      content: 'string',\n      role: 'user',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.beta.threads.messages.create('thread_id', {\n      content: 'string',\n      role: 'user',\n      attachments: [{ file_id: 'file_id', tools: [{ type: 'code_interpreter' }] }],\n      metadata: { foo: 'string' },\n    });\n  });\n\n  test('retrieve: only required params', async () => {\n    const responsePromise = client.beta.threads.messages.retrieve('message_id', { thread_id: 'thread_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: required and optional params', async () => {\n    const response = await client.beta.threads.messages.retrieve('message_id', { thread_id: 'thread_id' });\n  });\n\n  test('update: only required params', async () => {\n    const responsePromise = client.beta.threads.messages.update('message_id', { thread_id: 'thread_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update: required and optional params', async () => {\n    const response = await client.beta.threads.messages.update('message_id', {\n      thread_id: 'thread_id',\n      metadata: { foo: 'string' },\n    });\n  });\n\n  test('list', async () => {\n    const responsePromise = client.beta.threads.messages.list('thread_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.beta.threads.messages.list(\n        'thread_id',\n        {\n          after: 'after',\n          before: 'before',\n          limit: 0,\n          order: 'asc',\n          run_id: 'run_id',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete: only required params', async () => {\n    const responsePromise = client.beta.threads.messages.delete('message_id', { thread_id: 'thread_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('delete: required and optional params', async () => {\n    const response = await client.beta.threads.messages.delete('message_id', { thread_id: 'thread_id' });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/beta/threads/runs/runs.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource runs', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.beta.threads.runs.create('thread_id', { assistant_id: 'assistant_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.beta.threads.runs.create('thread_id', {\n      assistant_id: 'assistant_id',\n      include: ['step_details.tool_calls[*].file_search.results[*].content'],\n      additional_instructions: 'additional_instructions',\n      additional_messages: [\n        {\n          content: 'string',\n          role: 'user',\n          attachments: [{ file_id: 'file_id', tools: [{ type: 'code_interpreter' }] }],\n          metadata: { foo: 'string' },\n        },\n      ],\n      instructions: 'instructions',\n      max_completion_tokens: 256,\n      max_prompt_tokens: 256,\n      metadata: { foo: 'string' },\n      model: 'string',\n      parallel_tool_calls: true,\n      reasoning_effort: 'none',\n      response_format: 'auto',\n      stream: false,\n      temperature: 1,\n      tool_choice: 'none',\n      tools: [{ type: 'code_interpreter' }],\n      top_p: 1,\n      truncation_strategy: { type: 'auto', last_messages: 1 },\n    });\n  });\n\n  test('retrieve: only required params', async () => {\n    const responsePromise = client.beta.threads.runs.retrieve('run_id', { thread_id: 'thread_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: required and optional params', async () => {\n    const response = await client.beta.threads.runs.retrieve('run_id', { thread_id: 'thread_id' });\n  });\n\n  test('update: only required params', async () => {\n    const responsePromise = client.beta.threads.runs.update('run_id', { thread_id: 'thread_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update: required and optional params', async () => {\n    const response = await client.beta.threads.runs.update('run_id', {\n      thread_id: 'thread_id',\n      metadata: { foo: 'string' },\n    });\n  });\n\n  test('list', async () => {\n    const responsePromise = client.beta.threads.runs.list('thread_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.beta.threads.runs.list(\n        'thread_id',\n        {\n          after: 'after',\n          before: 'before',\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('cancel: only required params', async () => {\n    const responsePromise = client.beta.threads.runs.cancel('run_id', { thread_id: 'thread_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('cancel: required and optional params', async () => {\n    const response = await client.beta.threads.runs.cancel('run_id', { thread_id: 'thread_id' });\n  });\n\n  test('submitToolOutputs: only required params', async () => {\n    const responsePromise = client.beta.threads.runs.submitToolOutputs('run_id', {\n      thread_id: 'thread_id',\n      tool_outputs: [{}],\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('submitToolOutputs: required and optional params', async () => {\n    const response = await client.beta.threads.runs.submitToolOutputs('run_id', {\n      thread_id: 'thread_id',\n      tool_outputs: [{ output: 'output', tool_call_id: 'tool_call_id' }],\n      stream: false,\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/beta/threads/runs/steps.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource steps', () => {\n  test('retrieve: only required params', async () => {\n    const responsePromise = client.beta.threads.runs.steps.retrieve('step_id', {\n      thread_id: 'thread_id',\n      run_id: 'run_id',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: required and optional params', async () => {\n    const response = await client.beta.threads.runs.steps.retrieve('step_id', {\n      thread_id: 'thread_id',\n      run_id: 'run_id',\n      include: ['step_details.tool_calls[*].file_search.results[*].content'],\n    });\n  });\n\n  test('list: only required params', async () => {\n    const responsePromise = client.beta.threads.runs.steps.list('run_id', { thread_id: 'thread_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: required and optional params', async () => {\n    const response = await client.beta.threads.runs.steps.list('run_id', {\n      thread_id: 'thread_id',\n      after: 'after',\n      before: 'before',\n      include: ['step_details.tool_calls[*].file_search.results[*].content'],\n      limit: 0,\n      order: 'asc',\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/beta/threads/threads.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource threads', () => {\n  test('create', async () => {\n    const responsePromise = client.beta.threads.create();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.beta.threads.create(\n        {\n          messages: [\n            {\n              content: 'string',\n              role: 'user',\n              attachments: [{ file_id: 'file_id', tools: [{ type: 'code_interpreter' }] }],\n              metadata: { foo: 'string' },\n            },\n          ],\n          metadata: { foo: 'string' },\n          tool_resources: {\n            code_interpreter: { file_ids: ['string'] },\n            file_search: {\n              vector_store_ids: ['string'],\n              vector_stores: [\n                {\n                  chunking_strategy: { type: 'auto' },\n                  file_ids: ['string'],\n                  metadata: { foo: 'string' },\n                },\n              ],\n            },\n          },\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.beta.threads.retrieve('thread_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update', async () => {\n    const responsePromise = client.beta.threads.update('thread_id', {});\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.beta.threads.delete('thread_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('createAndRun: only required params', async () => {\n    const responsePromise = client.beta.threads.createAndRun({ assistant_id: 'assistant_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('createAndRun: required and optional params', async () => {\n    const response = await client.beta.threads.createAndRun({\n      assistant_id: 'assistant_id',\n      instructions: 'instructions',\n      max_completion_tokens: 256,\n      max_prompt_tokens: 256,\n      metadata: { foo: 'string' },\n      model: 'string',\n      parallel_tool_calls: true,\n      response_format: 'auto',\n      stream: false,\n      temperature: 1,\n      thread: {\n        messages: [\n          {\n            content: 'string',\n            role: 'user',\n            attachments: [{ file_id: 'file_id', tools: [{ type: 'code_interpreter' }] }],\n            metadata: { foo: 'string' },\n          },\n        ],\n        metadata: { foo: 'string' },\n        tool_resources: {\n          code_interpreter: { file_ids: ['string'] },\n          file_search: {\n            vector_store_ids: ['string'],\n            vector_stores: [\n              {\n                chunking_strategy: { type: 'auto' },\n                file_ids: ['string'],\n                metadata: { foo: 'string' },\n              },\n            ],\n          },\n        },\n      },\n      tool_choice: 'none',\n      tool_resources: {\n        code_interpreter: { file_ids: ['string'] },\n        file_search: { vector_store_ids: ['string'] },\n      },\n      tools: [{ type: 'code_interpreter' }],\n      top_p: 1,\n      truncation_strategy: { type: 'auto', last_messages: 1 },\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/chat/completions/completions.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource completions', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.chat.completions.create({\n      messages: [{ content: 'string', role: 'developer' }],\n      model: 'gpt-5.4',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.chat.completions.create({\n      messages: [\n        {\n          content: 'string',\n          role: 'developer',\n          name: 'name',\n        },\n      ],\n      model: 'gpt-5.4',\n      audio: { format: 'wav', voice: 'string' },\n      frequency_penalty: -2,\n      function_call: 'none',\n      functions: [\n        {\n          name: 'name',\n          description: 'description',\n          parameters: { foo: 'bar' },\n        },\n      ],\n      logit_bias: { foo: 0 },\n      logprobs: true,\n      max_completion_tokens: 0,\n      max_tokens: 0,\n      metadata: { foo: 'string' },\n      modalities: ['text'],\n      n: 1,\n      parallel_tool_calls: true,\n      prediction: { content: 'string', type: 'content' },\n      presence_penalty: -2,\n      prompt_cache_key: 'prompt-cache-key-1234',\n      prompt_cache_retention: 'in-memory',\n      reasoning_effort: 'none',\n      response_format: { type: 'text' },\n      safety_identifier: 'safety-identifier-1234',\n      seed: -9007199254740991,\n      service_tier: 'auto',\n      stop: '\\n',\n      store: true,\n      stream: false,\n      stream_options: { include_obfuscation: true, include_usage: true },\n      temperature: 1,\n      tool_choice: 'none',\n      tools: [\n        {\n          function: {\n            name: 'name',\n            description: 'description',\n            parameters: { foo: 'bar' },\n            strict: true,\n          },\n          type: 'function',\n        },\n      ],\n      top_logprobs: 0,\n      top_p: 1,\n      user: 'user-1234',\n      verbosity: 'low',\n      web_search_options: {\n        search_context_size: 'low',\n        user_location: {\n          approximate: {\n            city: 'city',\n            country: 'country',\n            region: 'region',\n            timezone: 'timezone',\n          },\n          type: 'approximate',\n        },\n      },\n    });\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.chat.completions.retrieve('completion_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update: only required params', async () => {\n    const responsePromise = client.chat.completions.update('completion_id', { metadata: { foo: 'string' } });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update: required and optional params', async () => {\n    const response = await client.chat.completions.update('completion_id', { metadata: { foo: 'string' } });\n  });\n\n  test('list', async () => {\n    const responsePromise = client.chat.completions.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.chat.completions.list(\n        {\n          after: 'after',\n          limit: 0,\n          metadata: { foo: 'string' },\n          model: 'model',\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.chat.completions.delete('completion_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/chat/completions/messages.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource messages', () => {\n  test('list', async () => {\n    const responsePromise = client.chat.completions.messages.list('completion_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.chat.completions.messages.list(\n        'completion_id',\n        {\n          after: 'after',\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/completions.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource completions', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.completions.create({ model: 'string', prompt: 'This is a test.' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.completions.create({\n      model: 'string',\n      prompt: 'This is a test.',\n      best_of: 0,\n      echo: true,\n      frequency_penalty: -2,\n      logit_bias: { foo: 0 },\n      logprobs: 0,\n      max_tokens: 16,\n      n: 1,\n      presence_penalty: -2,\n      seed: 0,\n      stop: '\\n',\n      stream: false,\n      stream_options: { include_obfuscation: true, include_usage: true },\n      suffix: 'test.',\n      temperature: 1,\n      top_p: 1,\n      user: 'user-1234',\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/containers/containers.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource containers', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.containers.create({ name: 'name' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.containers.create({\n      name: 'name',\n      expires_after: { anchor: 'last_active_at', minutes: 0 },\n      file_ids: ['string'],\n      memory_limit: '1g',\n      network_policy: { type: 'disabled' },\n      skills: [\n        {\n          skill_id: 'x',\n          type: 'skill_reference',\n          version: 'version',\n        },\n      ],\n    });\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.containers.retrieve('container_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.containers.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.containers.list(\n        {\n          after: 'after',\n          limit: 0,\n          name: 'name',\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.containers.delete('container_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/containers/files/content.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource content', () => {\n  // Mock server doesn't support application/binary responses\n  test.skip('retrieve: required and optional params', async () => {\n    const response = await client.containers.files.content.retrieve('file_id', {\n      container_id: 'container_id',\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/containers/files/files.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource files', () => {\n  test('create', async () => {\n    const responsePromise = client.containers.files.create('container_id', {});\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: only required params', async () => {\n    const responsePromise = client.containers.files.retrieve('file_id', { container_id: 'container_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: required and optional params', async () => {\n    const response = await client.containers.files.retrieve('file_id', { container_id: 'container_id' });\n  });\n\n  test('list', async () => {\n    const responsePromise = client.containers.files.list('container_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.containers.files.list(\n        'container_id',\n        {\n          after: 'after',\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete: only required params', async () => {\n    const responsePromise = client.containers.files.delete('file_id', { container_id: 'container_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('delete: required and optional params', async () => {\n    const response = await client.containers.files.delete('file_id', { container_id: 'container_id' });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/conversations/conversations.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource conversations', () => {\n  test('create', async () => {\n    const responsePromise = client.conversations.create();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.conversations.create(\n        {\n          items: [\n            {\n              content: 'string',\n              role: 'user',\n              phase: 'commentary',\n              type: 'message',\n            },\n          ],\n          metadata: { foo: 'string' },\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.conversations.retrieve('conv_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update: only required params', async () => {\n    const responsePromise = client.conversations.update('conv_123', { metadata: { foo: 'string' } });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update: required and optional params', async () => {\n    const response = await client.conversations.update('conv_123', { metadata: { foo: 'string' } });\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.conversations.delete('conv_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/conversations/items.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource items', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.conversations.items.create('conv_123', {\n      items: [\n        {\n          content: 'string',\n          role: 'user',\n          type: 'message',\n        },\n      ],\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.conversations.items.create('conv_123', {\n      items: [\n        {\n          content: 'string',\n          role: 'user',\n          phase: 'commentary',\n          type: 'message',\n        },\n      ],\n      include: ['file_search_call.results'],\n    });\n  });\n\n  test('retrieve: only required params', async () => {\n    const responsePromise = client.conversations.items.retrieve('msg_abc', { conversation_id: 'conv_123' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: required and optional params', async () => {\n    const response = await client.conversations.items.retrieve('msg_abc', {\n      conversation_id: 'conv_123',\n      include: ['file_search_call.results'],\n    });\n  });\n\n  test('list', async () => {\n    const responsePromise = client.conversations.items.list('conv_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.conversations.items.list(\n        'conv_123',\n        {\n          after: 'after',\n          include: ['file_search_call.results'],\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete: only required params', async () => {\n    const responsePromise = client.conversations.items.delete('msg_abc', { conversation_id: 'conv_123' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('delete: required and optional params', async () => {\n    const response = await client.conversations.items.delete('msg_abc', { conversation_id: 'conv_123' });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/embeddings-base64-response.json",
    "content": "{\"object\":\"list\",\"data\":[{\"object\":\"embedding\",\"index\":0,\"embedding\":\"A1fLvaC4Bb0QB7w8yEvrPOm9Xj2r0yA8EW4sPRq75j3Fbiq81/chPumAGb0afqG8R6AFvpzsQT35SPO7Hi39PEMAir1lf0A92McfvRoVlLxQv9o9tHqIvQYlrL0fwlK8sufPPYz2gjzH5Ho93GebvN+eCTxjRjW8PJRKvXMtFD4+n3C9ByMPO39Gkjs1Jm49A1fLPdNXpjv8RLm92McfveKpLz01VNO9SUIevhAHvD0flG09+9srvW5j7Txp8dY8LW4Ju08bJb1GdL29g+aNPWlLBD1p8dY8LkCkvfPLtjxcBj4+1/ehPebv/bz/Ifo8SqkOvREFHzyAr588HbUPPbFS+r00gri825WAPQlcGj1qHZ+8o8EOPo880Tn5dli9zRUSPc2APD0b5RG9mhxEvTyUSj3FQMU95u/9vE20tD3wwBC94NmxvXSUhL3Ofh8904WLPRbeJb2Paja8BClmvhwgOj2e6Ic9em0LPdj1BD3lSau7dJQEPJi107yB6kc97sTKO6lAaD2YDwE9YDuPPSFVC735dtg9SK1IOysJNrwtQkE8BmJxPb2ZXT0hVYs9g+YNvLfuuz2nyhe9z7nHN5UVWDxea5E77F1avTIbyL256oG9ft+hPVWJAbwNoug82TCtvUrm072wgN86JPWGO3TRyTwOY4a8xJwPvkx5DL1f1B68RwkTvja7Q72BrQI9Pfs6PTdfeb3RxG09jJxVvfl22D3eCbQ9FbR6vTPtYrn0mzS+kqGkPDxXhbwyG8i98M9wveayuL1EpL88lNqvve3yL70RQmQ7VcZGPaPBjr1wyEA9fKaWOskMibwNomi8J9Rku9EeGz016Si8O1mivQ38lb0EgxO88P1VvcilmLuNA0a9lj8DvHCceD3lSSs9uFWsve6HBT6XEZ68ShS5PFJSE70dTIK86OvDvSNgsbzS8DU8bPz8PAuVpTxKQIE9/NmOPBhFFj7LsL67PJRKvIxu8LwSqVS8D8yTPSOOlj1g0gG8A+69vYz2AjxPhLK80fLSPbrL/LztWz09LAcZvqfKF73B/JO8lnzIvCk5OLxwMU69dmQCvQtp3bs6hwe9WZKKume4S7x3CLg9zK4hPLsjDT16P6a7MbTXPRp+IT0dtQ89GayGvcngwD2F8bO70R4bu8tFlDxcBr67xAWdvdnWfzzQTIC9zn6fPYSKwz3alx28h8GxPW74wj3eNxk+xUBFvIpjyj0WdRi9AkoIPXhvqLugx+U8F0ezvUlCHjx3NAC9uvlhPEOmXD36oAM9D56uvddgrz2giiC9GhWUvHrWGLv0yRk8fOPbvMc+KLs7//S8v5UjPJUV2D0KLjW6YKa5PDciNDuJznQ9USZLPQ==\"}],\"model\":\"text-embedding-3-large\",\"usage\":{\"prompt_tokens\":1,\"total_tokens\":1}}"
  },
  {
    "path": "tests/api-resources/embeddings-float-response.json",
    "content": "{\"object\":\"list\",\"data\":[{\"object\":\"embedding\",\"index\":0,\"embedding\":[-0.099287055,-0.032646775,0.022952586,0.028722659,0.05438033,0.009816091,0.042097155,0.112661555,-0.010402386,0.158172,-0.037476454,-0.01971345,-0.13049422,0.04734479,-0.0074244705,0.030905303,-0.06738331,0.046996493,-0.039008945,-0.018076468,0.10681021,-0.06664029,-0.08405499,-0.012863665,0.10151614,0.015986703,0.061253335,-0.018970422,0.008399694,-0.011064145,-0.049457774,0.14470463,-0.058745615,0.0021840946,0.00446397,0.058141906,0.099287055,0.0050763874,-0.09046361,-0.039008945,0.042886622,-0.103187956,-0.15454973,0.091810346,0.058002587,-0.041957837,0.028978076,0.02623816,-0.002097021,-0.040309247,-0.09250693,0.06928732,0.03229848,0.02623816,-0.08020054,0.022314047,0.18557113,0.079086,-0.030998182,0.030533789,-0.034829415,0.009705798,0.019492865,0.035084832,-0.122228034,-0.022523023,0.06278583,0.037685428,-0.019423205,0.13941054,0.00039908706,-0.052847836,0.035665322,0.04602127,-0.035618883,-0.04787884,0.049457774,0.096314944,-0.030998182,0.08823452,-0.03534025,-0.086841345,-0.06473628,0.03893929,0.06812634,-0.040495,-0.011133804,-0.22476584,0.045440778,0.06636165,0.03403995,0.032461017,-0.005227315,0.008092035,-0.025843427,0.048807625,0.0061880266,0.05670229,0.031509012,0.06993747,-0.034016732,0.10569567,0.0030620862,-0.011110584,0.011795563,0.058931373,0.054101694,0.068033464,-0.008660915,0.091763906,-0.0370585,0.000023809172,0.013188739,0.004437848,-0.053312227,-0.09770812,-0.06343598,0.07903956,-0.007906278,0.028397584,-0.084565826,-0.103466585,0.0017051902,0.0041185785,0.024636008,-0.016404655,-0.14024645,-0.034295365,-0.009694188,-0.14359008,-0.04778596,0.031903747,0.045649756,-0.06088182,0.058049027,-0.052151248,0.10569567,0.087909445,-0.061206896,-0.00021641403,-0.17637616,0.020096574,-0.016276948,-0.09770812,-0.058792055,-0.09018497,0.023393758,-0.08586612,-0.04295628,0.0034829418,0.048528988,-0.06970527,0.047066152,0.0011493708,-0.01672973,-0.014198792,-0.0034916492,0.037871186,-0.010309507,-0.079271756,-0.073234655,-0.0090034045,-0.052244127,-0.0046584345,-0.04834323,-0.008010766,0.060696065,0.04181852,-0.08414787,0.13040134,-0.019295497,0.022592682,-0.03596718,-0.015905434,-0.0956648,-0.021652287,0.011104779,0.030882083,0.02021267,0.0631109,0.017437927,0.14674795,-0.005819415,-0.012364443,-0.029349588,-0.012979763,0.072166555,0.07351329,-0.007923692,-0.09273913,0.007993352,-0.021791605,0.1030022,-0.030858863,0.046230245,-0.14944142,-0.0370585,-0.018064858,-0.02447347,-0.011244097,-0.050340116,-0.03183409,-0.006756907,-0.033087946,-0.001057218,-0.012434102,0.089859895,0.009868335,0.034457903,-0.005073485,0.10532416,0.0394269,0.035084832,-0.06575794,0.09417874,-0.005491438,-0.002366949,0.018099686,-0.005799098,-0.07667115,0.0156151885,-0.06264651,0.07787858,0.09547904,-0.009618724,0.086794905,0.095200405,0.14962718,-0.012039368,0.09882267,-0.037221037,0.033273704,-0.0051402412,0.02804929,-0.08753794,0.009659358,-0.031300034,0.01379245,0.053869497,0.03213594,-0.08526241,0.085633926,-0.039194703,-0.018076468,-0.0023321197,0.009386528,-0.026841871,-0.0025672184,-0.02990686,0.009984433,0.105509914,-0.00069114624,0.022662342,0.0027486214,0.05976728,0.04959709]}],\"model\":\"text-embedding-3-large\",\"usage\":{\"prompt_tokens\":1,\"total_tokens\":1}}"
  },
  {
    "path": "tests/api-resources/embeddings.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\nimport { mockFetch } from '../utils/mock-fetch';\nimport fs from 'fs/promises';\nimport Path from 'path';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource embeddings', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.embeddings.create({\n      input: 'The quick brown fox jumped over the lazy dog',\n      model: 'text-embedding-3-small',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.embeddings.create({\n      input: 'The quick brown fox jumped over the lazy dog',\n      model: 'text-embedding-3-small',\n      dimensions: 1,\n      encoding_format: 'float',\n      user: 'user-1234',\n    });\n  });\n\n  test('create: encoding_format=default should create float32 embeddings', async () => {\n    const client = makeClient();\n    const response = await client.embeddings.create({\n      input: 'The quick brown fox jumped over the lazy dog',\n      model: 'text-embedding-3-small',\n    });\n\n    expect(Array.isArray(response.data?.at(0)?.embedding)).toBe(true);\n    expect(response.data?.at(0)?.embedding.at(0)).toBe(-0.09928705543279648);\n  });\n\n  test('create: encoding_format=float should create float32 embeddings', async () => {\n    const client = makeClient();\n    const response = await client.embeddings.create({\n      input: 'The quick brown fox jumped over the lazy dog',\n      model: 'text-embedding-3-small',\n      encoding_format: 'float',\n    });\n\n    expect(Array.isArray(response.data?.at(0)?.embedding)).toBe(true);\n    expect(response.data?.at(0)?.embedding.at(0)).toBe(-0.099287055);\n  });\n\n  test('create: encoding_format=base64 should return base64 embeddings', async () => {\n    const client = makeClient();\n    const response = await client.embeddings.create({\n      input: 'The quick brown fox jumped over the lazy dog',\n      model: 'text-embedding-3-small',\n      encoding_format: 'base64',\n    });\n\n    expect(typeof response.data?.at(0)?.embedding).toBe('string');\n  });\n});\n\nfunction makeClient(): OpenAI {\n  const { fetch, handleRequest } = mockFetch();\n\n  handleRequest(async (_, init) => {\n    const format = (JSON.parse(init!.body as string) as OpenAI.EmbeddingCreateParams).encoding_format;\n    return new Response(\n      await fs.readFile(\n        Path.join(\n          __dirname,\n\n          // these responses were taken from the live API with:\n          //\n          // model: 'text-embedding-3-large',\n          // input: 'h',\n          // dimensions: 256,\n\n          format === 'base64' ? 'embeddings-base64-response.json' : 'embeddings-float-response.json',\n        ),\n      ),\n      {\n        status: 200,\n        headers: {\n          'Content-Type': 'application/json',\n        },\n      },\n    );\n  });\n\n  return new OpenAI({\n    fetch,\n    apiKey: 'My API Key',\n    baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n  });\n}\n"
  },
  {
    "path": "tests/api-resources/evals/evals.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource evals', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.evals.create({\n      data_source_config: {\n        item_schema: { foo: 'bar' },\n        type: 'custom',\n      },\n      testing_criteria: [\n        {\n          input: [{ content: 'content', role: 'role' }],\n          labels: ['string'],\n          model: 'model',\n          name: 'name',\n          passing_labels: ['string'],\n          type: 'label_model',\n        },\n      ],\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.evals.create({\n      data_source_config: {\n        item_schema: { foo: 'bar' },\n        type: 'custom',\n        include_sample_schema: true,\n      },\n      testing_criteria: [\n        {\n          input: [{ content: 'content', role: 'role' }],\n          labels: ['string'],\n          model: 'model',\n          name: 'name',\n          passing_labels: ['string'],\n          type: 'label_model',\n        },\n      ],\n      metadata: { foo: 'string' },\n      name: 'name',\n    });\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.evals.retrieve('eval_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update', async () => {\n    const responsePromise = client.evals.update('eval_id', {});\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.evals.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.evals.list(\n        {\n          after: 'after',\n          limit: 0,\n          order: 'asc',\n          order_by: 'created_at',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.evals.delete('eval_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/evals/runs/output-items.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource outputItems', () => {\n  test('retrieve: only required params', async () => {\n    const responsePromise = client.evals.runs.outputItems.retrieve('output_item_id', {\n      eval_id: 'eval_id',\n      run_id: 'run_id',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: required and optional params', async () => {\n    const response = await client.evals.runs.outputItems.retrieve('output_item_id', {\n      eval_id: 'eval_id',\n      run_id: 'run_id',\n    });\n  });\n\n  test('list: only required params', async () => {\n    const responsePromise = client.evals.runs.outputItems.list('run_id', { eval_id: 'eval_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: required and optional params', async () => {\n    const response = await client.evals.runs.outputItems.list('run_id', {\n      eval_id: 'eval_id',\n      after: 'after',\n      limit: 0,\n      order: 'asc',\n      status: 'fail',\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/evals/runs/runs.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource runs', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.evals.runs.create('eval_id', {\n      data_source: {\n        source: { content: [{ item: { foo: 'bar' } }], type: 'file_content' },\n        type: 'jsonl',\n      },\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.evals.runs.create('eval_id', {\n      data_source: {\n        source: {\n          content: [\n            {\n              item: { foo: 'bar' },\n              sample: { foo: 'bar' },\n            },\n          ],\n          type: 'file_content',\n        },\n        type: 'jsonl',\n      },\n      metadata: { foo: 'string' },\n      name: 'name',\n    });\n  });\n\n  test('retrieve: only required params', async () => {\n    const responsePromise = client.evals.runs.retrieve('run_id', { eval_id: 'eval_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: required and optional params', async () => {\n    const response = await client.evals.runs.retrieve('run_id', { eval_id: 'eval_id' });\n  });\n\n  test('list', async () => {\n    const responsePromise = client.evals.runs.list('eval_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.evals.runs.list(\n        'eval_id',\n        {\n          after: 'after',\n          limit: 0,\n          order: 'asc',\n          status: 'queued',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete: only required params', async () => {\n    const responsePromise = client.evals.runs.delete('run_id', { eval_id: 'eval_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('delete: required and optional params', async () => {\n    const response = await client.evals.runs.delete('run_id', { eval_id: 'eval_id' });\n  });\n\n  test('cancel: only required params', async () => {\n    const responsePromise = client.evals.runs.cancel('run_id', { eval_id: 'eval_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('cancel: required and optional params', async () => {\n    const response = await client.evals.runs.cancel('run_id', { eval_id: 'eval_id' });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/files.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI, { toFile } from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource files', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.files.create({\n      file: await toFile(Buffer.from('Example data'), 'README.md'),\n      purpose: 'assistants',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.files.create({\n      file: await toFile(Buffer.from('Example data'), 'README.md'),\n      purpose: 'assistants',\n      expires_after: { anchor: 'created_at', seconds: 3600 },\n    });\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.files.retrieve('file_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.files.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.files.list(\n        {\n          after: 'after',\n          limit: 0,\n          order: 'asc',\n          purpose: 'purpose',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.files.delete('file_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/fine-tuning/alpha/graders.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource graders', () => {\n  test('run: only required params', async () => {\n    const responsePromise = client.fineTuning.alpha.graders.run({\n      grader: {\n        input: 'input',\n        name: 'name',\n        operation: 'eq',\n        reference: 'reference',\n        type: 'string_check',\n      },\n      model_sample: 'model_sample',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('run: required and optional params', async () => {\n    const response = await client.fineTuning.alpha.graders.run({\n      grader: {\n        input: 'input',\n        name: 'name',\n        operation: 'eq',\n        reference: 'reference',\n        type: 'string_check',\n      },\n      model_sample: 'model_sample',\n      item: {},\n    });\n  });\n\n  test('validate: only required params', async () => {\n    const responsePromise = client.fineTuning.alpha.graders.validate({\n      grader: {\n        input: 'input',\n        name: 'name',\n        operation: 'eq',\n        reference: 'reference',\n        type: 'string_check',\n      },\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('validate: required and optional params', async () => {\n    const response = await client.fineTuning.alpha.graders.validate({\n      grader: {\n        input: 'input',\n        name: 'name',\n        operation: 'eq',\n        reference: 'reference',\n        type: 'string_check',\n      },\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/fine-tuning/checkpoints/permissions.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource permissions', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.fineTuning.checkpoints.permissions.create(\n      'ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd',\n      { project_ids: ['string'] },\n    );\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.fineTuning.checkpoints.permissions.create(\n      'ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd',\n      { project_ids: ['string'] },\n    );\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.fineTuning.checkpoints.permissions.retrieve('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.fineTuning.checkpoints.permissions.retrieve(\n        'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n        {\n          after: 'after',\n          limit: 0,\n          order: 'ascending',\n          project_id: 'project_id',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.fineTuning.checkpoints.permissions.list('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.fineTuning.checkpoints.permissions.list(\n        'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n        {\n          after: 'after',\n          limit: 0,\n          order: 'ascending',\n          project_id: 'project_id',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete: only required params', async () => {\n    const responsePromise = client.fineTuning.checkpoints.permissions.delete('cp_zc4Q7MP6XxulcVzj4MZdwsAB', {\n      fine_tuned_model_checkpoint: 'ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('delete: required and optional params', async () => {\n    const response = await client.fineTuning.checkpoints.permissions.delete('cp_zc4Q7MP6XxulcVzj4MZdwsAB', {\n      fine_tuned_model_checkpoint: 'ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd',\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/fine-tuning/jobs/checkpoints.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource checkpoints', () => {\n  test('list', async () => {\n    const responsePromise = client.fineTuning.jobs.checkpoints.list('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.fineTuning.jobs.checkpoints.list(\n        'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n        { after: 'after', limit: 0 },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/fine-tuning/jobs/jobs.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource jobs', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.fineTuning.jobs.create({\n      model: 'gpt-4o-mini',\n      training_file: 'file-abc123',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.fineTuning.jobs.create({\n      model: 'gpt-4o-mini',\n      training_file: 'file-abc123',\n      hyperparameters: {\n        batch_size: 'auto',\n        learning_rate_multiplier: 'auto',\n        n_epochs: 'auto',\n      },\n      integrations: [\n        {\n          type: 'wandb',\n          wandb: {\n            project: 'my-wandb-project',\n            entity: 'entity',\n            name: 'name',\n            tags: ['custom-tag'],\n          },\n        },\n      ],\n      metadata: { foo: 'string' },\n      method: {\n        type: 'supervised',\n        dpo: {\n          hyperparameters: {\n            batch_size: 'auto',\n            beta: 'auto',\n            learning_rate_multiplier: 'auto',\n            n_epochs: 'auto',\n          },\n        },\n        reinforcement: {\n          grader: {\n            input: 'input',\n            name: 'name',\n            operation: 'eq',\n            reference: 'reference',\n            type: 'string_check',\n          },\n          hyperparameters: {\n            batch_size: 'auto',\n            compute_multiplier: 'auto',\n            eval_interval: 'auto',\n            eval_samples: 'auto',\n            learning_rate_multiplier: 'auto',\n            n_epochs: 'auto',\n            reasoning_effort: 'default',\n          },\n        },\n        supervised: {\n          hyperparameters: {\n            batch_size: 'auto',\n            learning_rate_multiplier: 'auto',\n            n_epochs: 'auto',\n          },\n        },\n      },\n      seed: 42,\n      suffix: 'x',\n      validation_file: 'file-abc123',\n    });\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.fineTuning.jobs.retrieve('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.fineTuning.jobs.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.fineTuning.jobs.list(\n        {\n          after: 'after',\n          limit: 0,\n          metadata: { foo: 'string' },\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('cancel', async () => {\n    const responsePromise = client.fineTuning.jobs.cancel('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('listEvents', async () => {\n    const responsePromise = client.fineTuning.jobs.listEvents('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('listEvents: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.fineTuning.jobs.listEvents(\n        'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n        { after: 'after', limit: 0 },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('pause', async () => {\n    const responsePromise = client.fineTuning.jobs.pause('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('resume', async () => {\n    const responsePromise = client.fineTuning.jobs.resume('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/images.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI, { toFile } from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource images', () => {\n  test('createVariation: only required params', async () => {\n    const responsePromise = client.images.createVariation({\n      image: await toFile(Buffer.from('Example data'), 'README.md'),\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('createVariation: required and optional params', async () => {\n    const response = await client.images.createVariation({\n      image: await toFile(Buffer.from('Example data'), 'README.md'),\n      model: 'string',\n      n: 1,\n      response_format: 'url',\n      size: '1024x1024',\n      user: 'user-1234',\n    });\n  });\n\n  test('edit: only required params', async () => {\n    const responsePromise = client.images.edit({\n      image: await toFile(Buffer.from('Example data'), 'README.md'),\n      prompt: 'A cute baby sea otter wearing a beret',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('edit: required and optional params', async () => {\n    const response = await client.images.edit({\n      image: await toFile(Buffer.from('Example data'), 'README.md'),\n      prompt: 'A cute baby sea otter wearing a beret',\n      background: 'transparent',\n      input_fidelity: 'high',\n      mask: await toFile(Buffer.from('Example data'), 'README.md'),\n      model: 'string',\n      n: 1,\n      output_compression: 100,\n      output_format: 'png',\n      partial_images: 1,\n      quality: 'high',\n      response_format: 'url',\n      size: '1024x1024',\n      stream: false,\n      user: 'user-1234',\n    });\n  });\n\n  test('generate: only required params', async () => {\n    const responsePromise = client.images.generate({ prompt: 'A cute baby sea otter' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('generate: required and optional params', async () => {\n    const response = await client.images.generate({\n      prompt: 'A cute baby sea otter',\n      background: 'transparent',\n      model: 'string',\n      moderation: 'low',\n      n: 1,\n      output_compression: 100,\n      output_format: 'png',\n      partial_images: 1,\n      quality: 'medium',\n      response_format: 'url',\n      size: '1024x1024',\n      stream: false,\n      style: 'vivid',\n      user: 'user-1234',\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/models.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource models', () => {\n  test('retrieve', async () => {\n    const responsePromise = client.models.retrieve('gpt-4o-mini');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.models.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.models.delete('ft:gpt-4o-mini:acemeco:suffix:abc123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/moderations.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource moderations', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.moderations.create({ input: 'I want to kill them.' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.moderations.create({ input: 'I want to kill them.', model: 'string' });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/realtime/calls.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource calls', () => {\n  test('accept: only required params', async () => {\n    const responsePromise = client.realtime.calls.accept('call_id', { type: 'realtime' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('accept: required and optional params', async () => {\n    const response = await client.realtime.calls.accept('call_id', {\n      type: 'realtime',\n      audio: {\n        input: {\n          format: { rate: 24000, type: 'audio/pcm' },\n          noise_reduction: { type: 'near_field' },\n          transcription: {\n            language: 'language',\n            model: 'string',\n            prompt: 'prompt',\n          },\n          turn_detection: {\n            type: 'server_vad',\n            create_response: true,\n            idle_timeout_ms: 5000,\n            interrupt_response: true,\n            prefix_padding_ms: 0,\n            silence_duration_ms: 0,\n            threshold: 0,\n          },\n        },\n        output: {\n          format: { rate: 24000, type: 'audio/pcm' },\n          speed: 0.25,\n          voice: 'string',\n        },\n      },\n      include: ['item.input_audio_transcription.logprobs'],\n      instructions: 'instructions',\n      max_output_tokens: 0,\n      model: 'string',\n      output_modalities: ['text'],\n      prompt: {\n        id: 'id',\n        variables: { foo: 'string' },\n        version: 'version',\n      },\n      tool_choice: 'none',\n      tools: [\n        {\n          description: 'description',\n          name: 'name',\n          parameters: {},\n          type: 'function',\n        },\n      ],\n      tracing: 'auto',\n      truncation: 'auto',\n    });\n  });\n\n  test('hangup', async () => {\n    const responsePromise = client.realtime.calls.hangup('call_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('refer: only required params', async () => {\n    const responsePromise = client.realtime.calls.refer('call_id', { target_uri: 'tel:+14155550123' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('refer: required and optional params', async () => {\n    const response = await client.realtime.calls.refer('call_id', { target_uri: 'tel:+14155550123' });\n  });\n\n  test('reject', async () => {\n    const responsePromise = client.realtime.calls.reject('call_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('reject: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.realtime.calls.reject('call_id', { status_code: 486 }, { path: '/_stainless_unknown_path' }),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/realtime/client-secrets.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource clientSecrets', () => {\n  test('create', async () => {\n    const responsePromise = client.realtime.clientSecrets.create({});\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/responses/input-items.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource inputItems', () => {\n  test('list', async () => {\n    const responsePromise = client.responses.inputItems.list('response_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.responses.inputItems.list(\n        'response_id',\n        {\n          after: 'after',\n          include: ['file_search_call.results'],\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/responses/input-tokens.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource inputTokens', () => {\n  test('count', async () => {\n    const responsePromise = client.responses.inputTokens.count();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('count: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.responses.inputTokens.count(\n        {\n          conversation: 'string',\n          input: 'string',\n          instructions: 'instructions',\n          model: 'model',\n          parallel_tool_calls: true,\n          previous_response_id: 'resp_123',\n          reasoning: {\n            effort: 'none',\n            generate_summary: 'auto',\n            summary: 'auto',\n          },\n          text: {\n            format: { type: 'text' },\n            verbosity: 'low',\n          },\n          tool_choice: 'none',\n          tools: [\n            {\n              name: 'name',\n              parameters: { foo: 'bar' },\n              strict: true,\n              type: 'function',\n              defer_loading: true,\n              description: 'description',\n            },\n          ],\n          truncation: 'auto',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/responses/responses.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource responses', () => {\n  test('create', async () => {\n    const responsePromise = client.responses.create({});\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n\n    expect(response).toHaveProperty('output_text');\n    expect(typeof response.output_text).toBe('string');\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.responses.retrieve('resp_677efb5139a88190b512bc3fef8e535d');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n\n    expect(response).toHaveProperty('output_text');\n    expect(typeof response.output_text).toBe('string');\n  });\n\n  test('retrieve: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.responses.retrieve(\n        'resp_677efb5139a88190b512bc3fef8e535d',\n        {\n          include: ['file_search_call.results'],\n          include_obfuscation: true,\n          starting_after: 0,\n          stream: false,\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.responses.delete('resp_677efb5139a88190b512bc3fef8e535d');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('cancel', async () => {\n    const responsePromise = client.responses.cancel('resp_677efb5139a88190b512bc3fef8e535d');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('compact: only required params', async () => {\n    const responsePromise = client.responses.compact({ model: 'gpt-5.4' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('compact: required and optional params', async () => {\n    const response = await client.responses.compact({\n      model: 'gpt-5.4',\n      input: 'string',\n      instructions: 'instructions',\n      previous_response_id: 'resp_123',\n      prompt_cache_key: 'prompt_cache_key',\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/skills/skills.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI, { toFile } from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource skills', () => {\n  test('create', async () => {\n    const responsePromise = client.skills.create();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.skills.create(\n        { files: [await toFile(Buffer.from('Example data'), 'README.md')] },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.skills.retrieve('skill_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update: only required params', async () => {\n    const responsePromise = client.skills.update('skill_123', { default_version: 'default_version' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update: required and optional params', async () => {\n    const response = await client.skills.update('skill_123', { default_version: 'default_version' });\n  });\n\n  test('list', async () => {\n    const responsePromise = client.skills.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.skills.list(\n        {\n          after: 'after',\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.skills.delete('skill_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/skills/versions/content.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource content', () => {\n  // Mock server (Prism) doesn't support the generated binary Accept header (`application/binary`) for this endpoint.\n  test.skip('retrieve: required and optional params', async () => {\n    const response = await client.skills.versions.content.retrieve('version', { skill_id: 'skill_123' });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/skills/versions/versions.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI, { toFile } from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource versions', () => {\n  test('create', async () => {\n    const responsePromise = client.skills.versions.create('skill_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.skills.versions.create(\n        'skill_123',\n        { default: true, files: [await toFile(Buffer.from('Example data'), 'README.md')] },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('retrieve: only required params', async () => {\n    const responsePromise = client.skills.versions.retrieve('version', { skill_id: 'skill_123' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: required and optional params', async () => {\n    const response = await client.skills.versions.retrieve('version', { skill_id: 'skill_123' });\n  });\n\n  test('list', async () => {\n    const responsePromise = client.skills.versions.list('skill_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.skills.versions.list(\n        'skill_123',\n        {\n          after: 'skillver_123',\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete: only required params', async () => {\n    const responsePromise = client.skills.versions.delete('version', { skill_id: 'skill_123' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('delete: required and optional params', async () => {\n    const response = await client.skills.versions.delete('version', { skill_id: 'skill_123' });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/uploads/parts.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI, { toFile } from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource parts', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.uploads.parts.create('upload_abc123', {\n      data: await toFile(Buffer.from('Example data'), 'README.md'),\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.uploads.parts.create('upload_abc123', {\n      data: await toFile(Buffer.from('Example data'), 'README.md'),\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/uploads/uploads.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource uploads', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.uploads.create({\n      bytes: 0,\n      filename: 'filename',\n      mime_type: 'mime_type',\n      purpose: 'assistants',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.uploads.create({\n      bytes: 0,\n      filename: 'filename',\n      mime_type: 'mime_type',\n      purpose: 'assistants',\n      expires_after: { anchor: 'created_at', seconds: 3600 },\n    });\n  });\n\n  test('cancel', async () => {\n    const responsePromise = client.uploads.cancel('upload_abc123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('complete: only required params', async () => {\n    const responsePromise = client.uploads.complete('upload_abc123', { part_ids: ['string'] });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('complete: required and optional params', async () => {\n    const response = await client.uploads.complete('upload_abc123', { part_ids: ['string'], md5: 'md5' });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/vector-stores/file-batches.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource fileBatches', () => {\n  test('create', async () => {\n    const responsePromise = client.vectorStores.fileBatches.create('vs_abc123', {});\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: only required params', async () => {\n    const responsePromise = client.vectorStores.fileBatches.retrieve('vsfb_abc123', {\n      vector_store_id: 'vs_abc123',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: required and optional params', async () => {\n    const response = await client.vectorStores.fileBatches.retrieve('vsfb_abc123', {\n      vector_store_id: 'vs_abc123',\n    });\n  });\n\n  test('cancel: only required params', async () => {\n    const responsePromise = client.vectorStores.fileBatches.cancel('batch_id', {\n      vector_store_id: 'vector_store_id',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('cancel: required and optional params', async () => {\n    const response = await client.vectorStores.fileBatches.cancel('batch_id', {\n      vector_store_id: 'vector_store_id',\n    });\n  });\n\n  test('listFiles: only required params', async () => {\n    const responsePromise = client.vectorStores.fileBatches.listFiles('batch_id', {\n      vector_store_id: 'vector_store_id',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('listFiles: required and optional params', async () => {\n    const response = await client.vectorStores.fileBatches.listFiles('batch_id', {\n      vector_store_id: 'vector_store_id',\n      after: 'after',\n      before: 'before',\n      filter: 'in_progress',\n      limit: 0,\n      order: 'asc',\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/vector-stores/files.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource files', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.vectorStores.files.create('vs_abc123', { file_id: 'file_id' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.vectorStores.files.create('vs_abc123', {\n      file_id: 'file_id',\n      attributes: { foo: 'string' },\n      chunking_strategy: { type: 'auto' },\n    });\n  });\n\n  test('retrieve: only required params', async () => {\n    const responsePromise = client.vectorStores.files.retrieve('file-abc123', {\n      vector_store_id: 'vs_abc123',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve: required and optional params', async () => {\n    const response = await client.vectorStores.files.retrieve('file-abc123', {\n      vector_store_id: 'vs_abc123',\n    });\n  });\n\n  test('update: only required params', async () => {\n    const responsePromise = client.vectorStores.files.update('file-abc123', {\n      vector_store_id: 'vs_abc123',\n      attributes: { foo: 'string' },\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update: required and optional params', async () => {\n    const response = await client.vectorStores.files.update('file-abc123', {\n      vector_store_id: 'vs_abc123',\n      attributes: { foo: 'string' },\n    });\n  });\n\n  test('list', async () => {\n    const responsePromise = client.vectorStores.files.list('vector_store_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.vectorStores.files.list(\n        'vector_store_id',\n        {\n          after: 'after',\n          before: 'before',\n          filter: 'in_progress',\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete: only required params', async () => {\n    const responsePromise = client.vectorStores.files.delete('file_id', {\n      vector_store_id: 'vector_store_id',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('delete: required and optional params', async () => {\n    const response = await client.vectorStores.files.delete('file_id', {\n      vector_store_id: 'vector_store_id',\n    });\n  });\n\n  test('content: only required params', async () => {\n    const responsePromise = client.vectorStores.files.content('file-abc123', {\n      vector_store_id: 'vs_abc123',\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('content: required and optional params', async () => {\n    const response = await client.vectorStores.files.content('file-abc123', { vector_store_id: 'vs_abc123' });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/vector-stores/vector-stores.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource vectorStores', () => {\n  test('create', async () => {\n    const responsePromise = client.vectorStores.create({});\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.vectorStores.retrieve('vector_store_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('update', async () => {\n    const responsePromise = client.vectorStores.update('vector_store_id', {});\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.vectorStores.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.vectorStores.list(\n        {\n          after: 'after',\n          before: 'before',\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.vectorStores.delete('vector_store_id');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('search: only required params', async () => {\n    const responsePromise = client.vectorStores.search('vs_abc123', { query: 'string' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('search: required and optional params', async () => {\n    const response = await client.vectorStores.search('vs_abc123', {\n      query: 'string',\n      filters: {\n        key: 'key',\n        type: 'eq',\n        value: 'string',\n      },\n      max_num_results: 1,\n      ranking_options: { ranker: 'none', score_threshold: 0 },\n      rewrite_query: true,\n    });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/videos.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI, { toFile } from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource videos', () => {\n  test('create: only required params', async () => {\n    const responsePromise = client.videos.create({ prompt: 'x' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('create: required and optional params', async () => {\n    const response = await client.videos.create({\n      prompt: 'x',\n      input_reference: await toFile(Buffer.from('Example data'), 'README.md'),\n      model: 'string',\n      seconds: '4',\n      size: '720x1280',\n    });\n  });\n\n  test('retrieve', async () => {\n    const responsePromise = client.videos.retrieve('video_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list', async () => {\n    const responsePromise = client.videos.list();\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('list: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.videos.list(\n        {\n          after: 'after',\n          limit: 0,\n          order: 'asc',\n        },\n        { path: '/_stainless_unknown_path' },\n      ),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('delete', async () => {\n    const responsePromise = client.videos.delete('video_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('createCharacter: only required params', async () => {\n    const responsePromise = client.videos.createCharacter({\n      name: 'x',\n      video: await toFile(Buffer.from('Example data'), 'README.md'),\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('createCharacter: required and optional params', async () => {\n    const response = await client.videos.createCharacter({\n      name: 'x',\n      video: await toFile(Buffer.from('Example data'), 'README.md'),\n    });\n  });\n\n  // Mock server doesn't support application/binary responses\n  test.skip('downloadContent: request options and params are passed correctly', async () => {\n    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error\n    await expect(\n      client.videos.downloadContent('video_123', { variant: 'video' }, { path: '/_stainless_unknown_path' }),\n    ).rejects.toThrow(OpenAI.NotFoundError);\n  });\n\n  test('edit: only required params', async () => {\n    const responsePromise = client.videos.edit({\n      prompt: 'x',\n      video: await toFile(Buffer.from('Example data'), 'README.md'),\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('edit: required and optional params', async () => {\n    const response = await client.videos.edit({\n      prompt: 'x',\n      video: await toFile(Buffer.from('Example data'), 'README.md'),\n    });\n  });\n\n  test('extend: only required params', async () => {\n    const responsePromise = client.videos.extend({\n      prompt: 'x',\n      seconds: '4',\n      video: await toFile(Buffer.from('Example data'), 'README.md'),\n    });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('extend: required and optional params', async () => {\n    const response = await client.videos.extend({\n      prompt: 'x',\n      seconds: '4',\n      video: await toFile(Buffer.from('Example data'), 'README.md'),\n    });\n  });\n\n  test('getCharacter', async () => {\n    const responsePromise = client.videos.getCharacter('char_123');\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('remix: only required params', async () => {\n    const responsePromise = client.videos.remix('video_123', { prompt: 'x' });\n    const rawResponse = await responsePromise.asResponse();\n    expect(rawResponse).toBeInstanceOf(Response);\n    const response = await responsePromise;\n    expect(response).not.toBeInstanceOf(Response);\n    const dataAndResponse = await responsePromise.withResponse();\n    expect(dataAndResponse.data).toBe(response);\n    expect(dataAndResponse.response).toBe(rawResponse);\n  });\n\n  test('remix: required and optional params', async () => {\n    const response = await client.videos.remix('video_123', { prompt: 'x' });\n  });\n});\n"
  },
  {
    "path": "tests/api-resources/webhooks.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('resource webhooks', () => {\n  // all this data is taken from a real webhook event\n  const payload = `{\"id\": \"evt_685c059ae3a481909bdc86819b066fb6\", \"object\": \"event\", \"created_at\": 1750861210, \"type\": \"response.completed\", \"data\": {\"id\": \"resp_123\"}}`;\n  const webhookSignature = 'v1,gUAg4R2hWouRZqRQG4uJypNS8YK885G838+EHb4nKBY=';\n  const testTimestamp = 1750861210;\n  const webhookTimestamp = testTimestamp.toString();\n  const webhookId = 'wh_685c059ae39c8190af8c71ed1022a24d';\n  const headers = new Headers({\n    'webhook-signature': webhookSignature,\n    'webhook-timestamp': webhookTimestamp,\n    'webhook-id': webhookId,\n  });\n  const secret = 'whsec_RdvaYFYUXuIFuEbvZHwMfYFhUf7aMYjYcmM24+Aj40c=';\n\n  // Mock time to match our test timestamp\n  const mockNow = testTimestamp * 1000; // Convert to milliseconds\n\n  beforeEach(() => {\n    jest.spyOn(global.Date, 'now').mockImplementation(() => mockNow);\n  });\n\n  afterEach(() => {\n    // restore the spy created with spyOn\n    jest.restoreAllMocks();\n  });\n\n  describe('unwrap', () => {\n    it('deserializes the payload object', async () => {\n      const unwrapped = await client.webhooks.unwrap(payload, headers, secret);\n\n      expect(unwrapped).toEqual({\n        id: 'evt_685c059ae3a481909bdc86819b066fb6',\n        object: 'event',\n        created_at: 1750861210,\n        type: 'response.completed',\n        data: { id: 'resp_123' },\n      });\n    });\n  });\n\n  describe('verifySignature', () => {\n    it('should pass for valid signature', async () => {\n      await client.webhooks.verifySignature(payload, headers, secret);\n    });\n\n    it('should throw an error for invalid secret format', async () => {\n      await expect(\n        client.webhooks.verifySignature(payload, headers, null as any),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(\n        `\"The webhook secret must either be set using the env var, OPENAI_WEBHOOK_SECRET, on the client class, OpenAI({ webhookSecret: '123' }), or passed to this function\"`,\n      );\n    });\n\n    it('should throw for invalid signature', async () => {\n      await expect(\n        client.webhooks.verifySignature(payload, headers, Buffer.from('foo').toString('base64')),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(\n        `\"The given webhook signature does not match the expected signature\"`,\n      );\n    });\n\n    it('should throw for missing webhook-signature header', async () => {\n      const incompleteHeaders = new Headers({\n        'webhook-timestamp': webhookTimestamp,\n        'webhook-id': webhookId,\n      });\n\n      await expect(\n        client.webhooks.verifySignature(payload, incompleteHeaders, secret),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(`\"Missing required header: webhook-signature\"`);\n    });\n\n    it('should throw for missing webhook-timestamp header', async () => {\n      const incompleteHeaders = new Headers({\n        'webhook-signature': webhookSignature,\n        'webhook-id': webhookId,\n      });\n\n      await expect(\n        client.webhooks.verifySignature(payload, incompleteHeaders, secret),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(`\"Missing required header: webhook-timestamp\"`);\n    });\n\n    it('should throw for missing webhook-id header', async () => {\n      const incompleteHeaders = new Headers({\n        'webhook-signature': webhookSignature,\n        'webhook-timestamp': webhookTimestamp,\n      });\n\n      await expect(\n        client.webhooks.verifySignature(payload, incompleteHeaders, secret),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(`\"Missing required header: webhook-id\"`);\n    });\n\n    it('should throw if payload is not a string', async () => {\n      await expect(\n        client.webhooks.verifySignature({ payload: 'not a string' } as any, headers, secret),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(\n        `\"The given webhook signature does not match the expected signature\"`,\n      );\n    });\n\n    it('should throw for timestamp too old', async () => {\n      // Create a timestamp that is older than 5 minutes from our mocked \"now\" time\n      const oldTimestamp = (testTimestamp - 400).toString(); // 6 minutes 40 seconds ago\n      const oldHeaders = new Headers({\n        'webhook-signature': 'v1,dummy_signature',\n        'webhook-timestamp': oldTimestamp,\n        'webhook-id': webhookId,\n      });\n\n      await expect(\n        client.webhooks.verifySignature(payload, oldHeaders, secret),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(`\"Webhook timestamp is too old\"`);\n    });\n\n    it('should throw for timestamp too new', async () => {\n      // Create a timestamp that is in the future beyond tolerance\n      const futureTimestamp = (testTimestamp + 400).toString(); // 6 minutes 40 seconds in the future\n      const futureHeaders = new Headers({\n        'webhook-signature': 'v1,dummy_signature',\n        'webhook-timestamp': futureTimestamp,\n        'webhook-id': webhookId,\n      });\n\n      await expect(\n        client.webhooks.verifySignature(payload, futureHeaders, secret),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(`\"Webhook timestamp is too new\"`);\n    });\n\n    it('should throw for invalid timestamp format', async () => {\n      const invalidHeaders = new Headers({\n        'webhook-signature': webhookSignature,\n        'webhook-timestamp': 'not-a-number',\n        'webhook-id': webhookId,\n      });\n\n      await expect(\n        client.webhooks.verifySignature(payload, invalidHeaders, secret),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(`\"Invalid webhook timestamp format\"`);\n    });\n\n    it('should pass with custom tolerance', async () => {\n      // Create a timestamp that would normally be too old with default tolerance\n      const oldTimestamp = (testTimestamp - 400).toString(); // 6 minutes 40 seconds ago\n      const oldHeaders = new Headers({\n        'webhook-signature': 'v1,dummy_signature',\n        'webhook-timestamp': oldTimestamp,\n        'webhook-id': webhookId,\n      });\n\n      // Should fail with default tolerance\n      await expect(\n        client.webhooks.verifySignature(payload, oldHeaders, secret),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(`\"Webhook timestamp is too old\"`);\n\n      // Should still fail with custom tolerance of 10 minutes because signature won't match\n      await expect(\n        client.webhooks.verifySignature(payload, oldHeaders, secret, 600),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(\n        `\"The given webhook signature does not match the expected signature\"`,\n      );\n    });\n\n    it('should pass for multiple signatures when one is valid', async () => {\n      // Test multiple signatures: one invalid, one valid\n      const multipleSignatures = `v1,invalid_signature ${webhookSignature}`;\n      const multipleHeaders = new Headers({\n        'webhook-signature': multipleSignatures,\n        'webhook-timestamp': webhookTimestamp,\n        'webhook-id': webhookId,\n      });\n\n      // Should not throw when at least one signature is valid\n      await client.webhooks.verifySignature(payload, multipleHeaders, secret);\n    });\n\n    it('should throw for multiple signatures when all are invalid', async () => {\n      // Test multiple invalid signatures\n      const multipleInvalidSignatures = 'v1,invalid_signature1 v1,invalid_signature2';\n      const multipleHeaders = new Headers({\n        'webhook-signature': multipleInvalidSignatures,\n        'webhook-timestamp': webhookTimestamp,\n        'webhook-id': webhookId,\n      });\n\n      await expect(\n        client.webhooks.verifySignature(payload, multipleHeaders, secret),\n      ).rejects.toThrowErrorMatchingInlineSnapshot(\n        `\"The given webhook signature does not match the expected signature\"`,\n      );\n    });\n  });\n});\n"
  },
  {
    "path": "tests/backwards-compat-resource-exports.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport type { BatchCancelledWebhookEvent, UnwrapWebhookEvent } from '../src/resources/webhooks';\nimport type { Conversation, ConversationDeletedResource } from '../src/resources/conversations';\n\nconst expectType = <T>(_value: T): void => {};\n\ndescribe('backwards compatibility: resource type exports', () => {\n  test('legacy resource paths continue exporting types after resource splitting', () => {\n    expectType<UnwrapWebhookEvent | null>(null);\n    expectType<BatchCancelledWebhookEvent | null>(null);\n    expectType<Conversation | null>(null);\n    expectType<ConversationDeletedResource | null>(null);\n\n    expect(true).toBe(true);\n  });\n});\n"
  },
  {
    "path": "tests/base64.test.ts",
    "content": "import { fromBase64, toBase64 } from 'openai/internal/utils/base64';\n\ndescribe.each(['Buffer', 'atob'])('with %s', (mode) => {\n  let originalBuffer: BufferConstructor;\n  beforeAll(() => {\n    if (mode === 'atob') {\n      originalBuffer = globalThis.Buffer;\n      // @ts-expect-error Can't assign undefined to BufferConstructor\n      delete globalThis.Buffer;\n    }\n  });\n  afterAll(() => {\n    if (mode === 'atob') {\n      globalThis.Buffer = originalBuffer;\n    }\n  });\n  test('toBase64', () => {\n    const testCases = [\n      {\n        input: 'hello world',\n        expected: 'aGVsbG8gd29ybGQ=',\n      },\n      {\n        input: new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]),\n        expected: 'aGVsbG8gd29ybGQ=',\n      },\n      {\n        input: undefined,\n        expected: '',\n      },\n      {\n        input: new Uint8Array([\n          229, 102, 215, 230, 65, 22, 46, 87, 243, 176, 99, 99, 31, 174, 8, 242, 83, 142, 169, 64, 122, 123,\n          193, 71,\n        ]),\n        expected: '5WbX5kEWLlfzsGNjH64I8lOOqUB6e8FH',\n      },\n      {\n        input: '✓',\n        expected: '4pyT',\n      },\n      {\n        input: new Uint8Array([226, 156, 147]),\n        expected: '4pyT',\n      },\n    ];\n\n    testCases.forEach(({ input, expected }) => {\n      expect(toBase64(input)).toBe(expected);\n    });\n  });\n\n  test('fromBase64', () => {\n    const testCases = [\n      {\n        input: 'aGVsbG8gd29ybGQ=',\n        expected: new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]),\n      },\n      {\n        input: '',\n        expected: new Uint8Array([]),\n      },\n      {\n        input: '5WbX5kEWLlfzsGNjH64I8lOOqUB6e8FH',\n        expected: new Uint8Array([\n          229, 102, 215, 230, 65, 22, 46, 87, 243, 176, 99, 99, 31, 174, 8, 242, 83, 142, 169, 64, 122, 123,\n          193, 71,\n        ]),\n      },\n      {\n        input: '4pyT',\n        expected: new Uint8Array([226, 156, 147]),\n      },\n    ];\n\n    testCases.forEach(({ input, expected }) => {\n      expect(fromBase64(input)).toEqual(expected);\n    });\n  });\n});\n"
  },
  {
    "path": "tests/buildHeaders.test.ts",
    "content": "import { inspect } from 'node:util';\nimport { buildHeaders, type HeadersLike, type NullableHeaders } from 'openai/internal/headers';\n\nfunction inspectNullableHeaders(headers: NullableHeaders) {\n  return `NullableHeaders {${[\n    ...[...headers.values.entries()].map(([name, value]) => ` ${inspect(name)}: ${inspect(value)}`),\n    ...[...headers.nulls].map((name) => ` ${inspect(name)}: null`),\n  ].join(', ')} }`;\n}\n\ndescribe('buildHeaders', () => {\n  const cases: [HeadersLike[], string][] = [\n    [[new Headers({ 'content-type': 'text/plain' })], `NullableHeaders { 'content-type': 'text/plain' }`],\n    [\n      [\n        {\n          'content-type': 'text/plain',\n        },\n        {\n          'Content-Type': undefined,\n        },\n      ],\n      `NullableHeaders { 'content-type': 'text/plain' }`,\n    ],\n    [\n      [\n        {\n          'content-type': 'text/plain',\n        },\n        {\n          'Content-Type': null,\n        },\n      ],\n      `NullableHeaders { 'content-type': null }`,\n    ],\n    [\n      [\n        {\n          cookie: 'name1=value1',\n          Cookie: 'name2=value2',\n        },\n      ],\n      `NullableHeaders { 'cookie': 'name2=value2' }`,\n    ],\n    [\n      [\n        {\n          cookie: 'name1=value1',\n          Cookie: undefined,\n        },\n      ],\n      `NullableHeaders { 'cookie': 'name1=value1' }`,\n    ],\n    [\n      [\n        {\n          cookie: ['name1=value1', 'name2=value2'],\n        },\n      ],\n      `NullableHeaders { 'cookie': 'name1=value1; name2=value2' }`,\n    ],\n    [\n      [\n        {\n          'x-foo': ['name1=value1', 'name2=value2'],\n        },\n      ],\n      `NullableHeaders { 'x-foo': 'name1=value1, name2=value2' }`,\n    ],\n    [\n      [\n        [\n          ['cookie', 'name1=value1'],\n          ['cookie', 'name2=value2'],\n          ['Cookie', 'name3=value3'],\n        ],\n      ],\n      `NullableHeaders { 'cookie': 'name1=value1; name2=value2; name3=value3' }`,\n    ],\n    [[undefined], `NullableHeaders { }`],\n    [[null], `NullableHeaders { }`],\n  ];\n  for (const [input, expected] of cases) {\n    test(expected, () => {\n      expect(inspectNullableHeaders(buildHeaders(input))).toEqual(expected);\n    });\n  }\n});\n"
  },
  {
    "path": "tests/form.test.ts",
    "content": "import { multipartFormRequestOptions, createForm } from 'openai/internal/uploads';\nimport { toFile } from 'openai/core/uploads';\n\ndescribe('form data validation', () => {\n  test('valid values do not error', async () => {\n    await multipartFormRequestOptions(\n      {\n        body: {\n          foo: 'foo',\n          string: 1,\n          bool: true,\n          file: await toFile(Buffer.from('some-content')),\n          blob: new Blob(['Some content'], { type: 'text/plain' }),\n        },\n      },\n      fetch,\n    );\n  });\n\n  test('null', async () => {\n    await expect(() =>\n      multipartFormRequestOptions(\n        {\n          body: {\n            null: null,\n          },\n        },\n        fetch,\n      ),\n    ).rejects.toThrow(TypeError);\n  });\n\n  test('undefined is stripped', async () => {\n    const form = await createForm(\n      {\n        foo: undefined,\n        bar: 'baz',\n      },\n      fetch,\n    );\n    expect(form.has('foo')).toBe(false);\n    expect(form.get('bar')).toBe('baz');\n  });\n\n  test('nested undefined property is stripped', async () => {\n    const form = await createForm(\n      {\n        bar: {\n          baz: undefined,\n        },\n      },\n      fetch,\n    );\n    expect(Array.from(form.entries())).toEqual([]);\n\n    const form2 = await createForm(\n      {\n        bar: {\n          foo: 'string',\n          baz: undefined,\n        },\n      },\n      fetch,\n    );\n    expect(Array.from(form2.entries())).toEqual([['bar[foo]', 'string']]);\n  });\n\n  test('nested undefined array item is stripped', async () => {\n    const form = await createForm(\n      {\n        bar: [undefined, undefined],\n      },\n      fetch,\n    );\n    expect(Array.from(form.entries())).toEqual([]);\n\n    const form2 = await createForm(\n      {\n        bar: [undefined, 'foo'],\n      },\n      fetch,\n    );\n    expect(Array.from(form2.entries())).toEqual([['bar[]', 'foo']]);\n  });\n});\n"
  },
  {
    "path": "tests/helpers/zod.test.ts",
    "content": "import { zodResponseFormat } from 'openai/helpers/zod';\nimport { z as zv3 } from 'zod/v3';\nimport { z as zv4 } from 'zod/v4';\n\ndescribe.each([\n  { version: 'v3', z: zv3 },\n  { version: 'v4', z: zv4 as any as typeof zv3 },\n])('zodResponseFormat (Zod $version)', ({ version, z }) => {\n  it('does the thing', () => {\n    expect(\n      zodResponseFormat(\n        z.object({\n          city: z.string(),\n          temperature: z.number(),\n          units: z.enum(['c', 'f']),\n        }),\n        'location',\n      ).json_schema,\n    ).toMatchInlineSnapshot(`\n      {\n        \"name\": \"location\",\n        \"schema\": {\n          \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n          \"additionalProperties\": false,\n          \"properties\": {\n            \"city\": {\n              \"type\": \"string\",\n            },\n            \"temperature\": {\n              \"type\": \"number\",\n            },\n            \"units\": {\n              \"enum\": [\n                \"c\",\n                \"f\",\n              ],\n              \"type\": \"string\",\n            },\n          },\n          \"required\": [\n            \"city\",\n            \"temperature\",\n            \"units\",\n          ],\n          \"type\": \"object\",\n        },\n        \"strict\": true,\n      }\n    `);\n  });\n\n  it('automatically adds optional properties to `required`', () => {\n    expect(\n      zodResponseFormat(\n        z.object({\n          city: z.string(),\n          temperature: z.number(),\n          units: z.enum(['c', 'f']).optional().nullable(),\n        }),\n        'location',\n      ).json_schema,\n    ).toMatchInlineSnapshot(`\n      {\n        \"name\": \"location\",\n        \"schema\": {\n          \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n          \"additionalProperties\": false,\n          \"properties\": {\n            \"city\": {\n              \"type\": \"string\",\n            },\n            \"temperature\": {\n              \"type\": \"number\",\n            },\n            \"units\": {\n              \"anyOf\": [\n                {\n                  \"enum\": [\n                    \"c\",\n                    \"f\",\n                  ],\n                  \"type\": \"string\",\n                },\n                {\n                  \"type\": \"null\",\n                },\n              ],\n            },\n          },\n          \"required\": [\n            \"city\",\n            \"temperature\",\n            \"units\",\n          ],\n          \"type\": \"object\",\n        },\n        \"strict\": true,\n      }\n    `);\n  });\n\n  it('automatically adds properties with defaults to `required`', () => {\n    expect(\n      zodResponseFormat(\n        z.object({\n          city: z.string(),\n          temperature: z.number(),\n          units: z.enum(['c', 'f']).default('c'),\n        }),\n        'location',\n      ).json_schema,\n    ).toMatchInlineSnapshot(`\n      {\n        \"name\": \"location\",\n        \"schema\": {\n          \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n          \"additionalProperties\": false,\n          \"properties\": {\n            \"city\": {\n              \"type\": \"string\",\n            },\n            \"temperature\": {\n              \"type\": \"number\",\n            },\n            \"units\": {\n              \"default\": \"c\",\n              \"enum\": [\n                \"c\",\n                \"f\",\n              ],\n              \"type\": \"string\",\n            },\n          },\n          \"required\": [\n            \"city\",\n            \"temperature\",\n            \"units\",\n          ],\n          \"type\": \"object\",\n        },\n        \"strict\": true,\n      }\n    `);\n  });\n\n  it('allows description field to be passed in', () => {\n    expect(\n      zodResponseFormat(\n        z.object({\n          city: z.string(),\n        }),\n        'city',\n        { description: 'A city' },\n      ).json_schema,\n    ).toHaveProperty('description', 'A city');\n  });\n\n  test('kitchen sink types', () => {\n    const Table = z.enum(['orders', 'customers', 'products']);\n\n    const Column = z.enum([\n      'id',\n      'status',\n      'expected_delivery_date',\n      'delivered_at',\n      'shipped_at',\n      'ordered_at',\n      'canceled_at',\n    ]);\n\n    const Operator = z.enum(['=', '>', '<', '<=', '>=', '!=']);\n\n    const OrderBy = z.enum(['asc', 'desc']);\n\n    const DynamicValue = z.object({\n      column_name: z.string(),\n    });\n\n    const Condition = z.object({\n      column: z.string(),\n      operator: Operator,\n      value: z.union([z.string(), z.number(), DynamicValue]),\n    });\n\n    const Query = z.object({\n      table_name: Table,\n      columns: z.array(Column),\n      conditions: z.array(Condition),\n      order_by: OrderBy,\n    });\n\n    expect(zodResponseFormat(Query, 'query').json_schema).toMatchInlineSnapshot(`\n      {\n        \"name\": \"query\",\n        \"schema\": {\n          \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n          \"additionalProperties\": false,\n          \"properties\": {\n            \"columns\": {\n              \"items\": {\n                \"enum\": [\n                  \"id\",\n                  \"status\",\n                  \"expected_delivery_date\",\n                  \"delivered_at\",\n                  \"shipped_at\",\n                  \"ordered_at\",\n                  \"canceled_at\",\n                ],\n                \"type\": \"string\",\n              },\n              \"type\": \"array\",\n            },\n            \"conditions\": {\n              \"items\": {\n                \"additionalProperties\": false,\n                \"properties\": {\n                  \"column\": {\n                    \"type\": \"string\",\n                  },\n                  \"operator\": {\n                    \"enum\": [\n                      \"=\",\n                      \">\",\n                      \"<\",\n                      \"<=\",\n                      \">=\",\n                      \"!=\",\n                    ],\n                    \"type\": \"string\",\n                  },\n                  \"value\": {\n                    \"anyOf\": [\n                      {\n                        \"type\": \"string\",\n                      },\n                      {\n                        \"type\": \"number\",\n                      },\n                      {\n                        \"additionalProperties\": false,\n                        \"properties\": {\n                          \"column_name\": {\n                            \"type\": \"string\",\n                          },\n                        },\n                        \"required\": [\n                          \"column_name\",\n                        ],\n                        \"type\": \"object\",\n                      },\n                    ],\n                  },\n                },\n                \"required\": [\n                  \"column\",\n                  \"operator\",\n                  \"value\",\n                ],\n                \"type\": \"object\",\n              },\n              \"type\": \"array\",\n            },\n            \"order_by\": {\n              \"enum\": [\n                \"asc\",\n                \"desc\",\n              ],\n              \"type\": \"string\",\n            },\n            \"table_name\": {\n              \"enum\": [\n                \"orders\",\n                \"customers\",\n                \"products\",\n              ],\n              \"type\": \"string\",\n            },\n          },\n          \"required\": [\n            \"table_name\",\n            \"columns\",\n            \"conditions\",\n            \"order_by\",\n          ],\n          \"type\": \"object\",\n        },\n        \"strict\": true,\n      }\n    `);\n  });\n\n  it('throws error on optional fields', () => {\n    if (version === 'v3') {\n      expect(() =>\n        zodResponseFormat(\n          z.object({\n            required: z.string(),\n            optional: z.string().optional(),\n            optional_and_nullable: z.string().optional().nullable(),\n          }),\n          'schema',\n        ),\n      ).toThrowErrorMatchingInlineSnapshot(\n        `\"Zod field at \\`#/definitions/schema/properties/optional\\` uses \\`.optional()\\` without \\`.nullable()\\` which is not supported by the API. See: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required\"`,\n      );\n    } else {\n      expect(() =>\n        zodResponseFormat(\n          z.object({\n            required: z.string(),\n            optional: z.string().optional(),\n            optional_and_nullable: z.string().optional().nullable(),\n          }),\n          'schema',\n        ),\n      ).toThrowErrorMatchingInlineSnapshot(\n        `\"Zod field at \\`properties/optional\\` uses \\`.optional()\\` without \\`.nullable()\\` which is not supported by the API. See: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required\"`,\n      );\n    }\n  });\n\n  it('throws error on nested optional fields', () => {\n    if (version === 'v3') {\n      expect(() =>\n        zodResponseFormat(\n          z.object({\n            foo: z.object({ bar: z.array(z.object({ can_be_missing: z.boolean().optional() })) }),\n          }),\n          'schema',\n        ),\n      ).toThrowErrorMatchingInlineSnapshot(\n        `\"Zod field at \\`#/definitions/schema/properties/foo/properties/bar/items/properties/can_be_missing\\` uses \\`.optional()\\` without \\`.nullable()\\` which is not supported by the API. See: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required\"`,\n      );\n    } else {\n      expect(() =>\n        zodResponseFormat(\n          z.object({\n            foo: z.object({ bar: z.array(z.object({ can_be_missing: z.boolean().optional() })) }),\n          }),\n          'schema',\n        ),\n      ).toThrowErrorMatchingInlineSnapshot(\n        `\"Zod field at \\`properties/foo/properties/bar/items/properties/can_be_missing\\` uses \\`.optional()\\` without \\`.nullable()\\` which is not supported by the API. See: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required\"`,\n      );\n    }\n  });\n\n  it('does not warn on union nullable fields', () => {\n    const consoleSpy = jest.spyOn(console, 'warn');\n    consoleSpy.mockClear();\n\n    zodResponseFormat(\n      z.object({\n        union: z.union([z.string(), z.null()]).optional(),\n      }),\n      'schema',\n    );\n\n    expect(consoleSpy).toHaveBeenCalledTimes(0);\n  });\n});\n"
  },
  {
    "path": "tests/index.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIPromise } from 'openai/core/api-promise';\n\nimport util from 'node:util';\nimport OpenAI from 'openai';\nimport { APIUserAbortError } from 'openai';\nconst defaultFetch = fetch;\n\ndescribe('instantiate client', () => {\n  const env = process.env;\n\n  beforeEach(() => {\n    jest.resetModules();\n    process.env = { ...env };\n  });\n\n  afterEach(() => {\n    process.env = env;\n  });\n\n  describe('defaultHeaders', () => {\n    const client = new OpenAI({\n      baseURL: 'http://localhost:5000/',\n      defaultHeaders: { 'X-My-Default-Header': '2' },\n      apiKey: 'My API Key',\n    });\n\n    test('they are used in the request', async () => {\n      const { req } = await client.buildRequest({ path: '/foo', method: 'post' });\n      expect(req.headers.get('x-my-default-header')).toEqual('2');\n    });\n\n    test('can ignore `undefined` and leave the default', async () => {\n      const { req } = await client.buildRequest({\n        path: '/foo',\n        method: 'post',\n        headers: { 'X-My-Default-Header': undefined },\n      });\n      expect(req.headers.get('x-my-default-header')).toEqual('2');\n    });\n\n    test('can be removed with `null`', async () => {\n      const { req } = await client.buildRequest({\n        path: '/foo',\n        method: 'post',\n        headers: { 'X-My-Default-Header': null },\n      });\n      expect(req.headers.has('x-my-default-header')).toBe(false);\n    });\n  });\n  describe('logging', () => {\n    const env = process.env;\n\n    beforeEach(() => {\n      process.env = { ...env };\n      process.env['OPENAI_LOG'] = undefined;\n    });\n\n    afterEach(() => {\n      process.env = env;\n    });\n\n    const forceAPIResponseForClient = async (client: OpenAI) => {\n      await new APIPromise(\n        client,\n        Promise.resolve({\n          response: new Response(),\n          controller: new AbortController(),\n          requestLogID: 'log_000000',\n          retryOfRequestLogID: undefined,\n          startTime: Date.now(),\n          options: {\n            method: 'get',\n            path: '/',\n          },\n        }),\n      );\n    };\n\n    test('debug logs when log level is debug', async () => {\n      const debugMock = jest.fn();\n      const logger = {\n        debug: debugMock,\n        info: jest.fn(),\n        warn: jest.fn(),\n        error: jest.fn(),\n      };\n\n      const client = new OpenAI({\n        logger: logger,\n        logLevel: 'debug',\n        apiKey: 'My API Key',\n      });\n\n      await forceAPIResponseForClient(client);\n      expect(debugMock).toHaveBeenCalled();\n    });\n\n    test('default logLevel is warn', async () => {\n      const client = new OpenAI({ apiKey: 'My API Key' });\n      expect(client.logLevel).toBe('warn');\n    });\n\n    test('debug logs are skipped when log level is info', async () => {\n      const debugMock = jest.fn();\n      const logger = {\n        debug: debugMock,\n        info: jest.fn(),\n        warn: jest.fn(),\n        error: jest.fn(),\n      };\n\n      const client = new OpenAI({\n        logger: logger,\n        logLevel: 'info',\n        apiKey: 'My API Key',\n      });\n\n      await forceAPIResponseForClient(client);\n      expect(debugMock).not.toHaveBeenCalled();\n    });\n\n    test('debug logs happen with debug env var', async () => {\n      const debugMock = jest.fn();\n      const logger = {\n        debug: debugMock,\n        info: jest.fn(),\n        warn: jest.fn(),\n        error: jest.fn(),\n      };\n\n      process.env['OPENAI_LOG'] = 'debug';\n      const client = new OpenAI({ logger: logger, apiKey: 'My API Key' });\n      expect(client.logLevel).toBe('debug');\n\n      await forceAPIResponseForClient(client);\n      expect(debugMock).toHaveBeenCalled();\n    });\n\n    test('warn when env var level is invalid', async () => {\n      const warnMock = jest.fn();\n      const logger = {\n        debug: jest.fn(),\n        info: jest.fn(),\n        warn: warnMock,\n        error: jest.fn(),\n      };\n\n      process.env['OPENAI_LOG'] = 'not a log level';\n      const client = new OpenAI({ logger: logger, apiKey: 'My API Key' });\n      expect(client.logLevel).toBe('warn');\n      expect(warnMock).toHaveBeenCalledWith(\n        'process.env[\\'OPENAI_LOG\\'] was set to \"not a log level\", expected one of [\"off\",\"error\",\"warn\",\"info\",\"debug\"]',\n      );\n    });\n\n    test('client log level overrides env var', async () => {\n      const debugMock = jest.fn();\n      const logger = {\n        debug: debugMock,\n        info: jest.fn(),\n        warn: jest.fn(),\n        error: jest.fn(),\n      };\n\n      process.env['OPENAI_LOG'] = 'debug';\n      const client = new OpenAI({\n        logger: logger,\n        logLevel: 'off',\n        apiKey: 'My API Key',\n      });\n\n      await forceAPIResponseForClient(client);\n      expect(debugMock).not.toHaveBeenCalled();\n    });\n\n    test('no warning logged for invalid env var level + valid client level', async () => {\n      const warnMock = jest.fn();\n      const logger = {\n        debug: jest.fn(),\n        info: jest.fn(),\n        warn: warnMock,\n        error: jest.fn(),\n      };\n\n      process.env['OPENAI_LOG'] = 'not a log level';\n      const client = new OpenAI({\n        logger: logger,\n        logLevel: 'debug',\n        apiKey: 'My API Key',\n      });\n      expect(client.logLevel).toBe('debug');\n      expect(warnMock).not.toHaveBeenCalled();\n    });\n  });\n\n  describe('defaultQuery', () => {\n    test('with null query params given', () => {\n      const client = new OpenAI({\n        baseURL: 'http://localhost:5000/',\n        defaultQuery: { apiVersion: 'foo' },\n        apiKey: 'My API Key',\n      });\n      expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/foo?apiVersion=foo');\n    });\n\n    test('multiple default query params', () => {\n      const client = new OpenAI({\n        baseURL: 'http://localhost:5000/',\n        defaultQuery: { apiVersion: 'foo', hello: 'world' },\n        apiKey: 'My API Key',\n      });\n      expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/foo?apiVersion=foo&hello=world');\n    });\n\n    test('overriding with `undefined`', () => {\n      const client = new OpenAI({\n        baseURL: 'http://localhost:5000/',\n        defaultQuery: { hello: 'world' },\n        apiKey: 'My API Key',\n      });\n      expect(client.buildURL('/foo', { hello: undefined })).toEqual('http://localhost:5000/foo');\n    });\n  });\n\n  test('custom fetch', async () => {\n    const client = new OpenAI({\n      baseURL: 'http://localhost:5000/',\n      apiKey: 'My API Key',\n      fetch: (url) => {\n        return Promise.resolve(\n          new Response(JSON.stringify({ url, custom: true }), {\n            headers: { 'Content-Type': 'application/json' },\n          }),\n        );\n      },\n    });\n\n    const response = await client.get('/foo');\n    expect(response).toEqual({ url: 'http://localhost:5000/foo', custom: true });\n  });\n\n  test('explicit global fetch', async () => {\n    // make sure the global fetch type is assignable to our Fetch type\n    const client = new OpenAI({\n      baseURL: 'http://localhost:5000/',\n      apiKey: 'My API Key',\n      fetch: defaultFetch,\n    });\n  });\n\n  test('custom signal', async () => {\n    const client = new OpenAI({\n      baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n      apiKey: 'My API Key',\n      fetch: (...args) => {\n        return new Promise((resolve, reject) =>\n          setTimeout(\n            () =>\n              defaultFetch(...args)\n                .then(resolve)\n                .catch(reject),\n            300,\n          ),\n        );\n      },\n    });\n\n    const controller = new AbortController();\n    setTimeout(() => controller.abort(), 200);\n\n    const spy = jest.spyOn(client, 'request');\n\n    await expect(client.get('/foo', { signal: controller.signal })).rejects.toThrowError(APIUserAbortError);\n    expect(spy).toHaveBeenCalledTimes(1);\n  });\n\n  test('normalized method', async () => {\n    let capturedRequest: RequestInit | undefined;\n    const testFetch = async (url: string | URL | Request, init: RequestInit = {}): Promise<Response> => {\n      capturedRequest = init;\n      return new Response(JSON.stringify({}), { headers: { 'Content-Type': 'application/json' } });\n    };\n\n    const client = new OpenAI({\n      baseURL: 'http://localhost:5000/',\n      apiKey: 'My API Key',\n      fetch: testFetch,\n    });\n\n    await client.patch('/foo');\n    expect(capturedRequest?.method).toEqual('PATCH');\n  });\n\n  describe('baseUrl', () => {\n    test('trailing slash', () => {\n      const client = new OpenAI({ baseURL: 'http://localhost:5000/custom/path/', apiKey: 'My API Key' });\n      expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/custom/path/foo');\n    });\n\n    test('no trailing slash', () => {\n      const client = new OpenAI({ baseURL: 'http://localhost:5000/custom/path', apiKey: 'My API Key' });\n      expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/custom/path/foo');\n    });\n\n    afterEach(() => {\n      process.env['OPENAI_BASE_URL'] = undefined;\n    });\n\n    test('explicit option', () => {\n      const client = new OpenAI({ baseURL: 'https://example.com', apiKey: 'My API Key' });\n      expect(client.baseURL).toEqual('https://example.com');\n    });\n\n    test('env variable', () => {\n      process.env['OPENAI_BASE_URL'] = 'https://example.com/from_env';\n      const client = new OpenAI({ apiKey: 'My API Key' });\n      expect(client.baseURL).toEqual('https://example.com/from_env');\n    });\n\n    test('empty env variable', () => {\n      process.env['OPENAI_BASE_URL'] = ''; // empty\n      const client = new OpenAI({ apiKey: 'My API Key' });\n      expect(client.baseURL).toEqual('https://api.openai.com/v1');\n    });\n\n    test('blank env variable', () => {\n      process.env['OPENAI_BASE_URL'] = '  '; // blank\n      const client = new OpenAI({ apiKey: 'My API Key' });\n      expect(client.baseURL).toEqual('https://api.openai.com/v1');\n    });\n\n    test('in request options', () => {\n      const client = new OpenAI({ apiKey: 'My API Key' });\n      expect(client.buildURL('/foo', null, 'http://localhost:5000/option')).toEqual(\n        'http://localhost:5000/option/foo',\n      );\n    });\n\n    test('in request options overridden by client options', () => {\n      const client = new OpenAI({ apiKey: 'My API Key', baseURL: 'http://localhost:5000/client' });\n      expect(client.buildURL('/foo', null, 'http://localhost:5000/option')).toEqual(\n        'http://localhost:5000/client/foo',\n      );\n    });\n\n    test('in request options overridden by env variable', () => {\n      process.env['OPENAI_BASE_URL'] = 'http://localhost:5000/env';\n      const client = new OpenAI({ apiKey: 'My API Key' });\n      expect(client.buildURL('/foo', null, 'http://localhost:5000/option')).toEqual(\n        'http://localhost:5000/env/foo',\n      );\n    });\n  });\n\n  test('maxRetries option is correctly set', () => {\n    const client = new OpenAI({ maxRetries: 4, apiKey: 'My API Key' });\n    expect(client.maxRetries).toEqual(4);\n\n    // default\n    const client2 = new OpenAI({ apiKey: 'My API Key' });\n    expect(client2.maxRetries).toEqual(2);\n  });\n\n  describe('withOptions', () => {\n    test('creates a new client with overridden options', async () => {\n      const client = new OpenAI({\n        baseURL: 'http://localhost:5000/',\n        maxRetries: 3,\n        apiKey: 'My API Key',\n      });\n\n      const newClient = client.withOptions({\n        maxRetries: 5,\n        baseURL: 'http://localhost:5001/',\n      });\n\n      // Verify the new client has updated options\n      expect(newClient.maxRetries).toEqual(5);\n      expect(newClient.baseURL).toEqual('http://localhost:5001/');\n\n      // Verify the original client is unchanged\n      expect(client.maxRetries).toEqual(3);\n      expect(client.baseURL).toEqual('http://localhost:5000/');\n\n      // Verify it's a different instance\n      expect(newClient).not.toBe(client);\n      expect(newClient.constructor).toBe(client.constructor);\n    });\n\n    test('inherits options from the parent client', async () => {\n      const client = new OpenAI({\n        baseURL: 'http://localhost:5000/',\n        defaultHeaders: { 'X-Test-Header': 'test-value' },\n        defaultQuery: { 'test-param': 'test-value' },\n        apiKey: 'My API Key',\n      });\n\n      const newClient = client.withOptions({\n        baseURL: 'http://localhost:5001/',\n      });\n\n      // Test inherited options remain the same\n      expect(newClient.buildURL('/foo', null)).toEqual('http://localhost:5001/foo?test-param=test-value');\n\n      const { req } = await newClient.buildRequest({ path: '/foo', method: 'get' });\n      expect(req.headers.get('x-test-header')).toEqual('test-value');\n    });\n\n    test('respects runtime property changes when creating new client', () => {\n      const client = new OpenAI({\n        baseURL: 'http://localhost:5000/',\n        timeout: 1000,\n        apiKey: 'My API Key',\n      });\n\n      // Modify the client properties directly after creation\n      client.baseURL = 'http://localhost:6000/';\n      client.timeout = 2000;\n\n      // Create a new client with withOptions\n      const newClient = client.withOptions({\n        maxRetries: 10,\n      });\n\n      // Verify the new client uses the updated properties, not the original ones\n      expect(newClient.baseURL).toEqual('http://localhost:6000/');\n      expect(newClient.timeout).toEqual(2000);\n      expect(newClient.maxRetries).toEqual(10);\n\n      // Original client should still have its modified properties\n      expect(client.baseURL).toEqual('http://localhost:6000/');\n      expect(client.timeout).toEqual(2000);\n      expect(client.maxRetries).not.toEqual(10);\n\n      // Verify URL building uses the updated baseURL\n      expect(newClient.buildURL('/bar', null)).toEqual('http://localhost:6000/bar');\n    });\n  });\n\n  test('with environment variable arguments', () => {\n    // set options via env var\n    process.env['OPENAI_API_KEY'] = 'My API Key';\n    const client = new OpenAI();\n    expect(client.apiKey).toBe('My API Key');\n  });\n\n  test('with overridden environment variable arguments', () => {\n    // set options via env var\n    process.env['OPENAI_API_KEY'] = 'another My API Key';\n    const client = new OpenAI({ apiKey: 'My API Key' });\n    expect(client.apiKey).toBe('My API Key');\n  });\n});\n\ndescribe('request building', () => {\n  const client = new OpenAI({ apiKey: 'My API Key' });\n\n  describe('custom headers', () => {\n    test('handles undefined', async () => {\n      const { req } = await client.buildRequest({\n        path: '/foo',\n        method: 'post',\n        body: { value: 'hello' },\n        headers: { 'X-Foo': 'baz', 'x-foo': 'bar', 'x-Foo': undefined, 'x-baz': 'bam', 'X-Baz': null },\n      });\n      expect(req.headers.get('x-foo')).toEqual('bar');\n      expect(req.headers.get('x-Foo')).toEqual('bar');\n      expect(req.headers.get('X-Foo')).toEqual('bar');\n      expect(req.headers.get('x-baz')).toEqual(null);\n    });\n  });\n});\n\ndescribe('default encoder', () => {\n  const client = new OpenAI({ apiKey: 'My API Key' });\n\n  class Serializable {\n    toJSON() {\n      return { $type: 'Serializable' };\n    }\n  }\n  class Collection<T> {\n    #things: T[];\n    constructor(things: T[]) {\n      this.#things = Array.from(things);\n    }\n    toJSON() {\n      return Array.from(this.#things);\n    }\n    [Symbol.iterator]() {\n      return this.#things[Symbol.iterator];\n    }\n  }\n  for (const jsonValue of [{}, [], { __proto__: null }, new Serializable(), new Collection(['item'])]) {\n    test(`serializes ${util.inspect(jsonValue)} as json`, async () => {\n      const { req } = await client.buildRequest({\n        path: '/foo',\n        method: 'post',\n        body: jsonValue,\n      });\n      expect(req.headers).toBeInstanceOf(Headers);\n      expect(req.headers.get('content-type')).toEqual('application/json');\n      expect(req.body).toBe(JSON.stringify(jsonValue));\n    });\n  }\n\n  const encoder = new TextEncoder();\n  const asyncIterable = (async function* () {\n    yield encoder.encode('a\\n');\n    yield encoder.encode('b\\n');\n    yield encoder.encode('c\\n');\n  })();\n  for (const streamValue of [\n    [encoder.encode('a\\nb\\nc\\n')][Symbol.iterator](),\n    new Response('a\\nb\\nc\\n').body,\n    asyncIterable,\n  ]) {\n    test(`converts ${util.inspect(streamValue)} to ReadableStream`, async () => {\n      const { req } = await client.buildRequest({\n        path: '/foo',\n        method: 'post',\n        body: streamValue,\n      });\n      expect(req.headers).toBeInstanceOf(Headers);\n      expect(req.headers.get('content-type')).toEqual(null);\n      expect(req.body).toBeInstanceOf(ReadableStream);\n      expect(await new Response(req.body).text()).toBe('a\\nb\\nc\\n');\n    });\n  }\n\n  test(`can set content-type for ReadableStream`, async () => {\n    const { req } = await client.buildRequest({\n      path: '/foo',\n      method: 'post',\n      body: new Response('a\\nb\\nc\\n').body,\n      headers: { 'Content-Type': 'text/plain' },\n    });\n    expect(req.headers).toBeInstanceOf(Headers);\n    expect(req.headers.get('content-type')).toEqual('text/plain');\n    expect(req.body).toBeInstanceOf(ReadableStream);\n    expect(await new Response(req.body).text()).toBe('a\\nb\\nc\\n');\n  });\n});\n\ndescribe('retries', () => {\n  test('retry on timeout', async () => {\n    let count = 0;\n    const testFetch = async (\n      url: string | URL | Request,\n      { signal }: RequestInit = {},\n    ): Promise<Response> => {\n      if (count++ === 0) {\n        return new Promise(\n          (resolve, reject) => signal?.addEventListener('abort', () => reject(new Error('timed out'))),\n        );\n      }\n      return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });\n    };\n\n    const client = new OpenAI({\n      apiKey: 'My API Key',\n      timeout: 10,\n      fetch: testFetch,\n    });\n\n    expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });\n    expect(count).toEqual(2);\n    expect(\n      await client\n        .request({ path: '/foo', method: 'get' })\n        .asResponse()\n        .then((r) => r.text()),\n    ).toEqual(JSON.stringify({ a: 1 }));\n    expect(count).toEqual(3);\n  });\n\n  test('retry count header', async () => {\n    let count = 0;\n    let capturedRequest: RequestInit | undefined;\n    const testFetch = async (url: string | URL | Request, init: RequestInit = {}): Promise<Response> => {\n      count++;\n      if (count <= 2) {\n        return new Response(undefined, {\n          status: 429,\n          headers: {\n            'Retry-After': '0.1',\n          },\n        });\n      }\n      capturedRequest = init;\n      return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });\n    };\n\n    const client = new OpenAI({\n      apiKey: 'My API Key',\n      fetch: testFetch,\n      maxRetries: 4,\n    });\n\n    expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });\n\n    expect((capturedRequest!.headers as Headers).get('x-stainless-retry-count')).toEqual('2');\n    expect(count).toEqual(3);\n  });\n\n  test('omit retry count header', async () => {\n    let count = 0;\n    let capturedRequest: RequestInit | undefined;\n    const testFetch = async (url: string | URL | Request, init: RequestInit = {}): Promise<Response> => {\n      count++;\n      if (count <= 2) {\n        return new Response(undefined, {\n          status: 429,\n          headers: {\n            'Retry-After': '0.1',\n          },\n        });\n      }\n      capturedRequest = init;\n      return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });\n    };\n    const client = new OpenAI({\n      apiKey: 'My API Key',\n      fetch: testFetch,\n      maxRetries: 4,\n    });\n\n    expect(\n      await client.request({\n        path: '/foo',\n        method: 'get',\n        headers: { 'X-Stainless-Retry-Count': null },\n      }),\n    ).toEqual({ a: 1 });\n\n    expect((capturedRequest!.headers as Headers).has('x-stainless-retry-count')).toBe(false);\n  });\n\n  test('omit retry count header by default', async () => {\n    let count = 0;\n    let capturedRequest: RequestInit | undefined;\n    const testFetch = async (url: string | URL | Request, init: RequestInit = {}): Promise<Response> => {\n      count++;\n      if (count <= 2) {\n        return new Response(undefined, {\n          status: 429,\n          headers: {\n            'Retry-After': '0.1',\n          },\n        });\n      }\n      capturedRequest = init;\n      return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });\n    };\n    const client = new OpenAI({\n      apiKey: 'My API Key',\n      fetch: testFetch,\n      maxRetries: 4,\n      defaultHeaders: { 'X-Stainless-Retry-Count': null },\n    });\n\n    expect(\n      await client.request({\n        path: '/foo',\n        method: 'get',\n      }),\n    ).toEqual({ a: 1 });\n\n    expect(capturedRequest!.headers as Headers).not.toHaveProperty('x-stainless-retry-count');\n  });\n\n  test('overwrite retry count header', async () => {\n    let count = 0;\n    let capturedRequest: RequestInit | undefined;\n    const testFetch = async (url: string | URL | Request, init: RequestInit = {}): Promise<Response> => {\n      count++;\n      if (count <= 2) {\n        return new Response(undefined, {\n          status: 429,\n          headers: {\n            'Retry-After': '0.1',\n          },\n        });\n      }\n      capturedRequest = init;\n      return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });\n    };\n    const client = new OpenAI({\n      apiKey: 'My API Key',\n      fetch: testFetch,\n      maxRetries: 4,\n    });\n\n    expect(\n      await client.request({\n        path: '/foo',\n        method: 'get',\n        headers: { 'X-Stainless-Retry-Count': '42' },\n      }),\n    ).toEqual({ a: 1 });\n\n    expect((capturedRequest!.headers as Headers).get('x-stainless-retry-count')).toEqual('42');\n  });\n\n  test('retry on 429 with retry-after', async () => {\n    let count = 0;\n    const testFetch = async (\n      url: string | URL | Request,\n      { signal }: RequestInit = {},\n    ): Promise<Response> => {\n      if (count++ === 0) {\n        return new Response(undefined, {\n          status: 429,\n          headers: {\n            'Retry-After': '0.1',\n          },\n        });\n      }\n      return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });\n    };\n\n    const client = new OpenAI({ apiKey: 'My API Key', fetch: testFetch });\n\n    expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });\n    expect(count).toEqual(2);\n    expect(\n      await client\n        .request({ path: '/foo', method: 'get' })\n        .asResponse()\n        .then((r) => r.text()),\n    ).toEqual(JSON.stringify({ a: 1 }));\n    expect(count).toEqual(3);\n  });\n\n  test('retry on 429 with retry-after-ms', async () => {\n    let count = 0;\n    const testFetch = async (\n      url: string | URL | Request,\n      { signal }: RequestInit = {},\n    ): Promise<Response> => {\n      if (count++ === 0) {\n        return new Response(undefined, {\n          status: 429,\n          headers: {\n            'Retry-After-Ms': '10',\n          },\n        });\n      }\n      return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });\n    };\n\n    const client = new OpenAI({ apiKey: 'My API Key', fetch: testFetch });\n\n    expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });\n    expect(count).toEqual(2);\n    expect(\n      await client\n        .request({ path: '/foo', method: 'get' })\n        .asResponse()\n        .then((r) => r.text()),\n    ).toEqual(JSON.stringify({ a: 1 }));\n    expect(count).toEqual(3);\n  });\n\n  describe('auth', () => {\n    test('apiKey', async () => {\n      const client = new OpenAI({\n        baseURL: 'http://localhost:5000/',\n        apiKey: 'My API Key',\n      });\n      const { req } = await client.buildRequest({ path: '/foo', method: 'get' });\n      expect(req.headers.get('authorization')).toEqual('Bearer My API Key');\n    });\n\n    test('token', async () => {\n      const testFetch = async (url: any, { headers }: RequestInit = {}): Promise<Response> => {\n        return new Response(JSON.stringify({}), { headers: headers ?? [] });\n      };\n      const client = new OpenAI({\n        baseURL: 'http://localhost:5000/',\n        apiKey: async () => 'my token',\n        fetch: testFetch,\n      });\n      expect(\n        (await client.request({ method: 'post', path: 'https://example.com' }).asResponse()).headers.get(\n          'authorization',\n        ),\n      ).toEqual('Bearer my token');\n    });\n\n    test('token is refreshed', async () => {\n      let fail = true;\n      const testFetch = async (url: any, { headers }: RequestInit = {}): Promise<Response> => {\n        if (fail) {\n          fail = false;\n          return new Response(undefined, {\n            status: 429,\n            headers: {\n              'Retry-After': '0.1',\n            },\n          });\n        }\n        return new Response(JSON.stringify({}), {\n          headers: headers ?? [],\n        });\n      };\n      let counter = 0;\n      async function apiKey() {\n        return `token-${counter++}`;\n      }\n      const client = new OpenAI({\n        baseURL: 'http://localhost:5000/',\n        apiKey,\n        fetch: testFetch,\n      });\n      expect(\n        (\n          await client.chat.completions\n            .create({\n              model: '',\n              messages: [{ role: 'system', content: 'Hello' }],\n            })\n            .asResponse()\n        ).headers.get('authorization'),\n      ).toEqual('Bearer token-1');\n    });\n\n    test('at least one', () => {\n      try {\n        new OpenAI({\n          baseURL: 'http://localhost:5000/',\n        });\n      } catch (error: any) {\n        expect(error).toBeInstanceOf(Error);\n        expect(error.message).toEqual(\n          'Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.',\n        );\n      }\n    });\n  });\n});\n"
  },
  {
    "path": "tests/internal/decoders/line.test.ts",
    "content": "import { findDoubleNewlineIndex, LineDecoder } from 'openai/internal/decoders/line';\n\nfunction decodeChunks(chunks: string[], { flush }: { flush: boolean } = { flush: false }): string[] {\n  const decoder = new LineDecoder();\n  const lines: string[] = [];\n  for (const chunk of chunks) {\n    lines.push(...decoder.decode(chunk));\n  }\n\n  if (flush) {\n    lines.push(...decoder.flush());\n  }\n\n  return lines;\n}\n\ndescribe('line decoder', () => {\n  test('basic', () => {\n    // baz is not included because the line hasn't ended yet\n    expect(decodeChunks(['foo', ' bar\\nbaz'])).toEqual(['foo bar']);\n  });\n\n  test('basic with \\\\r', () => {\n    expect(decodeChunks(['foo', ' bar\\r\\nbaz'])).toEqual(['foo bar']);\n    expect(decodeChunks(['foo', ' bar\\r\\nbaz'], { flush: true })).toEqual(['foo bar', 'baz']);\n  });\n\n  test('trailing new lines', () => {\n    expect(decodeChunks(['foo', ' bar', 'baz\\n', 'thing\\n'])).toEqual(['foo barbaz', 'thing']);\n  });\n\n  test('trailing new lines with \\\\r', () => {\n    expect(decodeChunks(['foo', ' bar', 'baz\\r\\n', 'thing\\r\\n'])).toEqual(['foo barbaz', 'thing']);\n  });\n\n  test('escaped new lines', () => {\n    expect(decodeChunks(['foo', ' bar\\\\nbaz\\n'])).toEqual(['foo bar\\\\nbaz']);\n  });\n\n  test('escaped new lines with \\\\r', () => {\n    expect(decodeChunks(['foo', ' bar\\\\r\\\\nbaz\\n'])).toEqual(['foo bar\\\\r\\\\nbaz']);\n  });\n\n  test('\\\\r & \\\\n split across multiple chunks', () => {\n    expect(decodeChunks(['foo\\r', '\\n', 'bar'], { flush: true })).toEqual(['foo', 'bar']);\n  });\n\n  test('single \\\\r', () => {\n    expect(decodeChunks(['foo\\r', 'bar'], { flush: true })).toEqual(['foo', 'bar']);\n  });\n\n  test('double \\\\r', () => {\n    expect(decodeChunks(['foo\\r', 'bar\\r'], { flush: true })).toEqual(['foo', 'bar']);\n    expect(decodeChunks(['foo\\r', '\\r', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);\n    // implementation detail that we don't yield the single \\r line until a new \\r or \\n is encountered\n    expect(decodeChunks(['foo\\r', '\\r', 'bar'], { flush: false })).toEqual(['foo']);\n  });\n\n  test('double \\\\r then \\\\r\\\\n', () => {\n    expect(decodeChunks(['foo\\r', '\\r', '\\r', '\\n', 'bar', '\\n'])).toEqual(['foo', '', '', 'bar']);\n    expect(decodeChunks(['foo\\n', '\\n', '\\n', 'bar', '\\n'])).toEqual(['foo', '', '', 'bar']);\n  });\n\n  test('double newline', () => {\n    expect(decodeChunks(['foo\\n\\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);\n    expect(decodeChunks(['foo', '\\n', '\\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);\n    expect(decodeChunks(['foo\\n', '\\n', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);\n    expect(decodeChunks(['foo', '\\n', '\\n', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);\n  });\n\n  test('multi-byte characters across chunks', () => {\n    const decoder = new LineDecoder();\n\n    // bytes taken from the string 'известни' and arbitrarily split\n    // so that some multi-byte characters span multiple chunks\n    expect(decoder.decode(new Uint8Array([0xd0]))).toHaveLength(0);\n    expect(decoder.decode(new Uint8Array([0xb8, 0xd0, 0xb7, 0xd0]))).toHaveLength(0);\n    expect(\n      decoder.decode(new Uint8Array([0xb2, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0xd0, 0xbd, 0xd0, 0xb8])),\n    ).toHaveLength(0);\n\n    const decoded = decoder.decode(new Uint8Array([0xa]));\n    expect(decoded).toEqual(['известни']);\n  });\n\n  test('flushing trailing newlines', () => {\n    expect(decodeChunks(['foo\\n', '\\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);\n  });\n\n  test('flushing empty buffer', () => {\n    expect(decodeChunks([], { flush: true })).toEqual([]);\n  });\n});\n\ndescribe('findDoubleNewlineIndex', () => {\n  test('finds \\\\n\\\\n', () => {\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\n\\nbar'))).toBe(5);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('\\n\\nbar'))).toBe(2);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\n\\n'))).toBe(5);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('\\n\\n'))).toBe(2);\n  });\n\n  test('finds \\\\r\\\\r', () => {\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\r\\rbar'))).toBe(5);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('\\r\\rbar'))).toBe(2);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\r\\r'))).toBe(5);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('\\r\\r'))).toBe(2);\n  });\n\n  test('finds \\\\r\\\\n\\\\r\\\\n', () => {\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\r\\n\\r\\nbar'))).toBe(7);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('\\r\\n\\r\\nbar'))).toBe(4);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\r\\n\\r\\n'))).toBe(7);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('\\r\\n\\r\\n'))).toBe(4);\n  });\n\n  test('returns -1 when no double newline found', () => {\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\nbar'))).toBe(-1);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\rbar'))).toBe(-1);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\r\\nbar'))).toBe(-1);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode(''))).toBe(-1);\n  });\n\n  test('handles incomplete patterns', () => {\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\r\\n\\r'))).toBe(-1);\n    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\\r\\n'))).toBe(-1);\n  });\n});\n"
  },
  {
    "path": "tests/lib/ChatCompletionRunFunctions.test.ts",
    "content": "import OpenAI from 'openai';\nimport { OpenAIError, APIConnectionError } from 'openai/error';\nimport { PassThrough } from 'stream';\nimport {\n  ParsingToolFunction,\n  type ChatCompletionRunner,\n  type ChatCompletionToolRunnerParams,\n  ChatCompletionStreamingRunner,\n  type ChatCompletionStreamingToolRunnerParams,\n} from 'openai/resources/chat/completions';\nimport type { ChatCompletionMessageParam } from 'openai/resources/chat/completions';\nimport { isAssistantMessage } from '../../src/lib/chatCompletionUtils';\nimport { mockFetch } from '../utils/mock-fetch';\n\n// mockChatCompletionFetch is like mockFetch, but with better a more convenient handleRequest to mock\n// chat completion request/responses.\nfunction mockChatCompletionFetch() {\n  const { fetch, handleRequest: handleRawRequest } = mockFetch();\n\n  function handleRequest(\n    handler: (body: ChatCompletionToolRunnerParams<any[]>) => Promise<OpenAI.Chat.ChatCompletion>,\n  ): Promise<void> {\n    return handleRawRequest(async (req, init) => {\n      const rawBody = init?.body;\n      if (typeof rawBody !== 'string') throw new Error(`expected init.body to be a string`);\n      const body: ChatCompletionToolRunnerParams<any[]> = JSON.parse(rawBody);\n      return new Response(JSON.stringify(await handler(body)), {\n        headers: { 'Content-Type': 'application/json' },\n      });\n    });\n  }\n  return { fetch, handleRequest };\n}\n\n// mockStreamingChatCompletionFetch is like mockFetch, but with better a more convenient handleRequest to mock\n// streaming chat completion request/responses.\nfunction mockStreamingChatCompletionFetch() {\n  const { fetch, handleRequest: handleRawRequest } = mockFetch();\n\n  function handleRequest(\n    handler: (\n      body: ChatCompletionStreamingToolRunnerParams<any[]>,\n    ) => AsyncIterable<OpenAI.Chat.ChatCompletionChunk>,\n  ): Promise<void> {\n    return handleRawRequest(async (req, init) => {\n      const rawBody = init?.body;\n      if (typeof rawBody !== 'string') throw new Error(`expected init.body to be a string`);\n      const body: ChatCompletionStreamingToolRunnerParams<any[]> = JSON.parse(rawBody);\n      const stream = new PassThrough();\n      (async () => {\n        for await (const chunk of handler(body)) {\n          stream.write(`data: ${JSON.stringify(chunk)}\\n\\n`);\n        }\n        stream.end(`data: [DONE]\\n\\n`);\n      })();\n      return new Response(stream, {\n        headers: {\n          'Content-Type': 'text/event-stream',\n          'Transfer-Encoding': 'chunked',\n        },\n      });\n    });\n  }\n  return { fetch, handleRequest };\n}\n\n// contentChoiceDeltas returns an async iterator which mocks a delta stream of a by splitting the\n// argument into chunks separated by whitespace.\nfunction* contentChoiceDeltas(\n  content: string,\n  {\n    index = 0,\n    role = 'assistant',\n  }: { index?: number; role?: NonNullable<OpenAI.Chat.ChatCompletionChunk.Choice.Delta['role']> } = {},\n): Iterable<OpenAI.Chat.Completions.ChatCompletionChunk.Choice> {\n  const deltas = content.split(/\\s+/g);\n  for (let i = 0; i < deltas.length; i++) {\n    yield {\n      index,\n      finish_reason: i === deltas.length - 1 ? 'stop' : null,\n      logprobs: null,\n      delta: {\n        role,\n        content: deltas[i] ? `${deltas[i]}${i === deltas.length - 1 ? '' : ' '}` : null,\n      },\n    };\n  }\n}\n\n// functionCallDeltas returns an async iterator which mocks a delta stream of a functionCall by splitting\n// the argument into chunks separated by whitespace.\nfunction* functionCallDeltas(\n  args: string,\n  {\n    index = 0,\n    id = '123',\n    name,\n    role = 'assistant',\n  }: {\n    name: string;\n    id?: string;\n    index?: number;\n    role?: NonNullable<OpenAI.Chat.ChatCompletionChunk.Choice.Delta['role']>;\n  },\n): Iterable<OpenAI.Chat.Completions.ChatCompletionChunk.Choice> {\n  const deltas = args.split(/\\s+/g);\n  for (let i = 0; i < deltas.length; i++) {\n    yield {\n      index,\n      finish_reason: i === deltas.length - 1 ? 'function_call' : null,\n      delta: {\n        role,\n        tool_calls: [\n          {\n            type: 'function',\n            index: 0,\n            id,\n            function: {\n              arguments: `${deltas[i] || ''}${i === deltas.length - 1 ? '' : ' '}`,\n              ...(i === deltas.length - 1 ? { name } : null),\n            },\n          },\n        ],\n      },\n    };\n  }\n}\n\nclass RunnerListener {\n  readonly contents: string[] = [];\n  readonly messages: ChatCompletionMessageParam[] = [];\n  readonly chatCompletions: OpenAI.Chat.ChatCompletion[] = [];\n  readonly functionCalls: OpenAI.Chat.ChatCompletionMessageFunctionToolCall.Function[] = [];\n  readonly functionCallResults: string[] = [];\n  finalContent: string | null = null;\n  finalMessage: ChatCompletionMessageParam | undefined;\n  finalChatCompletion: OpenAI.Chat.ChatCompletion | undefined;\n  finalFunctionCall: OpenAI.Chat.ChatCompletionMessageFunctionToolCall.Function | undefined;\n  finalFunctionCallResult: string | undefined;\n  totalUsage: OpenAI.CompletionUsage | undefined;\n  error: OpenAIError | undefined;\n  gotConnect = false;\n  gotAbort = false;\n  gotEnd = false;\n\n  onceMessageCallCount = 0;\n\n  constructor(public runner: ChatCompletionRunner<any>) {\n    runner\n      .on('connect', () => (this.gotConnect = true))\n      .on('content', (content) => this.contents.push(content))\n      .on('message', (message) => this.messages.push(message))\n      .on('chatCompletion', (completion) => this.chatCompletions.push(completion))\n      .on('functionToolCall', (functionCall) => this.functionCalls.push(functionCall))\n      .on('functionToolCallResult', (result) => this.functionCallResults.push(result))\n      .on('finalContent', (content) => (this.finalContent = content))\n      .on('finalMessage', (message) => (this.finalMessage = message))\n      .on('finalChatCompletion', (completion) => (this.finalChatCompletion = completion))\n      .on('finalFunctionToolCall', (functionCall) => (this.finalFunctionCall = functionCall))\n      .on('finalFunctionToolCallResult', (result) => (this.finalFunctionCallResult = result))\n      .on('totalUsage', (usage) => (this.totalUsage = usage))\n      .on('error', (error) => (this.error = error))\n      .on('abort', (error) => ((this.error = error), (this.gotAbort = true)))\n      .on('end', () => (this.gotEnd = true))\n      .once('message', () => this.onceMessageCallCount++);\n  }\n\n  async sanityCheck({ error }: { error?: string } = {}) {\n    expect(this.onceMessageCallCount).toBeLessThanOrEqual(1);\n    expect(this.gotAbort).toEqual(this.runner.aborted);\n    if (this.runner.aborted) expect(this.runner.errored).toBe(true);\n    if (error) {\n      expect(this.error?.message).toEqual(error);\n      expect(this.runner.errored).toBe(true);\n      await expect(this.runner.finalChatCompletion()).rejects.toThrow(error);\n      await expect(this.runner.finalMessage()).rejects.toThrow(error);\n      await expect(this.runner.finalContent()).rejects.toThrow(error);\n      await expect(this.runner.finalFunctionToolCall()).rejects.toThrow(error);\n      await expect(this.runner.finalFunctionToolCallResult()).rejects.toThrow(error);\n      await expect(this.runner.totalUsage()).rejects.toThrow(error);\n      await expect(this.runner.done()).rejects.toThrow(error);\n    } else {\n      expect(this.error).toBeUndefined();\n      expect(this.runner.errored).toBe(false);\n    }\n\n    if (!this.gotConnect) {\n      expect(this.contents).toEqual([]);\n      expect(this.messages).toEqual([]);\n      expect(this.chatCompletions).toEqual([]);\n      expect(this.functionCalls).toEqual([]);\n      expect(this.functionCallResults).toEqual([]);\n      expect(this.finalContent).toBeUndefined();\n      expect(this.finalMessage).toBeUndefined();\n      expect(this.finalChatCompletion).toBeUndefined();\n      expect(this.finalFunctionCall).toBeUndefined();\n      expect(this.finalFunctionCallResult).toBeUndefined();\n      expect(this.totalUsage).toBeUndefined();\n      expect(this.gotEnd).toBe(true);\n      return;\n    }\n\n    if (error) return;\n\n    const expectedContents = this.messages\n      .filter(isAssistantMessage)\n      .map((m) => m.content as string)\n      .filter(Boolean);\n    expect(this.contents).toEqual(expectedContents);\n    expect(this.finalMessage).toEqual([...this.messages].reverse().find((x) => x.role === 'assistant'));\n    expect(await this.runner.finalMessage()).toEqual(this.finalMessage);\n    expect(this.finalContent).toEqual(expectedContents[expectedContents.length - 1] ?? null);\n    expect(await this.runner.finalContent()).toEqual(this.finalContent);\n    expect(this.finalChatCompletion).toEqual(this.chatCompletions[this.chatCompletions.length - 1]);\n    expect(await this.runner.finalChatCompletion()).toEqual(this.finalChatCompletion);\n    expect(this.finalFunctionCall).toEqual(this.functionCalls[this.functionCalls.length - 1]);\n    expect(await this.runner.finalFunctionToolCall()).toEqual(this.finalFunctionCall);\n    expect(this.finalFunctionCallResult).toEqual(\n      this.functionCallResults[this.functionCallResults.length - 1],\n    );\n    expect(await this.runner.finalFunctionToolCallResult()).toEqual(this.finalFunctionCallResult);\n    expect(this.chatCompletions).toEqual(this.runner.allChatCompletions());\n    expect(this.messages).toEqual(this.runner.messages.slice(-this.messages.length));\n    if (this.chatCompletions.some((c) => c.usage)) {\n      const totalUsage: OpenAI.CompletionUsage = {\n        completion_tokens: 0,\n        prompt_tokens: 0,\n        total_tokens: 0,\n      };\n      for (const { usage } of this.chatCompletions) {\n        if (usage) {\n          totalUsage.completion_tokens += usage.completion_tokens;\n          totalUsage.prompt_tokens += usage.prompt_tokens;\n          totalUsage.total_tokens += usage.total_tokens;\n        }\n      }\n      expect(this.totalUsage).toEqual(totalUsage);\n      expect(await this.runner.totalUsage()).toEqual(totalUsage);\n    }\n\n    expect(this.gotEnd).toBe(true);\n  }\n}\n\nclass StreamingRunnerListener {\n  readonly eventChunks: OpenAI.Chat.ChatCompletionChunk[] = [];\n  readonly eventContents: [string, string][] = [];\n  readonly eventMessages: ChatCompletionMessageParam[] = [];\n  readonly eventChatCompletions: OpenAI.Chat.ChatCompletion[] = [];\n  readonly eventFunctionCalls: OpenAI.Chat.ChatCompletionMessageFunctionToolCall.Function[] = [];\n  readonly eventFunctionCallResults: string[] = [];\n\n  finalContent: string | null = null;\n  finalMessage: ChatCompletionMessageParam | undefined;\n  finalChatCompletion: OpenAI.Chat.ChatCompletion | undefined;\n  finalFunctionCall: OpenAI.Chat.ChatCompletionMessageFunctionToolCall.Function | undefined;\n  finalFunctionCallResult: string | undefined;\n  error: OpenAIError | undefined;\n  gotConnect = false;\n  gotEnd = false;\n\n  constructor(public runner: ChatCompletionStreamingRunner<any>) {\n    runner\n      .on('connect', () => (this.gotConnect = true))\n      .on('chunk', (chunk) => this.eventChunks.push(chunk))\n      .on('content', (delta, snapshot) => this.eventContents.push([delta, snapshot]))\n      .on('message', (message) => this.eventMessages.push(message))\n      .on('chatCompletion', (completion) => this.eventChatCompletions.push(completion))\n      .on('functionToolCall', (functionCall) => this.eventFunctionCalls.push(functionCall))\n      .on('functionToolCallResult', (result) => this.eventFunctionCallResults.push(result))\n      .on('finalContent', (content) => (this.finalContent = content))\n      .on('finalMessage', (message) => (this.finalMessage = message))\n      .on('finalChatCompletion', (completion) => (this.finalChatCompletion = completion))\n      .on('finalFunctionToolCall', (functionCall) => (this.finalFunctionCall = functionCall))\n      .on('finalFunctionToolCallResult', (result) => (this.finalFunctionCallResult = result))\n      .on('error', (error) => (this.error = error))\n      .on('abort', (abort) => (this.error = abort))\n      .on('end', () => (this.gotEnd = true));\n  }\n\n  async sanityCheck({ error }: { error?: string } = {}) {\n    if (error) {\n      expect(this.error?.message).toEqual(error);\n      expect(this.runner.errored).toBe(true);\n      await expect(this.runner.finalChatCompletion()).rejects.toThrow(error);\n      await expect(this.runner.finalMessage()).rejects.toThrow(error);\n      await expect(this.runner.finalContent()).rejects.toThrow(error);\n      await expect(this.runner.finalFunctionToolCall()).rejects.toThrow(error);\n      await expect(this.runner.finalFunctionToolCallResult()).rejects.toThrow(error);\n      await expect(this.runner.done()).rejects.toThrow(error);\n    } else {\n      expect(this.error).toBeUndefined();\n      expect(this.runner.errored).toBe(false);\n    }\n\n    if (!this.gotConnect) {\n      expect(this.eventContents).toEqual([]);\n      expect(this.eventMessages).toEqual([]);\n      expect(this.eventChatCompletions).toEqual([]);\n      expect(this.eventFunctionCalls).toEqual([]);\n      expect(this.eventFunctionCallResults).toEqual([]);\n      expect(this.finalContent).toBeUndefined();\n      expect(this.finalMessage).toBeUndefined();\n      expect(this.finalChatCompletion).toBeUndefined();\n      expect(this.finalFunctionCall).toBeUndefined();\n      expect(this.finalFunctionCallResult).toBeUndefined();\n      expect(this.gotEnd).toBe(true);\n      return;\n    }\n\n    if (error) return;\n\n    if (this.eventContents.length) expect(this.eventChunks.length).toBeGreaterThan(0);\n    expect(this.finalMessage).toEqual([...this.eventMessages].reverse().find((x) => x.role === 'assistant'));\n    expect(await this.runner.finalMessage()).toEqual(this.finalMessage);\n    expect(this.finalContent).toEqual(this.eventContents[this.eventContents.length - 1]?.[1] ?? null);\n    expect(await this.runner.finalContent()).toEqual(this.finalContent);\n    expect(this.finalChatCompletion).toEqual(this.eventChatCompletions[this.eventChatCompletions.length - 1]);\n    expect(await this.runner.finalChatCompletion()).toEqual(this.finalChatCompletion);\n    expect(this.finalFunctionCall).toEqual(this.eventFunctionCalls[this.eventFunctionCalls.length - 1]);\n    expect(await this.runner.finalFunctionToolCall()).toEqual(this.finalFunctionCall);\n    expect(this.finalFunctionCallResult).toEqual(\n      this.eventFunctionCallResults[this.eventFunctionCallResults.length - 1],\n    );\n    expect(await this.runner.finalFunctionToolCallResult()).toEqual(this.finalFunctionCallResult);\n    expect(this.eventChatCompletions).toEqual(this.runner.allChatCompletions());\n    expect(this.eventMessages).toEqual(this.runner.messages.slice(-this.eventMessages.length));\n    if (error) {\n      expect(this.error?.message).toEqual(error);\n      expect(this.runner.errored).toBe(true);\n    } else {\n      expect(this.error).toBeUndefined();\n      expect(this.runner.errored).toBe(false);\n    }\n    expect(this.gotEnd).toBe(true);\n  }\n}\n\nfunction _typeTests() {\n  const openai = new OpenAI();\n\n  openai.chat.completions.runTools({\n    messages: [\n      { role: 'user', content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}' },\n    ],\n    model: 'gpt-3.5-turbo',\n    tools: [\n      {\n        type: 'function',\n        function: {\n          name: 'numProperties',\n          function: (obj: object) => String(Object.keys(obj).length),\n          parameters: { type: 'object' },\n          parse: (str: string): object => {\n            const result = JSON.parse(str);\n            if (!(result instanceof Object) || Array.isArray(result)) {\n              throw new Error('must be an object');\n            }\n            return result;\n          },\n          description: 'gets the number of properties on an object',\n        },\n      },\n      {\n        type: 'function',\n        function: {\n          function: (str: string) => String(str.length),\n          parameters: { type: 'string' },\n          description: 'gets the length of a string',\n        },\n      },\n      {\n        type: 'function',\n        // @ts-expect-error function must accept string if parse is omitted\n        function: {\n          function: (obj: object) => String(Object.keys(obj).length),\n          parameters: { type: 'object' },\n          description: 'gets the number of properties on an object',\n        },\n      },\n    ],\n  });\n  openai.chat.completions.runTools({\n    messages: [\n      { role: 'user', content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}' },\n    ],\n    model: 'gpt-3.5-turbo',\n    tools: [\n      new ParsingToolFunction({\n        name: 'numProperties',\n        // @ts-expect-error parse and function don't match\n        parse: (str: string) => str,\n        function: (obj: object) => String(Object.keys(obj).length),\n        parameters: { type: 'object' },\n        description: 'gets the number of properties on an object',\n      }),\n    ],\n  });\n  openai.chat.completions.runTools({\n    messages: [\n      { role: 'user', content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}' },\n    ],\n    model: 'gpt-3.5-turbo',\n    tools: [\n      new ParsingToolFunction({\n        name: 'numProperties',\n        parse: (str: string): object => {\n          const result = JSON.parse(str);\n          if (!(result instanceof Object) || Array.isArray(result)) {\n            throw new Error('must be an object');\n          }\n          return result;\n        },\n        function: (obj: object) => String(Object.keys(obj).length),\n        parameters: { type: 'object' },\n        description: 'gets the number of properties on an object',\n      }),\n      new ParsingToolFunction({\n        name: 'keys',\n        parse: (str: string): object => {\n          const result = JSON.parse(str);\n          if (!(result instanceof Object)) {\n            throw new Error('must be an Object');\n          }\n          return result;\n        },\n        function: (obj: object) => Object.keys(obj).join(', '),\n        parameters: { type: 'object' },\n        description: 'gets the number of properties on an object',\n      }),\n      new ParsingToolFunction({\n        name: 'len2',\n        // @ts-expect-error parse and function don't match\n        parse: (str: string) => str,\n        function: (obj: object) => String(Object.keys(obj).length),\n        parameters: { type: 'object' },\n        description: 'gets the number of properties on an object',\n      }),\n    ],\n  });\n  openai.chat.completions.runTools({\n    messages: [\n      { role: 'user', content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}' },\n    ],\n    model: 'gpt-3.5-turbo',\n    // @ts-ignore error occurs here in TS 4\n    tools: [\n      {\n        type: 'function',\n        function: {\n          name: 'numProperties',\n          parse: (str: string): object => {\n            const result = JSON.parse(str);\n            if (!(result instanceof Object) || Array.isArray(result)) {\n              throw new Error('must be an object');\n            }\n            return result;\n          },\n          function: (obj: object) => String(Object.keys(obj).length),\n          parameters: { type: 'object' },\n          description: 'gets the number of properties on an object',\n        },\n      },\n      {\n        type: 'function',\n        function: {\n          name: 'keys',\n          parse: (str: string): object => {\n            const result = JSON.parse(str);\n            if (!(result instanceof Object)) {\n              throw new Error('must be an Object');\n            }\n            return result;\n          },\n          function: (obj: object) => Object.keys(obj).join(', '),\n          parameters: { type: 'object' },\n          description: 'gets the number of properties on an object',\n        },\n      },\n      {\n        type: 'function',\n        function: {\n          name: 'len2',\n          parse: (str: string) => str,\n          // @ts-ignore error occurs here in TS 5\n          // function input doesn't match parse output\n          function: (obj: object) => String(Object.keys(obj).length),\n          parameters: { type: 'object' },\n          description: 'gets the number of properties on an object',\n        },\n      },\n    ] as const,\n  });\n}\n\ndescribe('resource completions', () => {\n  describe('runTools with stream: false', () => {\n    test('successful flow', async () => {\n      const { fetch, handleRequest } = mockChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.runTools({\n        messages: [{ role: 'user', content: 'tell me what the weather is like' }],\n        model: 'gpt-3.5-turbo',\n        tools: [\n          {\n            type: 'function',\n            function: {\n              function: function getWeather() {\n                return `it's raining`;\n              },\n              parameters: {},\n              description: 'gets the weather',\n            },\n          },\n        ],\n      });\n      const listener = new RunnerListener(runner);\n\n      await handleRequest(async (request) => {\n        expect(request.messages).toEqual([{ role: 'user', content: 'tell me what the weather is like' }]);\n        return {\n          id: '1',\n          choices: [\n            {\n              index: 0,\n              finish_reason: 'function_call',\n              logprobs: null,\n              message: {\n                role: 'assistant',\n                content: null,\n                refusal: null,\n                parsed: null,\n                tool_calls: [\n                  {\n                    type: 'function',\n                    id: '123',\n                    function: {\n                      arguments: '',\n                      name: 'getWeather',\n                    },\n                  },\n                ],\n              },\n            },\n          ],\n          created: Math.floor(Date.now() / 1000),\n          model: 'gpt-3.5-turbo',\n          object: 'chat.completion',\n        };\n      });\n\n      await handleRequest(async (request) => {\n        expect(request.messages).toEqual([\n          {\n            role: 'user',\n            content: 'tell me what the weather is like',\n          },\n          {\n            role: 'assistant',\n            content: null,\n            refusal: null,\n            parsed: null,\n            tool_calls: [\n              {\n                type: 'function',\n                id: '123',\n                function: {\n                  arguments: '',\n                  name: 'getWeather',\n                  parsed_arguments: null,\n                },\n              },\n            ],\n          },\n          {\n            role: 'tool',\n            content: `it's raining`,\n            tool_call_id: '123',\n          },\n        ]);\n\n        return {\n          id: '2',\n          choices: [\n            {\n              index: 0,\n              finish_reason: 'stop',\n              logprobs: null,\n              message: {\n                role: 'assistant',\n                content: `it's raining`,\n                refusal: null,\n              },\n            },\n          ],\n          created: Math.floor(Date.now() / 1000),\n          model: 'gpt-3.5-turbo',\n          object: 'chat.completion',\n        };\n      });\n\n      await runner.done();\n\n      expect(listener.messages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                arguments: '',\n                name: 'getWeather',\n                parsed_arguments: null,\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: `it's raining`, tool_call_id: '123' },\n        {\n          role: 'assistant',\n          content: \"it's raining\",\n          parsed: null,\n          refusal: null,\n          tool_calls: undefined,\n        },\n      ]);\n      expect(listener.functionCallResults).toEqual([`it's raining`]);\n      await listener.sanityCheck();\n    });\n    test('flow with abort', async () => {\n      const { fetch, handleRequest } = mockChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const controller = new AbortController();\n      const runner = openai.chat.completions.runTools(\n        {\n          messages: [{ role: 'user', content: 'tell me what the weather is like' }],\n          model: 'gpt-3.5-turbo',\n          tools: [\n            {\n              type: 'function',\n              function: {\n                function: function getWeather() {\n                  return `it's raining`;\n                },\n                parameters: {},\n                description: 'gets the weather',\n              },\n            },\n          ],\n        },\n        { signal: controller.signal },\n      );\n      const listener = new RunnerListener(runner);\n\n      await handleRequest(async (request) => {\n        expect(request.messages).toEqual([{ role: 'user', content: 'tell me what the weather is like' }]);\n        return {\n          id: '1',\n          choices: [\n            {\n              index: 0,\n              finish_reason: 'function_call',\n              logprobs: null,\n              message: {\n                role: 'assistant',\n                content: null,\n                parsed: null,\n                refusal: null,\n                tool_calls: [\n                  {\n                    type: 'function',\n                    id: '123',\n                    function: {\n                      arguments: '',\n                      name: 'getWeather',\n                    },\n                  },\n                ],\n              },\n            },\n          ],\n          created: Math.floor(Date.now() / 1000),\n          model: 'gpt-3.5-turbo',\n          object: 'chat.completion',\n        };\n      });\n\n      controller.abort();\n\n      await runner.done().catch(() => {});\n\n      expect(listener.messages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                arguments: '',\n                name: 'getWeather',\n                parsed_arguments: null,\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: `it's raining`, tool_call_id: '123' },\n      ]);\n      expect(listener.functionCallResults).toEqual([`it's raining`]);\n      await listener.sanityCheck({ error: 'Request was aborted.' });\n      expect(runner.aborted).toBe(true);\n    });\n    test('successful flow with parse', async () => {\n      const { fetch, handleRequest } = mockChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.runTools({\n        messages: [\n          {\n            role: 'user',\n            content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n          },\n        ],\n        model: 'gpt-3.5-turbo',\n        tools: [\n          new ParsingToolFunction({\n            name: 'numProperties',\n            function: (obj: object) => String(Object.keys(obj).length),\n            parameters: { type: 'object' },\n            parse: (str: string): object => {\n              const result = JSON.parse(str);\n              if (!(result instanceof Object) || Array.isArray(result)) {\n                throw new Error('must be an object');\n              }\n              return result;\n            },\n            description: 'gets the number of properties on an object',\n          }),\n        ],\n      });\n      const listener = new RunnerListener(runner);\n\n      await handleRequest(async (request) => {\n        expect(request.messages).toEqual([\n          {\n            role: 'user',\n            content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n          },\n        ]);\n        return {\n          id: '1',\n          choices: [\n            {\n              index: 0,\n              finish_reason: 'function_call',\n              logprobs: null,\n              message: {\n                role: 'assistant',\n                content: null,\n                parsed: null,\n                refusal: null,\n                tool_calls: [\n                  {\n                    type: 'function',\n                    id: '123',\n                    function: {\n                      arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n                      name: 'numProperties',\n                    },\n                  },\n                ],\n              },\n            },\n          ],\n          created: Math.floor(Date.now() / 1000),\n          model: 'gpt-3.5-turbo',\n          object: 'chat.completion',\n          usage: {\n            completion_tokens: 5,\n            prompt_tokens: 20,\n            total_tokens: 25,\n          },\n        };\n      });\n\n      await handleRequest(async (request) => {\n        expect(request.messages).toEqual([\n          {\n            role: 'user',\n            content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n          },\n          {\n            role: 'assistant',\n            content: null,\n            parsed: null,\n            refusal: null,\n            tool_calls: [\n              {\n                type: 'function',\n                id: '123',\n                function: {\n                  arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n                  name: 'numProperties',\n                  parsed_arguments: null,\n                },\n              },\n            ],\n          },\n          {\n            role: 'tool',\n            content: '3',\n            tool_call_id: '123',\n          },\n        ]);\n        return {\n          id: '2',\n          choices: [\n            {\n              index: 0,\n              finish_reason: 'stop',\n              logprobs: null,\n              message: {\n                role: 'assistant',\n                content: `there are 3 properties in {\"a\": 1, \"b\": 2, \"c\": 3}`,\n                refusal: null,\n              },\n            },\n          ],\n          created: Math.floor(Date.now() / 1000),\n          model: 'gpt-3.5-turbo',\n          object: 'chat.completion',\n          usage: {\n            completion_tokens: 10,\n            prompt_tokens: 25,\n            total_tokens: 35,\n          },\n        };\n      });\n\n      await runner.done();\n\n      expect(listener.messages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                name: 'numProperties',\n                arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n                parsed_arguments: null,\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: '3', tool_call_id: '123' },\n        {\n          role: 'assistant',\n          content: 'there are 3 properties in {\"a\": 1, \"b\": 2, \"c\": 3}',\n          parsed: null,\n          refusal: null,\n          tool_calls: undefined,\n        },\n      ]);\n      expect(listener.functionCallResults).toEqual(['3']);\n      await listener.sanityCheck();\n    });\n    test('flow with parse error', async () => {\n      const { fetch, handleRequest } = mockChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.runTools({\n        messages: [\n          {\n            role: 'user',\n            content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n          },\n        ],\n        model: 'gpt-3.5-turbo',\n        tools: [\n          new ParsingToolFunction({\n            name: 'numProperties',\n            function: (obj: object) => String(Object.keys(obj).length),\n            parameters: { type: 'object' },\n            parse: (str: string): object => {\n              const result = JSON.parse(str);\n              if (!(result instanceof Object) || Array.isArray(result)) {\n                throw new Error('must be an object');\n              }\n              return result;\n            },\n            description: 'gets the number of properties on an object',\n          }),\n        ],\n      });\n      const listener = new RunnerListener(runner);\n\n      await Promise.all([\n        handleRequest(async (request) => {\n          expect(request.messages).toEqual([\n            {\n              role: 'user',\n              content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n            },\n          ]);\n          return {\n            id: '1',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'function_call',\n                logprobs: null,\n                message: {\n                  role: 'assistant',\n                  content: null,\n                  parsed: null,\n                  refusal: null,\n                  tool_calls: [\n                    {\n                      type: 'function',\n                      id: '123',\n                      function: {\n                        arguments: '[{\"a\": 1, \"b\": 2, \"c\": 3}]',\n                        name: 'numProperties',\n                      },\n                    },\n                  ],\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion',\n          };\n        }),\n        handleRequest(async (request) => {\n          expect(request.messages).toEqual([\n            {\n              role: 'user',\n              content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n            },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '123',\n                  function: {\n                    arguments: '[{\"a\": 1, \"b\": 2, \"c\": 3}]',\n                    name: 'numProperties',\n                    parsed_arguments: null,\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `must be an object`,\n              tool_call_id: '123',\n            },\n          ]);\n          return {\n            id: '2',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'function_call',\n                logprobs: null,\n                message: {\n                  role: 'assistant',\n                  content: null,\n                  parsed: null,\n                  refusal: null,\n                  tool_calls: [\n                    {\n                      type: 'function',\n                      id: '1234',\n                      function: {\n                        arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n                        name: 'numProperties',\n                      },\n                    },\n                  ],\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion',\n          };\n        }),\n        handleRequest(async (request) => {\n          expect(request.messages).toEqual([\n            {\n              role: 'user',\n              content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n            },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '123',\n                  function: {\n                    arguments: '[{\"a\": 1, \"b\": 2, \"c\": 3}]',\n                    name: 'numProperties',\n                    parsed_arguments: null,\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `must be an object`,\n              tool_call_id: '123',\n            },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '1234',\n                  function: {\n                    arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n                    name: 'numProperties',\n                    parsed_arguments: null,\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: '3',\n              tool_call_id: '1234',\n            },\n          ]);\n          return {\n            id: '3',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'stop',\n                logprobs: null,\n                message: {\n                  role: 'assistant',\n                  content: `there are 3 properties in {\"a\": 1, \"b\": 2, \"c\": 3}`,\n                  refusal: null,\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion',\n          };\n        }),\n        runner.done(),\n      ]);\n\n      expect(listener.messages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                name: 'numProperties',\n                arguments: '[{\"a\": 1, \"b\": 2, \"c\": 3}]',\n                parsed_arguments: null,\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: `must be an object`, tool_call_id: '123' },\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '1234',\n              function: {\n                name: 'numProperties',\n                arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n                parsed_arguments: null,\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: '3', tool_call_id: '1234' },\n        {\n          role: 'assistant',\n          content: 'there are 3 properties in {\"a\": 1, \"b\": 2, \"c\": 3}',\n          parsed: null,\n          refusal: null,\n          tool_calls: undefined,\n        },\n      ]);\n      expect(listener.functionCallResults).toEqual([`must be an object`, '3']);\n      await listener.sanityCheck();\n    });\n    test('single function call', async () => {\n      const { fetch, handleRequest } = mockChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.runTools({\n        messages: [{ role: 'user', content: 'tell me what the weather is like' }],\n        model: 'gpt-3.5-turbo',\n        tool_choice: {\n          type: 'function',\n          function: {\n            name: 'getWeather',\n          },\n        },\n        tools: [\n          {\n            type: 'function',\n            function: {\n              function: function getWeather() {\n                return `it's raining`;\n              },\n              parameters: {},\n              description: 'gets the weather',\n            },\n          },\n        ],\n      });\n      const listener = new RunnerListener(runner);\n\n      await Promise.all([\n        handleRequest(async (request) => {\n          expect(request.messages).toEqual([{ role: 'user', content: 'tell me what the weather is like' }]);\n          return {\n            id: '1',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'function_call',\n                logprobs: null,\n                message: {\n                  role: 'assistant',\n                  content: null,\n                  parsed: null,\n                  refusal: null,\n                  tool_calls: [\n                    {\n                      type: 'function',\n                      id: '123',\n                      function: {\n                        arguments: '',\n                        name: 'getWeather',\n                      },\n                    },\n                  ],\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion',\n          };\n        }),\n        runner.done(),\n      ]);\n\n      expect(listener.messages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                arguments: '',\n                name: 'getWeather',\n                parsed_arguments: null,\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: `it's raining`, tool_call_id: '123' },\n      ]);\n      expect(listener.functionCallResults).toEqual([`it's raining`]);\n      await listener.sanityCheck();\n    });\n    test('wrong function name', async () => {\n      const { fetch, handleRequest } = mockChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.runTools({\n        messages: [{ role: 'user', content: 'tell me what the weather is like' }],\n        model: 'gpt-3.5-turbo',\n        tools: [\n          {\n            type: 'function',\n            function: {\n              function: function getWeather() {\n                return `it's raining`;\n              },\n              parameters: {},\n              description: 'gets the weather',\n            },\n          },\n        ],\n      });\n      const listener = new RunnerListener(runner);\n\n      await Promise.all([\n        handleRequest(async (request) => {\n          expect(request.messages).toEqual([{ role: 'user', content: 'tell me what the weather is like' }]);\n          return {\n            id: '1',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'function_call',\n                logprobs: null,\n                message: {\n                  role: 'assistant',\n                  content: null,\n                  parsed: null,\n                  refusal: null,\n                  tool_calls: [\n                    {\n                      type: 'function',\n                      id: '123',\n                      function: {\n                        arguments: '',\n                        name: 'get_weather',\n                      },\n                    },\n                  ],\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion',\n          };\n        }),\n        handleRequest(async (request) => {\n          expect(request.messages).toEqual([\n            { role: 'user', content: 'tell me what the weather is like' },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '123',\n                  function: {\n                    arguments: '',\n                    name: 'get_weather',\n                    parsed_arguments: null,\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `Invalid tool_call: \"get_weather\". Available options are: \"getWeather\". Please try again`,\n              tool_call_id: '123',\n            },\n          ]);\n          return {\n            id: '2',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'function_call',\n                logprobs: null,\n                message: {\n                  role: 'assistant',\n                  content: null,\n                  parsed: null,\n                  refusal: null,\n                  tool_calls: [\n                    {\n                      type: 'function',\n                      id: '1234',\n                      function: {\n                        arguments: '',\n                        name: 'getWeather',\n                      },\n                    },\n                  ],\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion',\n          };\n        }),\n        handleRequest(async (request) => {\n          expect(request.messages).toEqual([\n            { role: 'user', content: 'tell me what the weather is like' },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '123',\n                  function: {\n                    arguments: '',\n                    name: 'get_weather',\n                    parsed_arguments: null,\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `Invalid tool_call: \"get_weather\". Available options are: \"getWeather\". Please try again`,\n              tool_call_id: '123',\n            },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '1234',\n                  function: {\n                    arguments: '',\n                    name: 'getWeather',\n                    parsed_arguments: null,\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `it's raining`,\n              tool_call_id: '1234',\n            },\n          ]);\n          return {\n            id: '3',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'stop',\n                logprobs: null,\n                message: {\n                  role: 'assistant',\n                  refusal: null,\n                  content: `it's raining`,\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion',\n          };\n        }),\n        runner.done(),\n      ]);\n\n      expect(listener.messages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: { name: 'get_weather', arguments: '', parsed_arguments: null },\n            },\n          ],\n        },\n        {\n          role: 'tool',\n          content: `Invalid tool_call: \"get_weather\". Available options are: \"getWeather\". Please try again`,\n          tool_call_id: '123',\n        },\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '1234',\n              function: {\n                name: 'getWeather',\n                arguments: '',\n                parsed_arguments: null,\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: `it's raining`, tool_call_id: '1234' },\n        {\n          role: 'assistant',\n          content: \"it's raining\",\n          parsed: null,\n          refusal: null,\n          tool_calls: undefined,\n        },\n      ]);\n      expect(listener.functionCallResults).toEqual([\n        `Invalid tool_call: \"get_weather\". Available options are: \"getWeather\". Please try again`,\n        `it's raining`,\n      ]);\n      await listener.sanityCheck();\n    });\n  });\n\n  describe('runTools with stream: true', () => {\n    test('successful flow', async () => {\n      const { fetch, handleRequest } = mockStreamingChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.runTools({\n        stream: true,\n        messages: [{ role: 'user', content: 'tell me what the weather is like' }],\n        model: 'gpt-3.5-turbo',\n        tools: [\n          {\n            type: 'function',\n            function: {\n              function: function getWeather() {\n                return `it's raining`;\n              },\n              parameters: {},\n              description: 'gets the weather',\n            },\n          },\n        ],\n      });\n      const listener = new StreamingRunnerListener(runner);\n\n      await Promise.all([\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([{ role: 'user', content: 'tell me what the weather is like' }]);\n          yield {\n            id: '1',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'function_call',\n                logprobs: null,\n                delta: {\n                  role: 'assistant',\n                  content: null,\n                  tool_calls: [\n                    {\n                      type: 'function',\n                      index: 0,\n                      id: '123',\n                      function: {\n                        arguments: '',\n                        name: 'getWeather',\n                      },\n                    },\n                  ],\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion.chunk',\n          };\n        }),\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([\n            { role: 'user', content: 'tell me what the weather is like' },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '123',\n                  function: {\n                    arguments: '',\n                    name: 'getWeather',\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `it's raining`,\n              tool_call_id: '123',\n            },\n          ]);\n          for (const choice of contentChoiceDeltas(`it's raining`)) {\n            yield {\n              id: '2',\n              choices: [choice],\n              created: Math.floor(Date.now() / 1000),\n              model: 'gpt-3.5-turbo',\n              object: 'chat.completion.chunk',\n            };\n          }\n        }),\n        runner.done(),\n      ]);\n\n      expect(listener.eventMessages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                arguments: '',\n                name: 'getWeather',\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: `it's raining`, tool_call_id: '123' },\n        {\n          role: 'assistant',\n          content: \"it's raining\",\n          parsed: null,\n          refusal: null,\n          tool_calls: undefined,\n        },\n      ]);\n      expect(listener.eventFunctionCallResults).toEqual([`it's raining`]);\n      await listener.sanityCheck();\n    });\n    test('flow with abort', async () => {\n      const { fetch, handleRequest } = mockStreamingChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const controller = new AbortController();\n      const runner = openai.chat.completions.runTools(\n        {\n          stream: true,\n          messages: [{ role: 'user', content: 'tell me what the weather is like' }],\n          model: 'gpt-3.5-turbo',\n          tools: [\n            {\n              type: 'function',\n              function: {\n                function: function getWeather() {\n                  return `it's raining`;\n                },\n                parameters: {},\n                description: 'gets the weather',\n              },\n            },\n          ],\n        },\n        { signal: controller.signal },\n      );\n      runner.on('functionToolCallResult', () => controller.abort());\n      const listener = new StreamingRunnerListener(runner);\n\n      await handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n        expect(request.messages).toEqual([{ role: 'user', content: 'tell me what the weather is like' }]);\n        yield {\n          id: '1',\n          choices: [\n            {\n              index: 0,\n              finish_reason: 'function_call',\n              delta: {\n                role: 'assistant',\n                content: null,\n                tool_calls: [\n                  {\n                    type: 'function',\n                    index: 0,\n                    id: '123',\n                    function: {\n                      arguments: '',\n                      name: 'getWeather',\n                    },\n                  },\n                ],\n              },\n            },\n          ],\n          created: Math.floor(Date.now() / 1000),\n          model: 'gpt-3.5-turbo',\n          object: 'chat.completion.chunk',\n        };\n      });\n\n      await runner.done().catch(() => {});\n\n      expect(listener.eventMessages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                arguments: '',\n                name: 'getWeather',\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: `it's raining`, tool_call_id: '123' },\n      ]);\n      expect(listener.eventFunctionCallResults).toEqual([`it's raining`]);\n      await listener.sanityCheck({ error: 'Request was aborted.' });\n      expect(runner.aborted).toBe(true);\n    });\n    test('successful flow with parse', async () => {\n      const { fetch, handleRequest } = mockStreamingChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.runTools({\n        stream: true,\n        messages: [\n          {\n            role: 'user',\n            content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n          },\n        ],\n        model: 'gpt-3.5-turbo',\n        tools: [\n          new ParsingToolFunction({\n            name: 'numProperties',\n            function: (obj: object) => String(Object.keys(obj).length),\n            parameters: { type: 'object' },\n            parse: (str: string): object => {\n              const result = JSON.parse(str);\n              if (!(result instanceof Object) || Array.isArray(result)) {\n                throw new Error('must be an object');\n              }\n              return result;\n            },\n            description: 'gets the number of properties on an object',\n          }),\n        ],\n      });\n      const listener = new StreamingRunnerListener(runner);\n\n      await Promise.all([\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([\n            {\n              role: 'user',\n              content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n            },\n          ]);\n          yield {\n            id: '1',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'function_call',\n                delta: {\n                  role: 'assistant',\n                  content: null,\n                  tool_calls: [\n                    {\n                      type: 'function',\n                      id: '123',\n                      index: 0,\n                      function: {\n                        arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n                        name: 'numProperties',\n                      },\n                    },\n                  ],\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion.chunk',\n          };\n        }),\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([\n            {\n              role: 'user',\n              content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n            },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '123',\n                  function: {\n                    arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n                    name: 'numProperties',\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: '3',\n              tool_call_id: '123',\n            },\n          ]);\n          for (const choice of contentChoiceDeltas(`there are 3 properties in {\"a\": 1, \"b\": 2, \"c\": 3}`)) {\n            yield {\n              id: '2',\n              choices: [choice],\n              created: Math.floor(Date.now() / 1000),\n              model: 'gpt-3.5-turbo',\n              object: 'chat.completion.chunk',\n            };\n          }\n        }),\n        runner.done(),\n      ]);\n\n      expect(listener.eventMessages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                name: 'numProperties',\n                arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: '3', tool_call_id: '123' },\n        {\n          role: 'assistant',\n          content: 'there are 3 properties in {\"a\": 1, \"b\": 2, \"c\": 3}',\n          parsed: null,\n          refusal: null,\n          tool_calls: undefined,\n        },\n      ]);\n      expect(listener.eventFunctionCallResults).toEqual(['3']);\n      await listener.sanityCheck();\n    });\n    test('flow with parse error', async () => {\n      const { fetch, handleRequest } = mockStreamingChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.runTools({\n        stream: true,\n        messages: [\n          {\n            role: 'user',\n            content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n          },\n        ],\n        model: 'gpt-3.5-turbo',\n        tools: [\n          new ParsingToolFunction({\n            name: 'numProperties',\n            function: (obj: object) => String(Object.keys(obj).length),\n            parameters: { type: 'object' },\n            parse: (str: string): object => {\n              const result = JSON.parse(str);\n              if (!(result instanceof Object) || Array.isArray(result)) {\n                throw new Error('must be an object');\n              }\n              return result;\n            },\n            description: 'gets the number of properties on an object',\n          }),\n        ],\n      });\n      const listener = new StreamingRunnerListener(runner);\n\n      await Promise.all([\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([\n            {\n              role: 'user',\n              content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n            },\n          ]);\n          for (const choice of functionCallDeltas('[{\"a\": 1, \"b\": 2, \"c\": 3}]', {\n            name: 'numProperties',\n            id: '123',\n          })) {\n            yield {\n              id: '1',\n              choices: [choice],\n              created: Math.floor(Date.now() / 1000),\n              model: 'gpt-3.5-turbo',\n              object: 'chat.completion.chunk',\n            };\n          }\n        }),\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([\n            {\n              role: 'user',\n              content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n            },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '123',\n                  function: {\n                    arguments: '[{\"a\": 1, \"b\": 2, \"c\": 3}]',\n                    name: 'numProperties',\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `must be an object`,\n              tool_call_id: '123',\n            },\n          ]);\n          for (const choice of functionCallDeltas('{\"a\": 1, \"b\": 2, \"c\": 3}', {\n            name: 'numProperties',\n            id: '1234',\n          })) {\n            yield {\n              id: '2',\n              choices: [choice],\n              created: Math.floor(Date.now() / 1000),\n              model: 'gpt-3.5-turbo',\n              object: 'chat.completion.chunk',\n            };\n          }\n        }),\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([\n            {\n              role: 'user',\n              content: 'can you tell me how many properties are in {\"a\": 1, \"b\": 2, \"c\": 3}',\n            },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '123',\n                  function: {\n                    arguments: '[{\"a\": 1, \"b\": 2, \"c\": 3}]',\n                    name: 'numProperties',\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `must be an object`,\n              tool_call_id: '123',\n            },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '1234',\n                  function: {\n                    arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n                    name: 'numProperties',\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: '3',\n              tool_call_id: '1234',\n            },\n          ]);\n          for (const choice of contentChoiceDeltas(`there are 3 properties in {\"a\": 1, \"b\": 2, \"c\": 3}`)) {\n            yield {\n              id: '3',\n              choices: [choice],\n              created: Math.floor(Date.now() / 1000),\n              model: 'gpt-3.5-turbo',\n              object: 'chat.completion.chunk',\n            };\n          }\n        }),\n        runner.done(),\n      ]);\n\n      expect(listener.eventMessages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                name: 'numProperties',\n                arguments: '[{\"a\": 1, \"b\": 2, \"c\": 3}]',\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: `must be an object`, tool_call_id: '123' },\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '1234',\n              function: {\n                name: 'numProperties',\n                arguments: '{\"a\": 1, \"b\": 2, \"c\": 3}',\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: '3', tool_call_id: '1234' },\n        {\n          role: 'assistant',\n          content: 'there are 3 properties in {\"a\": 1, \"b\": 2, \"c\": 3}',\n          parsed: null,\n          refusal: null,\n          tool_calls: undefined,\n        },\n      ]);\n      expect(listener.eventFunctionCallResults).toEqual([`must be an object`, '3']);\n      await listener.sanityCheck();\n    });\n    test('single function call', async () => {\n      const { fetch, handleRequest } = mockStreamingChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.runTools({\n        stream: true,\n        messages: [{ role: 'user', content: 'tell me what the weather is like' }],\n        model: 'gpt-3.5-turbo',\n        tool_choice: {\n          type: 'function',\n          function: {\n            name: 'getWeather',\n          },\n        },\n        tools: [\n          {\n            type: 'function',\n            function: {\n              function: function getWeather() {\n                return `it's raining`;\n              },\n              parameters: {},\n              description: 'gets the weather',\n            },\n          },\n        ],\n      });\n      const listener = new StreamingRunnerListener(runner);\n\n      await Promise.all([\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([{ role: 'user', content: 'tell me what the weather is like' }]);\n          yield {\n            id: '1',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'function_call',\n                delta: {\n                  role: 'assistant',\n                  content: null,\n                  tool_calls: [\n                    {\n                      type: 'function',\n                      index: 0,\n                      id: '123',\n                      function: {\n                        arguments: '',\n                        name: 'getWeather',\n                      },\n                    },\n                  ],\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion.chunk',\n          };\n        }),\n        runner.done(),\n      ]);\n\n      expect(listener.eventMessages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                arguments: '',\n                name: 'getWeather',\n              },\n            },\n          ],\n        },\n        { role: 'tool', tool_call_id: '123', content: `it's raining` },\n      ]);\n      expect(listener.eventFunctionCallResults).toEqual([`it's raining`]);\n      await listener.sanityCheck();\n    });\n    test('wrong function name', async () => {\n      const { fetch, handleRequest } = mockStreamingChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.runTools({\n        stream: true,\n        messages: [{ role: 'user', content: 'tell me what the weather is like' }],\n        model: 'gpt-3.5-turbo',\n        tools: [\n          {\n            type: 'function',\n            function: {\n              function: function getWeather() {\n                return `it's raining`;\n              },\n              parameters: {},\n              description: 'gets the weather',\n            },\n          },\n        ],\n      });\n      const listener = new StreamingRunnerListener(runner);\n\n      await Promise.all([\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([{ role: 'user', content: 'tell me what the weather is like' }]);\n          yield {\n            id: '1',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'function_call',\n                delta: {\n                  role: 'assistant',\n                  content: null,\n                  tool_calls: [\n                    {\n                      type: 'function',\n                      index: 0,\n                      id: '123',\n                      function: {\n                        arguments: '',\n                        name: 'get_weather',\n                      },\n                    },\n                  ],\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion.chunk',\n          };\n        }),\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([\n            { role: 'user', content: 'tell me what the weather is like' },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '123',\n                  function: {\n                    arguments: '',\n                    name: 'get_weather',\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `Invalid tool_call: \"get_weather\". Available options are: \"getWeather\". Please try again`,\n              tool_call_id: '123',\n            },\n          ]);\n          yield {\n            id: '2',\n            choices: [\n              {\n                index: 0,\n                finish_reason: 'function_call',\n                logprobs: null,\n                delta: {\n                  role: 'assistant',\n                  content: null,\n                  tool_calls: [\n                    {\n                      type: 'function',\n                      index: 0,\n                      id: '1234',\n                      function: {\n                        arguments: '',\n                        name: 'getWeather',\n                      },\n                    },\n                  ],\n                },\n              },\n            ],\n            created: Math.floor(Date.now() / 1000),\n            model: 'gpt-3.5-turbo',\n            object: 'chat.completion.chunk',\n          };\n        }),\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([\n            { role: 'user', content: 'tell me what the weather is like' },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '123',\n                  function: {\n                    arguments: '',\n                    name: 'get_weather',\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `Invalid tool_call: \"get_weather\". Available options are: \"getWeather\". Please try again`,\n              tool_call_id: '123',\n            },\n            {\n              role: 'assistant',\n              content: null,\n              parsed: null,\n              refusal: null,\n              tool_calls: [\n                {\n                  type: 'function',\n                  id: '1234',\n                  function: {\n                    arguments: '',\n                    name: 'getWeather',\n                  },\n                },\n              ],\n            },\n            {\n              role: 'tool',\n              content: `it's raining`,\n              tool_call_id: '1234',\n            },\n          ]);\n          for (const choice of contentChoiceDeltas(`it's raining`)) {\n            yield {\n              id: '3',\n              choices: [choice],\n              created: Math.floor(Date.now() / 1000),\n              model: 'gpt-3.5-turbo',\n              object: 'chat.completion.chunk',\n            };\n          }\n        }),\n        runner.done(),\n      ]);\n\n      expect(listener.eventMessages).toEqual([\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '123',\n              function: {\n                arguments: '',\n                name: 'get_weather',\n              },\n            },\n          ],\n        },\n        {\n          role: 'tool',\n          content: `Invalid tool_call: \"get_weather\". Available options are: \"getWeather\". Please try again`,\n          tool_call_id: '123',\n        },\n        {\n          role: 'assistant',\n          content: null,\n          parsed: null,\n          refusal: null,\n          tool_calls: [\n            {\n              type: 'function',\n              id: '1234',\n              function: {\n                arguments: '',\n                name: 'getWeather',\n              },\n            },\n          ],\n        },\n        { role: 'tool', content: `it's raining`, tool_call_id: '1234' },\n        {\n          role: 'assistant',\n          content: \"it's raining\",\n          parsed: null,\n          refusal: null,\n          tool_calls: undefined,\n        },\n      ]);\n      expect(listener.eventFunctionCallResults).toEqual([\n        `Invalid tool_call: \"get_weather\". Available options are: \"getWeather\". Please try again`,\n        `it's raining`,\n      ]);\n      await listener.sanityCheck();\n    });\n  });\n\n  describe('stream', () => {\n    test('successful flow', async () => {\n      const { fetch, handleRequest } = mockStreamingChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.stream({\n        stream: true,\n        messages: [{ role: 'user', content: 'tell me what the weather is like' }],\n        model: 'gpt-3.5-turbo',\n      });\n\n      const listener = new StreamingRunnerListener(runner);\n\n      await Promise.all([\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([{ role: 'user', content: 'tell me what the weather is like' }]);\n          for (const choice of contentChoiceDeltas(`The weather is great today!`)) {\n            yield {\n              id: '1',\n              choices: [choice],\n              created: Math.floor(Date.now() / 1000),\n              model: 'gpt-3.5-turbo',\n              object: 'chat.completion.chunk',\n            };\n          }\n        }),\n        runner.done(),\n      ]);\n\n      expect(listener.finalMessage).toEqual({\n        role: 'assistant',\n        content: 'The weather is great today!',\n        parsed: null,\n        refusal: null,\n        tool_calls: undefined,\n      });\n      await listener.sanityCheck();\n    });\n    test('toReadableStream and fromReadableStream', async () => {\n      const { fetch, handleRequest } = mockStreamingChatCompletionFetch();\n\n      const openai = new OpenAI({ apiKey: 'something1234', baseURL: 'http://127.0.0.1:4010', fetch });\n\n      const runner = openai.chat.completions.stream({\n        stream: true,\n        messages: [{ role: 'user', content: 'tell me what the weather is like' }],\n        model: 'gpt-3.5-turbo',\n      });\n\n      const proxied = ChatCompletionStreamingRunner.fromReadableStream(runner.toReadableStream());\n      const listener = new StreamingRunnerListener(proxied);\n\n      await Promise.all([\n        handleRequest(async function* (request): AsyncIterable<OpenAI.Chat.ChatCompletionChunk> {\n          expect(request.messages).toEqual([{ role: 'user', content: 'tell me what the weather is like' }]);\n          for (const choice of contentChoiceDeltas(`The weather is great today!`)) {\n            yield {\n              id: '1',\n              choices: [choice],\n              created: Math.floor(Date.now() / 1000),\n              model: 'gpt-3.5-turbo',\n              object: 'chat.completion.chunk',\n            };\n          }\n        }),\n        proxied.done(),\n      ]);\n\n      expect(listener.finalMessage).toEqual({\n        role: 'assistant',\n        content: 'The weather is great today!',\n        parsed: null,\n        refusal: null,\n        tool_calls: undefined,\n      });\n      await listener.sanityCheck();\n    });\n    test('handles network errors', async () => {\n      const { fetch, handleRequest } = mockFetch();\n\n      const openai = new OpenAI({ apiKey: '...', fetch });\n\n      const stream = openai.chat.completions.stream(\n        {\n          max_tokens: 1024,\n          model: 'gpt-3.5-turbo',\n          messages: [{ role: 'user', content: 'Say hello there!' }],\n        },\n        { maxRetries: 0 },\n      );\n\n      handleRequest(async () => {\n        throw new Error('mock request error');\n      }).catch(() => {});\n\n      async function runStream() {\n        await stream.done();\n      }\n\n      await expect(runStream).rejects.toThrow(APIConnectionError);\n    });\n    test('handles network errors on async iterator', async () => {\n      const { fetch, handleRequest } = mockFetch();\n\n      const openai = new OpenAI({ apiKey: '...', fetch });\n\n      const stream = openai.chat.completions.stream(\n        {\n          max_tokens: 1024,\n          model: 'gpt-3.5-turbo',\n          messages: [{ role: 'user', content: 'Say hello there!' }],\n        },\n        { maxRetries: 0 },\n      );\n\n      handleRequest(async () => {\n        throw new Error('mock request error');\n      }).catch(() => {});\n\n      async function runStream() {\n        for await (const _event of stream) {\n          continue;\n        }\n      }\n\n      await expect(runStream).rejects.toThrow(APIConnectionError);\n    });\n  });\n});\n"
  },
  {
    "path": "tests/lib/ChatCompletionStream.test.ts",
    "content": "import { zodResponseFormat } from 'openai/helpers/zod';\nimport { ChatCompletionTokenLogprob } from 'openai/resources';\nimport { z } from 'zod/v4';\nimport { makeStreamSnapshotRequest } from '../utils/mock-snapshots';\n\njest.setTimeout(1000 * 30);\n\ndescribe('.stream()', () => {\n  it('works', async () => {\n    const stream = await makeStreamSnapshotRequest((openai) =>\n      openai.chat.completions.stream({\n        model: 'gpt-4o-2024-08-06',\n        messages: [\n          {\n            role: 'user',\n            content: \"What's the weather like in SF?\",\n          },\n        ],\n        response_format: zodResponseFormat(\n          z.object({\n            city: z.string(),\n            units: z.enum(['c', 'f']).default('f'),\n          }),\n          'location',\n        ),\n      }),\n    );\n\n    expect((await stream.finalChatCompletion()).choices[0]).toMatchInlineSnapshot(`\n      {\n        \"finish_reason\": \"stop\",\n        \"index\": 0,\n        \"logprobs\": null,\n        \"message\": {\n          \"content\": \"{\"city\":\"San Francisco\",\"units\":\"c\"}\",\n          \"parsed\": {\n            \"city\": \"San Francisco\",\n            \"units\": \"c\",\n          },\n          \"refusal\": null,\n          \"role\": \"assistant\",\n        },\n      }\n    `);\n  });\n\n  it('emits content logprobs events', async () => {\n    var capturedLogProbs: ChatCompletionTokenLogprob[] | undefined;\n\n    const stream = (\n      await makeStreamSnapshotRequest((openai) =>\n        openai.chat.completions.stream({\n          model: 'gpt-4o-2024-08-06',\n          messages: [\n            {\n              role: 'user',\n              content: \"What's the weather like in SF?\",\n            },\n          ],\n          logprobs: true,\n          response_format: zodResponseFormat(\n            z.object({\n              city: z.string(),\n              units: z.enum(['c', 'f']).default('f'),\n            }),\n            'location',\n          ),\n        }),\n      )\n    ).on('logprobs.content.done', (props) => {\n      if (!capturedLogProbs?.length) {\n        capturedLogProbs = props.content;\n      }\n    });\n\n    const choice = (await stream.finalChatCompletion()).choices[0];\n    expect(choice).toMatchInlineSnapshot(`\n      {\n        \"finish_reason\": \"stop\",\n        \"index\": 0,\n        \"logprobs\": {\n          \"content\": [\n            {\n              \"bytes\": [\n                123,\n                34,\n              ],\n              \"logprob\": -0.0036115935,\n              \"token\": \"{\"\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                99,\n                105,\n                116,\n                121,\n              ],\n              \"logprob\": -0.000008418666,\n              \"token\": \"city\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                34,\n                58,\n                34,\n              ],\n              \"logprob\": -0.00034666734,\n              \"token\": \"\":\"\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                83,\n                97,\n                110,\n              ],\n              \"logprob\": -0.013863761,\n              \"token\": \"San\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                32,\n                70,\n                114,\n                97,\n                110,\n                99,\n                105,\n                115,\n                99,\n                111,\n              ],\n              \"logprob\": -0.00003190179,\n              \"token\": \" Francisco\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                34,\n                44,\n                34,\n              ],\n              \"logprob\": -0.03384693,\n              \"token\": \"\",\"\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                117,\n                110,\n                105,\n                116,\n                115,\n              ],\n              \"logprob\": -0.0000012664457,\n              \"token\": \"units\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                34,\n                58,\n                34,\n              ],\n              \"logprob\": -0.000031305768,\n              \"token\": \"\":\"\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                102,\n              ],\n              \"logprob\": -0.5759394,\n              \"token\": \"f\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                34,\n                125,\n              ],\n              \"logprob\": -0.0000420341,\n              \"token\": \"\"}\",\n              \"top_logprobs\": [],\n            },\n          ],\n          \"refusal\": null,\n        },\n        \"message\": {\n          \"content\": \"{\"city\":\"San Francisco\",\"units\":\"f\"}\",\n          \"parsed\": {\n            \"city\": \"San Francisco\",\n            \"units\": \"f\",\n          },\n          \"refusal\": null,\n          \"role\": \"assistant\",\n        },\n      }\n    `);\n    expect(capturedLogProbs?.length).toEqual(choice?.logprobs?.content?.length);\n  });\n\n  it('emits refusal logprobs events', async () => {\n    var capturedLogProbs: ChatCompletionTokenLogprob[] | undefined;\n\n    const stream = (\n      await makeStreamSnapshotRequest((openai) =>\n        openai.chat.completions.stream({\n          model: 'gpt-4o-2024-08-06',\n          messages: [\n            {\n              role: 'user',\n              content: 'a bad question',\n            },\n          ],\n          logprobs: true,\n          response_format: zodResponseFormat(\n            z.object({\n              city: z.string(),\n              units: z.enum(['c', 'f']).default('f'),\n            }),\n            'location',\n          ),\n        }),\n      )\n    ).on('logprobs.refusal.done', (props) => {\n      if (!capturedLogProbs?.length) {\n        capturedLogProbs = props.refusal;\n      }\n    });\n\n    const choice = (await stream.finalChatCompletion()).choices[0];\n    expect(choice).toMatchInlineSnapshot(`\n      {\n        \"finish_reason\": \"stop\",\n        \"index\": 0,\n        \"logprobs\": {\n          \"content\": null,\n          \"refusal\": [\n            {\n              \"bytes\": [\n                73,\n                39,\n                109,\n              ],\n              \"logprob\": -0.0020705638,\n              \"token\": \"I'm\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                32,\n                118,\n                101,\n                114,\n                121,\n              ],\n              \"logprob\": -0.60976714,\n              \"token\": \" very\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                32,\n                115,\n                111,\n                114,\n                114,\n                121,\n              ],\n              \"logprob\": -0.000008180258,\n              \"token\": \" sorry\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                44,\n              ],\n              \"logprob\": -0.000040603656,\n              \"token\": \",\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                32,\n                98,\n                117,\n                116,\n              ],\n              \"logprob\": -0.048603047,\n              \"token\": \" but\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                32,\n                73,\n              ],\n              \"logprob\": -0.003929745,\n              \"token\": \" I\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                32,\n                99,\n                97,\n                110,\n                39,\n                116,\n              ],\n              \"logprob\": -0.012669391,\n              \"token\": \" can't\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                32,\n                97,\n                115,\n                115,\n                105,\n                115,\n                116,\n              ],\n              \"logprob\": -0.0036209812,\n              \"token\": \" assist\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                32,\n                119,\n                105,\n                116,\n                104,\n              ],\n              \"logprob\": -0.0052407524,\n              \"token\": \" with\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                32,\n                116,\n                104,\n                97,\n                116,\n              ],\n              \"logprob\": -0.0029618926,\n              \"token\": \" that\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                32,\n                114,\n                101,\n                113,\n                117,\n                101,\n                115,\n                116,\n              ],\n              \"logprob\": -1.7024335,\n              \"token\": \" request\",\n              \"top_logprobs\": [],\n            },\n            {\n              \"bytes\": [\n                46,\n              ],\n              \"logprob\": -0.0000026968896,\n              \"token\": \".\",\n              \"top_logprobs\": [],\n            },\n          ],\n        },\n        \"message\": {\n          \"content\": null,\n          \"parsed\": null,\n          \"refusal\": \"I'm very sorry, but I can't assist with that request.\",\n          \"role\": \"assistant\",\n        },\n      }\n    `);\n    expect(capturedLogProbs?.length).toEqual(choice?.logprobs?.refusal?.length);\n  });\n});\n"
  },
  {
    "path": "tests/lib/ResponseStream.test.ts",
    "content": "import { makeStreamSnapshotRequest } from '../utils/mock-snapshots';\n\njest.setTimeout(1000 * 30);\n\ndescribe('.stream()', () => {\n  it('standard text works', async () => {\n    const deltas: string[] = [];\n\n    const stream = (\n      await makeStreamSnapshotRequest((openai) =>\n        openai.responses.stream({\n          model: 'gpt-4o-2024-08-06',\n          input: 'Say hello world',\n        }),\n      )\n    ).on('response.output_text.delta', (e) => {\n      deltas.push(e.snapshot);\n    });\n\n    const final = await stream.finalResponse();\n    expect(final.output_text).toBe('Hello world');\n    expect(deltas).toEqual(['Hello ', 'Hello world']);\n\n    // basic shape checks\n    expect(final.object).toBe('response');\n    expect(final.output[0]?.type).toBe('message');\n    // message should contain a single output_text part with the final text\n    const msg = final.output[0];\n    if (msg?.type === 'message') {\n      expect(msg.content[0]).toMatchObject({ type: 'output_text', text: 'Hello world' });\n    }\n  });\n\n  it('reasoning works', async () => {\n    const stream = await makeStreamSnapshotRequest((openai) =>\n      openai.responses.stream({\n        model: 'o3',\n        input: 'Compute 6 * 7',\n        reasoning: { effort: 'medium' },\n      }),\n    );\n\n    const final = await stream.finalResponse();\n    expect(final.object).toBe('response');\n    // first item should be reasoning with accumulated text\n    expect(final.output[0]?.type).toBe('reasoning');\n    if (final.output[0]?.type === 'reasoning') {\n      expect(final.output[0].content?.[0]).toMatchObject({\n        type: 'reasoning_text',\n        text: 'Chain: Step 1. Step 2.',\n      });\n    }\n    // second item should be the assistant message with the final text\n    expect(final.output[1]?.type).toBe('message');\n    if (final.output[1]?.type === 'message') {\n      expect(final.output[1].content[0]).toMatchObject({ type: 'output_text', text: 'The answer is 42' });\n    }\n    expect(final.output_text).toBe('The answer is 42');\n  });\n});\n"
  },
  {
    "path": "tests/lib/__snapshots__/ChatCompletionStream.test.ts.snap",
    "content": "// Jest Snapshot v1, https://goo.gl/fbAQLP\n\nexports[`.stream() emits content logprobs events 1`] = `\n\"data: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"refusal\":null},\"logprobs\":{\"content\":[],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"{\\\\\"\"},\"logprobs\":{\"content\":[{\"token\":\"{\\\\\"\",\"logprob\":-0.0036115935,\"bytes\":[123,34],\"top_logprobs\":[]}],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"city\"},\"logprobs\":{\"content\":[{\"token\":\"city\",\"logprob\":-8.418666e-6,\"bytes\":[99,105,116,121],\"top_logprobs\":[]}],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\\\\\":\\\\\"\"},\"logprobs\":{\"content\":[{\"token\":\"\\\\\":\\\\\"\",\"logprob\":-0.00034666734,\"bytes\":[34,58,34],\"top_logprobs\":[]}],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"San\"},\"logprobs\":{\"content\":[{\"token\":\"San\",\"logprob\":-0.013863761,\"bytes\":[83,97,110],\"top_logprobs\":[]}],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\" Francisco\"},\"logprobs\":{\"content\":[{\"token\":\" Francisco\",\"logprob\":-0.00003190179,\"bytes\":[32,70,114,97,110,99,105,115,99,111],\"top_logprobs\":[]}],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\\\\\",\\\\\"\"},\"logprobs\":{\"content\":[{\"token\":\"\\\\\",\\\\\"\",\"logprob\":-0.03384693,\"bytes\":[34,44,34],\"top_logprobs\":[]}],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"units\"},\"logprobs\":{\"content\":[{\"token\":\"units\",\"logprob\":-1.2664457e-6,\"bytes\":[117,110,105,116,115],\"top_logprobs\":[]}],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\\\\\":\\\\\"\"},\"logprobs\":{\"content\":[{\"token\":\"\\\\\":\\\\\"\",\"logprob\":-0.000031305768,\"bytes\":[34,58,34],\"top_logprobs\":[]}],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"f\"},\"logprobs\":{\"content\":[{\"token\":\"f\",\"logprob\":-0.5759394,\"bytes\":[102],\"top_logprobs\":[]}],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\\\\\"}\"},\"logprobs\":{\"content\":[{\"token\":\"\\\\\"}\",\"logprob\":-0.0000420341,\"bytes\":[34,125],\"top_logprobs\":[]}],\"refusal\":null},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{},\"logprobs\":null,\"finish_reason\":\"stop\"}]}\n\ndata: {\"id\":\"chatcmpl-9tZXFsqeQOozn5YU8I6SbjkmDnN76\",\"object\":\"chat.completion.chunk\",\"created\":1723031665,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[],\"usage\":{\"prompt_tokens\":17,\"completion_tokens\":10,\"total_tokens\":27}}\n\ndata: [DONE]\n\n\"\n`;\n\nexports[`.stream() emits refusal logprobs events 1`] = `\n\"data: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":null,\"refusal\":\"\"},\"logprobs\":{\"content\":null,\"refusal\":[]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\"I'm\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\"I'm\",\"logprob\":-0.0020705638,\"bytes\":[73,39,109],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\" very\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\" very\",\"logprob\":-0.60976714,\"bytes\":[32,118,101,114,121],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\" sorry\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\" sorry\",\"logprob\":-8.180258e-6,\"bytes\":[32,115,111,114,114,121],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\",\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\",\",\"logprob\":-0.000040603656,\"bytes\":[44],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\" but\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\" but\",\"logprob\":-0.048603047,\"bytes\":[32,98,117,116],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\" I\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\" I\",\"logprob\":-0.003929745,\"bytes\":[32,73],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\" can't\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\" can't\",\"logprob\":-0.012669391,\"bytes\":[32,99,97,110,39,116],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\" assist\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\" assist\",\"logprob\":-0.0036209812,\"bytes\":[32,97,115,115,105,115,116],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\" with\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\" with\",\"logprob\":-0.0052407524,\"bytes\":[32,119,105,116,104],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\" that\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\" that\",\"logprob\":-0.0029618926,\"bytes\":[32,116,104,97,116],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\" request\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\" request\",\"logprob\":-1.7024335,\"bytes\":[32,114,101,113,117,101,115,116],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{\"refusal\":\".\"},\"logprobs\":{\"content\":null,\"refusal\":[{\"token\":\".\",\"logprob\":-2.6968896e-6,\"bytes\":[46],\"top_logprobs\":[]}]},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[{\"index\":0,\"delta\":{},\"logprobs\":null,\"finish_reason\":\"stop\"}]}\n\ndata: {\"id\":\"chatcmpl-9tZXGacdbmJYO8K50haE4OauaJmPn\",\"object\":\"chat.completion.chunk\",\"created\":1723031666,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_2a322c9ffc\",\"choices\":[],\"usage\":{\"prompt_tokens\":17,\"completion_tokens\":13,\"total_tokens\":30}}\n\ndata: [DONE]\n\n\"\n`;\n\nexports[`.stream() works 1`] = `\n\"data: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"refusal\":null},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"{\\\\\"\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"city\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\\\\\":\\\\\"\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"San\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\" Francisco\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\\\\\",\\\\\"\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"units\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\\\\\":\\\\\"\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"c\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\\\\\"}\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[{\"index\":0,\"delta\":{},\"logprobs\":null,\"finish_reason\":\"stop\"}]}\n\ndata: {\"id\":\"chatcmpl-9tZXEmwtoDf6vqCqEWSvDP8jx9OXe\",\"object\":\"chat.completion.chunk\",\"created\":1723031664,\"model\":\"gpt-4o-2024-08-06\",\"system_fingerprint\":\"fp_845eaabc1f\",\"choices\":[],\"usage\":{\"prompt_tokens\":17,\"completion_tokens\":10,\"total_tokens\":27}}\n\ndata: [DONE]\n\n\"\n`;\n"
  },
  {
    "path": "tests/lib/__snapshots__/ResponseStream.test.ts.snap",
    "content": "// Jest Snapshot v1, https://goo.gl/fbAQLP\n\nexports[`.stream() standard text works 1`] = `\n\"data: {\\\"response\\\":{\\\"id\\\":\\\"resp_test_1\\\",\\\"object\\\":\\\"response\\\",\\\"created_at\\\":1723031665,\\\"model\\\":\\\"gpt-4o-2024-08-06\\\",\\\"output\\\":[],\\\"output_text\\\":\\\"\\\",\\\"error\\\":null,\\\"incomplete_details\\\":null,\\\"instructions\\\":null,\\\"metadata\\\":null,\\\"parallel_tool_calls\\\":false,\\\"temperature\\\":null,\\\"tools\\\":[],\\\"top_p\\\":null,\\\"status\\\":\\\"in_progress\\\",\\\"usage\\\":{\\\"input_tokens\\\":0,\\\"input_tokens_details\\\":{\\\"cached_tokens\\\":0},\\\"output_tokens\\\":0,\\\"output_tokens_details\\\":{\\\"reasoning_tokens\\\":0},\\\"total_tokens\\\":0}},\\\"sequence_number\\\":0,\\\"type\\\":\\\"response.created\\\"}\n\ndata: {\\\"item\\\":{\\\"id\\\":\\\"msg_1\\\",\\\"type\\\":\\\"message\\\",\\\"role\\\":\\\"assistant\\\",\\\"status\\\":\\\"in_progress\\\",\\\"content\\\":[]},\\\"output_index\\\":0,\\\"sequence_number\\\":1,\\\"type\\\":\\\"response.output_item.added\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"item_id\\\":\\\"msg_1\\\",\\\"output_index\\\":0,\\\"part\\\":{\\\"type\\\":\\\"output_text\\\",\\\"text\\\":\\\"\\\",\\\"annotations\\\":[]},\\\"sequence_number\\\":2,\\\"type\\\":\\\"response.content_part.added\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"delta\\\":\\\"Hello \\\",\\\"item_id\\\":\\\"msg_1\\\",\\\"logprobs\\\":[],\\\"output_index\\\":0,\\\"sequence_number\\\":3,\\\"type\\\":\\\"response.output_text.delta\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"delta\\\":\\\"world\\\",\\\"item_id\\\":\\\"msg_1\\\",\\\"logprobs\\\":[],\\\"output_index\\\":0,\\\"sequence_number\\\":4,\\\"type\\\":\\\"response.output_text.delta\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"item_id\\\":\\\"msg_1\\\",\\\"logprobs\\\":[],\\\"output_index\\\":0,\\\"sequence_number\\\":5,\\\"text\\\":\\\"Hello world\\\",\\\"type\\\":\\\"response.output_text.done\\\"}\n\ndata: {\\\"item\\\":{\\\"id\\\":\\\"msg_1\\\",\\\"type\\\":\\\"message\\\",\\\"role\\\":\\\"assistant\\\",\\\"status\\\":\\\"completed\\\",\\\"content\\\":[{\\\"type\\\":\\\"output_text\\\",\\\"text\\\":\\\"Hello world\\\",\\\"annotations\\\":[]}]},\\\"output_index\\\":0,\\\"sequence_number\\\":6,\\\"type\\\":\\\"response.output_item.done\\\"}\n\ndata: {\\\"response\\\":{\\\"id\\\":\\\"resp_test_1\\\",\\\"object\\\":\\\"response\\\",\\\"created_at\\\":1723031665,\\\"model\\\":\\\"gpt-4o-2024-08-06\\\",\\\"output\\\":[{\\\"id\\\":\\\"msg_1\\\",\\\"type\\\":\\\"message\\\",\\\"role\\\":\\\"assistant\\\",\\\"status\\\":\\\"completed\\\",\\\"content\\\":[{\\\"type\\\":\\\"output_text\\\",\\\"text\\\":\\\"Hello world\\\",\\\"annotations\\\":[]}]}],\\\"output_text\\\":\\\"Hello world\\\",\\\"error\\\":null,\\\"incomplete_details\\\":null,\\\"instructions\\\":null,\\\"metadata\\\":null,\\\"parallel_tool_calls\\\":false,\\\"temperature\\\":null,\\\"tools\\\":[],\\\"top_p\\\":null,\\\"status\\\":\\\"completed\\\",\\\"usage\\\":{\\\"input_tokens\\\":10,\\\"input_tokens_details\\\":{\\\"cached_tokens\\\":0},\\\"output_tokens\\\":2,\\\"output_tokens_details\\\":{\\\"reasoning_tokens\\\":0},\\\"total_tokens\\\":12}},\\\"sequence_number\\\":7,\\\"type\\\":\\\"response.completed\\\"}\n\ndata: [DONE]\n\n\"\n`;\n\nexports[`.stream() reasoning works 1`] = `\n\"data: {\\\"response\\\":{\\\"id\\\":\\\"resp_reason_1\\\",\\\"object\\\":\\\"response\\\",\\\"created_at\\\":1723031666,\\\"model\\\":\\\"o3\\\",\\\"output\\\":[],\\\"output_text\\\":\\\"\\\",\\\"error\\\":null,\\\"incomplete_details\\\":null,\\\"instructions\\\":null,\\\"metadata\\\":null,\\\"parallel_tool_calls\\\":false,\\\"temperature\\\":null,\\\"tools\\\":[],\\\"top_p\\\":null,\\\"status\\\":\\\"in_progress\\\",\\\"usage\\\":{\\\"input_tokens\\\":0,\\\"input_tokens_details\\\":{\\\"cached_tokens\\\":0},\\\"output_tokens\\\":0,\\\"output_tokens_details\\\":{\\\"reasoning_tokens\\\":0},\\\"total_tokens\\\":0}},\\\"sequence_number\\\":0,\\\"type\\\":\\\"response.created\\\"}\n\ndata: {\\\"item\\\":{\\\"id\\\":\\\"r1\\\",\\\"type\\\":\\\"reasoning\\\",\\\"summary\\\":[],\\\"status\\\":\\\"in_progress\\\"},\\\"output_index\\\":0,\\\"sequence_number\\\":1,\\\"type\\\":\\\"response.output_item.added\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"item_id\\\":\\\"r1\\\",\\\"output_index\\\":0,\\\"part\\\":{\\\"type\\\":\\\"reasoning_text\\\",\\\"text\\\":\\\"\\\"},\\\"sequence_number\\\":2,\\\"type\\\":\\\"response.content_part.added\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"delta\\\":\\\"Chain: Step 1. \\\",\\\"item_id\\\":\\\"r1\\\",\\\"output_index\\\":0,\\\"sequence_number\\\":3,\\\"type\\\":\\\"response.reasoning_text.delta\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"delta\\\":\\\"Step 2.\\\",\\\"item_id\\\":\\\"r1\\\",\\\"output_index\\\":0,\\\"sequence_number\\\":4,\\\"type\\\":\\\"response.reasoning_text.delta\\\"}\n\ndata: {\\\"item\\\":{\\\"id\\\":\\\"msg_2\\\",\\\"type\\\":\\\"message\\\",\\\"role\\\":\\\"assistant\\\",\\\"status\\\":\\\"in_progress\\\",\\\"content\\\":[]},\\\"output_index\\\":1,\\\"sequence_number\\\":5,\\\"type\\\":\\\"response.output_item.added\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"item_id\\\":\\\"msg_2\\\",\\\"output_index\\\":1,\\\"part\\\":{\\\"type\\\":\\\"output_text\\\",\\\"text\\\":\\\"\\\",\\\"annotations\\\":[]},\\\"sequence_number\\\":6,\\\"type\\\":\\\"response.content_part.added\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"delta\\\":\\\"The answer is \\\",\\\"item_id\\\":\\\"msg_2\\\",\\\"logprobs\\\":[],\\\"output_index\\\":1,\\\"sequence_number\\\":7,\\\"type\\\":\\\"response.output_text.delta\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"delta\\\":\\\"42\\\",\\\"item_id\\\":\\\"msg_2\\\",\\\"logprobs\\\":[],\\\"output_index\\\":1,\\\"sequence_number\\\":8,\\\"type\\\":\\\"response.output_text.delta\\\"}\n\ndata: {\\\"content_index\\\":0,\\\"item_id\\\":\\\"msg_2\\\",\\\"logprobs\\\":[],\\\"output_index\\\":1,\\\"sequence_number\\\":9,\\\"text\\\":\\\"The answer is 42\\\",\\\"type\\\":\\\"response.output_text.done\\\"}\n\ndata: {\\\"response\\\":{\\\"id\\\":\\\"resp_reason_1\\\",\\\"object\\\":\\\"response\\\",\\\"created_at\\\":1723031666,\\\"model\\\":\\\"o3\\\",\\\"output\\\":[{\\\"id\\\":\\\"r1\\\",\\\"type\\\":\\\"reasoning\\\",\\\"summary\\\":[],\\\"status\\\":\\\"completed\\\",\\\"content\\\":[{\\\"type\\\":\\\"reasoning_text\\\",\\\"text\\\":\\\"Chain: Step 1. Step 2.\\\"}]},{\\\"id\\\":\\\"msg_2\\\",\\\"type\\\":\\\"message\\\",\\\"role\\\":\\\"assistant\\\",\\\"status\\\":\\\"completed\\\",\\\"content\\\":[{\\\"type\\\":\\\"output_text\\\",\\\"text\\\":\\\"The answer is 42\\\",\\\"annotations\\\":[]}]}],\\\"output_text\\\":\\\"The answer is 42\\\",\\\"error\\\":null,\\\"incomplete_details\\\":null,\\\"instructions\\\":null,\\\"metadata\\\":null,\\\"parallel_tool_calls\\\":false,\\\"temperature\\\":null,\\\"tools\\\":[],\\\"top_p\\\":null,\\\"status\\\":\\\"completed\\\",\\\"usage\\\":{\\\"input_tokens\\\":0,\\\"input_tokens_details\\\":{\\\"cached_tokens\\\":0},\\\"output_tokens\\\":6,\\\"output_tokens_details\\\":{\\\"reasoning_tokens\\\":2},\\\"total_tokens\\\":6}},\\\"sequence_number\\\":10,\\\"type\\\":\\\"response.completed\\\"}\n\ndata: [DONE]\n\n\"\n`;\n\n"
  },
  {
    "path": "tests/lib/__snapshots__/parser.test.ts.snap",
    "content": "// Jest Snapshot v1, https://goo.gl/fbAQLP\n\nexports[`.parse() zod deserialises response_format 1`] = `\n\"{\n  \"id\": \"chatcmpl-9uLhvwLPvKOZoJ7hwaa666fYuxYif\",\n  \"object\": \"chat.completion\",\n  \"created\": 1723216839,\n  \"model\": \"gpt-4o-2024-08-06\",\n  \"choices\": [\n    {\n      \"index\": 0,\n      \"message\": {\n        \"role\": \"assistant\",\n        \"content\": \"{\\\\\"city\\\\\":\\\\\"San Francisco\\\\\",\\\\\"units\\\\\":\\\\\"c\\\\\"}\",\n        \"refusal\": null\n      },\n      \"logprobs\": null,\n      \"finish_reason\": \"stop\"\n    }\n  ],\n  \"usage\": {\n    \"prompt_tokens\": 17,\n    \"completion_tokens\": 10,\n    \"total_tokens\": 27\n  },\n  \"system_fingerprint\": \"fp_2a322c9ffc\"\n}\n\"\n`;\n\nexports[`.parse() zod merged schemas 2`] = `\n\"{\n  \"id\": \"chatcmpl-9uLi0HJ6HYH0FM1VI1N6XCREiGvX1\",\n  \"object\": \"chat.completion\",\n  \"created\": 1723216844,\n  \"model\": \"gpt-4o-2024-08-06\",\n  \"choices\": [\n    {\n      \"index\": 0,\n      \"message\": {\n        \"role\": \"assistant\",\n        \"content\": \"{\\\\\"person1\\\\\":{\\\\\"name\\\\\":\\\\\"Jane Doe\\\\\",\\\\\"phone_number\\\\\":\\\\\".\\\\\",\\\\\"roles\\\\\":[\\\\\"other\\\\\"],\\\\\"description\\\\\":\\\\\"Engineer at OpenAI, born Nov 16, contact email: jane@openai.com\\\\\"},\\\\\"person2\\\\\":{\\\\\"name\\\\\":\\\\\"John Smith\\\\\",\\\\\"phone_number\\\\\":\\\\\"john@openai.com\\\\\",\\\\\"differentField\\\\\":\\\\\"Engineer at OpenAI, born March 1.\\\\\"}}\",\n        \"refusal\": null\n      },\n      \"logprobs\": null,\n      \"finish_reason\": \"stop\"\n    }\n  ],\n  \"usage\": {\n    \"prompt_tokens\": 61,\n    \"completion_tokens\": 72,\n    \"total_tokens\": 133\n  },\n  \"system_fingerprint\": \"fp_2a322c9ffc\"\n}\n\"\n`;\n\nexports[`.parse() zod nested schema extraction 2`] = `\n\"{\n  \"id\": \"chatcmpl-9uLi6hkH6VcoaYiNEzy3h56QRAyns\",\n  \"object\": \"chat.completion\",\n  \"created\": 1723216850,\n  \"model\": \"gpt-4o-2024-08-06\",\n  \"choices\": [\n    {\n      \"index\": 0,\n      \"message\": {\n        \"role\": \"assistant\",\n        \"content\": \"{\\\\\"name\\\\\":\\\\\"TodoApp\\\\\",\\\\\"fields\\\\\":[{\\\\\"type\\\\\":\\\\\"string\\\\\",\\\\\"name\\\\\":\\\\\"taskId\\\\\",\\\\\"metadata\\\\\":{\\\\\"foo\\\\\":\\\\\"unique identifier for each task\\\\\"}},{\\\\\"type\\\\\":\\\\\"string\\\\\",\\\\\"name\\\\\":\\\\\"title\\\\\",\\\\\"metadata\\\\\":{\\\\\"foo\\\\\":\\\\\"title of the task\\\\\"}},{\\\\\"type\\\\\":\\\\\"string\\\\\",\\\\\"name\\\\\":\\\\\"description\\\\\",\\\\\"metadata\\\\\":{\\\\\"foo\\\\\":\\\\\"detailed description of the task. This is optional.\\\\\"}},{\\\\\"type\\\\\":\\\\\"string\\\\\",\\\\\"name\\\\\":\\\\\"status\\\\\",\\\\\"metadata\\\\\":{\\\\\"foo\\\\\":\\\\\"status of the task, e.g., pending, completed, etc.\\\\\"}},{\\\\\"type\\\\\":\\\\\"string\\\\\",\\\\\"name\\\\\":\\\\\"dueDate\\\\\",\\\\\"metadata\\\\\":null},{\\\\\"type\\\\\":\\\\\"string\\\\\",\\\\\"name\\\\\":\\\\\"priority\\\\\",\\\\\"metadata\\\\\":{\\\\\"foo\\\\\":\\\\\"priority level of the task, e.g., low, medium, high\\\\\"}},{\\\\\"type\\\\\":\\\\\"string\\\\\",\\\\\"name\\\\\":\\\\\"creationDate\\\\\",\\\\\"metadata\\\\\":{\\\\\"foo\\\\\":\\\\\"date when the task was created\\\\\"}},{\\\\\"type\\\\\":\\\\\"string\\\\\",\\\\\"name\\\\\":\\\\\"lastModifiedDate\\\\\",\\\\\"metadata\\\\\":{\\\\\"foo\\\\\":\\\\\"date when the task was last modified\\\\\"}},{\\\\\"type\\\\\":\\\\\"string\\\\\",\\\\\"name\\\\\":\\\\\"tags\\\\\",\\\\\"metadata\\\\\":{\\\\\"foo\\\\\":\\\\\"tags associated with the task, for categorization\\\\\"}}]}\",\n        \"refusal\": null\n      },\n      \"logprobs\": null,\n      \"finish_reason\": \"stop\"\n    }\n  ],\n  \"usage\": {\n    \"prompt_tokens\": 36,\n    \"completion_tokens\": 208,\n    \"total_tokens\": 244\n  },\n  \"system_fingerprint\": \"fp_2a322c9ffc\"\n}\n\"\n`;\n\nexports[`.parse() zod recursive schema extraction 2`] = `\n\"{\n  \"id\": \"chatcmpl-9vdbw9dekyUSEsSKVQDhTxA2RCxcK\",\n  \"object\": \"chat.completion\",\n  \"created\": 1723523988,\n  \"model\": \"gpt-4o-2024-08-06\",\n  \"choices\": [\n    {\n      \"index\": 0,\n      \"message\": {\n        \"role\": \"assistant\",\n        \"content\": \"{\\\\\"linked_list\\\\\":{\\\\\"value\\\\\":1,\\\\\"next\\\\\":{\\\\\"value\\\\\":2,\\\\\"next\\\\\":{\\\\\"value\\\\\":3,\\\\\"next\\\\\":{\\\\\"value\\\\\":4,\\\\\"next\\\\\":{\\\\\"value\\\\\":5,\\\\\"next\\\\\":null}}}}}}\",\n        \"refusal\": null\n      },\n      \"logprobs\": null,\n      \"finish_reason\": \"stop\"\n    }\n  ],\n  \"usage\": {\n    \"prompt_tokens\": 40,\n    \"completion_tokens\": 38,\n    \"total_tokens\": 78\n  },\n  \"system_fingerprint\": \"fp_2a322c9ffc\"\n}\n\"\n`;\n\nexports[`.parse() zod ref schemas with \\`.transform()\\` 2`] = `\n\"{\n  \"id\": \"chatcmpl-A6zyLEtubMlUvGplOmr92S0mK0kiG\",\n  \"object\": \"chat.completion\",\n  \"created\": 1726231553,\n  \"model\": \"gpt-4o-2024-08-06\",\n  \"choices\": [\n    {\n      \"index\": 0,\n      \"message\": {\n        \"role\": \"assistant\",\n        \"content\": \"{\\\\\"first\\\\\":{\\\\\"baz\\\\\":true},\\\\\"second\\\\\":{\\\\\"baz\\\\\":false}}\",\n        \"refusal\": null\n      },\n      \"logprobs\": null,\n      \"finish_reason\": \"stop\"\n    }\n  ],\n  \"usage\": {\n    \"prompt_tokens\": 167,\n    \"completion_tokens\": 13,\n    \"total_tokens\": 180,\n    \"completion_tokens_details\": {\n      \"reasoning_tokens\": 0\n    }\n  },\n  \"system_fingerprint\": \"fp_143bb8492c\"\n}\n\"\n`;\n\nexports[`.parse() zod top-level recursive schemas 1`] = `\n\"{\n  \"id\": \"chatcmpl-9uLhw79ArBF4KsQQOlsoE68m6vh6v\",\n  \"object\": \"chat.completion\",\n  \"created\": 1723216840,\n  \"model\": \"gpt-4o-2024-08-06\",\n  \"choices\": [\n    {\n      \"index\": 0,\n      \"message\": {\n        \"role\": \"assistant\",\n        \"content\": \"{\\\\\"type\\\\\":\\\\\"form\\\\\",\\\\\"label\\\\\":\\\\\"User Profile Form\\\\\",\\\\\"children\\\\\":[{\\\\\"type\\\\\":\\\\\"field\\\\\",\\\\\"label\\\\\":\\\\\"First Name\\\\\",\\\\\"children\\\\\":[],\\\\\"attributes\\\\\":[{\\\\\"name\\\\\":\\\\\"type\\\\\",\\\\\"value\\\\\":\\\\\"text\\\\\"},{\\\\\"name\\\\\":\\\\\"name\\\\\",\\\\\"value\\\\\":\\\\\"firstName\\\\\"},{\\\\\"name\\\\\":\\\\\"placeholder\\\\\",\\\\\"value\\\\\":\\\\\"Enter your first name\\\\\"}]},{\\\\\"type\\\\\":\\\\\"field\\\\\",\\\\\"label\\\\\":\\\\\"Last Name\\\\\",\\\\\"children\\\\\":[],\\\\\"attributes\\\\\":[{\\\\\"name\\\\\":\\\\\"type\\\\\",\\\\\"value\\\\\":\\\\\"text\\\\\"},{\\\\\"name\\\\\":\\\\\"name\\\\\",\\\\\"value\\\\\":\\\\\"lastName\\\\\"},{\\\\\"name\\\\\":\\\\\"placeholder\\\\\",\\\\\"value\\\\\":\\\\\"Enter your last name\\\\\"}]},{\\\\\"type\\\\\":\\\\\"field\\\\\",\\\\\"label\\\\\":\\\\\"Email Address\\\\\",\\\\\"children\\\\\":[],\\\\\"attributes\\\\\":[{\\\\\"name\\\\\":\\\\\"type\\\\\",\\\\\"value\\\\\":\\\\\"email\\\\\"},{\\\\\"name\\\\\":\\\\\"name\\\\\",\\\\\"value\\\\\":\\\\\"email\\\\\"},{\\\\\"name\\\\\":\\\\\"placeholder\\\\\",\\\\\"value\\\\\":\\\\\"Enter your email address\\\\\"}]},{\\\\\"type\\\\\":\\\\\"button\\\\\",\\\\\"label\\\\\":\\\\\"Submit\\\\\",\\\\\"children\\\\\":[],\\\\\"attributes\\\\\":[{\\\\\"name\\\\\":\\\\\"type\\\\\",\\\\\"value\\\\\":\\\\\"submit\\\\\"}]}],\\\\\"attributes\\\\\":[]}\",\n        \"refusal\": null\n      },\n      \"logprobs\": null,\n      \"finish_reason\": \"stop\"\n    }\n  ],\n  \"usage\": {\n    \"prompt_tokens\": 38,\n    \"completion_tokens\": 175,\n    \"total_tokens\": 213\n  },\n  \"system_fingerprint\": \"fp_845eaabc1f\"\n}\n\"\n`;\n"
  },
  {
    "path": "tests/lib/azure.test.ts",
    "content": "import { AzureOpenAI } from 'openai';\nimport { APIUserAbortError } from 'openai';\nimport { type Response, RequestInit, RequestInfo } from 'openai/internal/builtin-types';\n\nconst defaultFetch = fetch;\n\nconst apiVersion = '2024-02-15-preview';\nconst deployment = 'deployment';\nconst model = 'unused model';\n\ndescribe('instantiate azure client', () => {\n  const env = process.env;\n\n  beforeEach(() => {\n    jest.resetModules();\n    process.env = { ...env };\n\n    console.warn = jest.fn();\n  });\n\n  afterEach(() => {\n    process.env = env;\n  });\n\n  describe('defaultHeaders', () => {\n    const client = new AzureOpenAI({\n      baseURL: 'http://localhost:5000/',\n      defaultHeaders: { 'X-My-Default-Header': '2' },\n      apiKey: 'My API Key',\n      apiVersion,\n    });\n\n    test('they are used in the request', async () => {\n      const { req } = await client.buildRequest({ path: '/foo', method: 'post' });\n      expect(req.headers.get('x-my-default-header')).toEqual('2');\n    });\n\n    test('can ignore `undefined` and leave the default', async () => {\n      const { req } = await client.buildRequest({\n        path: '/foo',\n        method: 'post',\n        headers: { 'X-My-Default-Header': undefined },\n      });\n      expect(req.headers.get('x-my-default-header')).toEqual('2');\n    });\n\n    test('can be removed with `null`', async () => {\n      const { req } = await client.buildRequest({\n        path: '/foo',\n        method: 'post',\n        headers: { 'X-My-Default-Header': null },\n      });\n      expect(req.headers.has('x-my-default-header')).toBe(false);\n    });\n\n    test('includes retry count', async () => {\n      const { req } = await client.buildRequest(\n        {\n          path: '/foo',\n          method: 'post',\n          headers: { 'X-My-Default-Header': null },\n        },\n        { retryCount: 1 },\n      );\n      expect(req.headers.get('x-stainless-retry-count')).toEqual('1');\n    });\n  });\n\n  describe('defaultQuery', () => {\n    test('with null query params given', () => {\n      const client = new AzureOpenAI({\n        baseURL: 'http://localhost:5000/',\n        defaultQuery: { apiVersion: 'foo' },\n        apiKey: 'My API Key',\n        apiVersion,\n      });\n      expect(client.buildURL('/foo', null)).toEqual(\n        `http://localhost:5000/foo?apiVersion=foo&api-version=${apiVersion}`,\n      );\n    });\n\n    test('multiple default query params', () => {\n      const client = new AzureOpenAI({\n        baseURL: 'http://localhost:5000/',\n        defaultQuery: { apiVersion: 'foo', hello: 'world' },\n        apiKey: 'My API Key',\n        apiVersion,\n      });\n      expect(client.buildURL('/foo', null)).toEqual(\n        `http://localhost:5000/foo?apiVersion=foo&hello=world&api-version=${apiVersion}`,\n      );\n    });\n\n    test('overriding with `undefined`', () => {\n      const client = new AzureOpenAI({\n        baseURL: 'http://localhost:5000/',\n        defaultQuery: { hello: 'world' },\n        apiKey: 'My API Key',\n        apiVersion,\n      });\n      expect(client.buildURL('/foo', { hello: undefined })).toEqual(\n        `http://localhost:5000/foo?api-version=${apiVersion}`,\n      );\n    });\n  });\n\n  test('custom fetch', async () => {\n    const client = new AzureOpenAI({\n      baseURL: 'http://localhost:5000/',\n      apiKey: 'My API Key',\n      apiVersion,\n      fetch: (url) => {\n        return Promise.resolve(\n          new Response(JSON.stringify({ url, custom: true }), {\n            headers: { 'Content-Type': 'application/json' },\n          }),\n        );\n      },\n    });\n\n    const response = await client.get('/foo');\n    expect(response).toEqual({ url: `http://localhost:5000/foo?api-version=${apiVersion}`, custom: true });\n  });\n\n  test('custom signal', async () => {\n    const client = new AzureOpenAI({\n      baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n      apiKey: 'My API Key',\n      apiVersion,\n      fetch: (...args) => {\n        return new Promise((resolve, reject) =>\n          setTimeout(\n            () =>\n              defaultFetch(...args)\n                .then(resolve)\n                .catch(reject),\n            300,\n          ),\n        );\n      },\n    });\n\n    const controller = new AbortController();\n    setTimeout(() => controller.abort(), 200);\n\n    const spy = jest.spyOn(client, 'request');\n\n    await expect(client.get('/foo', { signal: controller.signal })).rejects.toThrowError(APIUserAbortError);\n    expect(spy).toHaveBeenCalledTimes(1);\n  });\n\n  describe('baseUrl', () => {\n    test('trailing slash', () => {\n      const client = new AzureOpenAI({\n        baseURL: 'http://localhost:5000/custom/path/',\n        apiKey: 'My API Key',\n        apiVersion,\n      });\n      expect(client.buildURL('/foo', null)).toEqual(\n        `http://localhost:5000/custom/path/foo?api-version=${apiVersion}`,\n      );\n    });\n\n    test('no trailing slash', () => {\n      const client = new AzureOpenAI({\n        baseURL: 'http://localhost:5000/custom/path',\n        apiKey: 'My API Key',\n        apiVersion,\n      });\n      expect(client.buildURL('/foo', null)).toEqual(\n        `http://localhost:5000/custom/path/foo?api-version=${apiVersion}`,\n      );\n    });\n\n    afterEach(() => {\n      process.env['OPENAI_BASE_URL'] = undefined;\n    });\n\n    test('explicit option', () => {\n      const client = new AzureOpenAI({ baseURL: 'https://example.com', apiKey: 'My API Key', apiVersion });\n      expect(client.baseURL).toEqual('https://example.com');\n    });\n\n    test('env variable', () => {\n      process.env['OPENAI_BASE_URL'] = 'https://example.com/from_env';\n      const client = new AzureOpenAI({ apiKey: 'My API Key', apiVersion });\n      expect(client.baseURL).toEqual('https://example.com/from_env');\n    });\n\n    test('empty baseUrl/endpoint env variable', () => {\n      process.env['OPENAI_BASE_URL'] = ''; // empty\n      expect(() => new AzureOpenAI({ apiKey: 'My API Key', apiVersion })).toThrow(\n        /Must provide one of the `baseURL` or `endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable/,\n      );\n    });\n\n    test('blank baseUrl/endpoint env variable', () => {\n      process.env['OPENAI_BASE_URL'] = '  '; // blank\n      expect(() => new AzureOpenAI({ apiKey: 'My API Key', apiVersion })).toThrow(\n        /Must provide one of the `baseURL` or `endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable/,\n      );\n    });\n  });\n\n  test('maxRetries option is correctly set', () => {\n    const client = new AzureOpenAI({\n      baseURL: 'https://example.com',\n      maxRetries: 4,\n      apiKey: 'My API Key',\n      apiVersion,\n    });\n    expect(client.maxRetries).toEqual(4);\n\n    // default\n    const client2 = new AzureOpenAI({ baseURL: 'https://example.com', apiKey: 'My API Key', apiVersion });\n    expect(client2.maxRetries).toEqual(2);\n  });\n\n  test('with environment variable arguments', () => {\n    // set options via env var\n    process.env['OPENAI_BASE_URL'] = 'https://example.com';\n    process.env['AZURE_OPENAI_API_KEY'] = 'My API Key';\n    process.env['OPENAI_API_VERSION'] = 'My API Version';\n    const client = new AzureOpenAI();\n    expect(client.baseURL).toBe('https://example.com');\n    expect(client.apiKey).toBe('My API Key');\n    expect(client.apiVersion).toBe('My API Version');\n  });\n\n  test('with overriden environment variable arguments', () => {\n    // set options via env var\n    process.env['AZURE_OPENAI_API_KEY'] = 'another My API Key';\n    process.env['OPENAI_API_VERSION'] = 'another My API Version';\n    const client = new AzureOpenAI({ baseURL: 'https://example.com', apiKey: 'My API Key', apiVersion });\n    expect(client.apiKey).toBe('My API Key');\n    expect(client.apiVersion).toBe(apiVersion);\n  });\n\n  describe('Azure Active Directory (AD)', () => {\n    test('with azureADTokenProvider', async () => {\n      const testFetch = async (url: RequestInfo, { headers }: RequestInit = {}): Promise<Response> => {\n        return new Response(JSON.stringify({ a: 1 }), { headers: headers ?? [] });\n      };\n      const client = new AzureOpenAI({\n        baseURL: 'http://localhost:5000/',\n        azureADTokenProvider: async () => 'my token',\n        apiVersion,\n        fetch: testFetch,\n      });\n      expect(\n        (await client.request({ method: 'post', path: 'https://example.com' }).asResponse()).headers.get(\n          'authorization',\n        ),\n      ).toEqual('Bearer my token');\n    });\n\n    test('apiKey and azureADTokenProvider cant be combined', () => {\n      expect(\n        () =>\n          new AzureOpenAI({\n            baseURL: 'http://localhost:5000/',\n            azureADTokenProvider: async () => 'my token',\n            apiKey: 'My API Key',\n            apiVersion,\n          }),\n      ).toThrow(\n        /The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time./,\n      );\n    });\n\n    test('AAD token is refreshed', async () => {\n      let fail = true;\n      const testFetch = async (url: RequestInfo, { headers }: RequestInit = {}): Promise<Response> => {\n        if (fail) {\n          fail = false;\n          return new Response(undefined, {\n            status: 429,\n            headers: {\n              'Retry-After': '0.1',\n            },\n          });\n        }\n        return new Response(JSON.stringify({}), {\n          headers: headers ?? [],\n        });\n      };\n      let counter = 0;\n      async function azureADTokenProvider() {\n        return `token-${counter++}`;\n      }\n      const client = new AzureOpenAI({\n        baseURL: 'http://localhost:5000/',\n        azureADTokenProvider,\n        apiVersion,\n        fetch: testFetch,\n      });\n      expect(\n        (\n          await client.chat.completions\n            .create({\n              model,\n              messages: [{ role: 'system', content: 'Hello' }],\n            })\n            .asResponse()\n        ).headers.get('authorization'),\n      ).toEqual('Bearer token-1');\n    });\n  });\n\n  test('uses api-key header when apiKey is provided', async () => {\n    const testFetch = async (url: RequestInfo, { headers }: RequestInit = {}): Promise<Response> => {\n      return new Response(JSON.stringify({ a: 1 }), { headers: headers ?? [] });\n    };\n    const client = new AzureOpenAI({\n      baseURL: 'http://localhost:5000/',\n      apiKey: 'My API Key',\n      apiVersion,\n      fetch: testFetch,\n    });\n\n    const res = await client.request({ method: 'post', path: 'https://example.com' }).asResponse();\n    expect(res.headers.get('api-key')).toEqual('My API Key');\n    expect(res.headers.get('authorization')).toEqual(null);\n  });\n\n  test('with endpoint', () => {\n    const client = new AzureOpenAI({ endpoint: 'https://example.com', apiKey: 'My API Key', apiVersion });\n    expect(client.baseURL).toEqual('https://example.com/openai');\n  });\n\n  test('baseURL and endpoint are mutually exclusive', () => {\n    expect(\n      () =>\n        new AzureOpenAI({\n          endpoint: 'https://example.com',\n          baseURL: 'https://anotherexample.com',\n          apiKey: 'My API Key',\n          apiVersion,\n        }),\n    ).toThrow(/baseURL and endpoint are mutually exclusive/);\n  });\n});\n\ndescribe('azure request building', () => {\n  const client = new AzureOpenAI({ baseURL: 'https://example.com', apiKey: 'My API Key', apiVersion });\n\n  describe('model to deployment mapping', function () {\n    const testFetch = async (url: RequestInfo): Promise<Response> => {\n      return new Response(JSON.stringify({ url }), { headers: { 'content-type': 'application/json' } });\n    };\n    describe('with client-level deployment', function () {\n      const client = new AzureOpenAI({\n        endpoint: 'https://example.com',\n        apiKey: 'My API Key',\n        apiVersion,\n        deployment,\n        fetch: testFetch,\n      });\n\n      test('handles Batch', async () => {\n        expect(\n          await client.batches.create({\n            completion_window: '24h',\n            endpoint: '/v1/chat/completions',\n            input_file_id: 'file-id',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/batches?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles completions', async () => {\n        expect(\n          await client.completions.create({\n            model,\n            prompt: 'prompt',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/completions?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles chat completions', async () => {\n        expect(\n          await client.chat.completions.create({\n            model,\n            messages: [{ role: 'system', content: 'Hello' }],\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/chat/completions?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles embeddings', async () => {\n        expect(\n          await client.embeddings.create({\n            model,\n            input: 'input',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/embeddings?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles audio translations', async () => {\n        expect(\n          await client.audio.translations.create({\n            model,\n            file: new File([], ''),\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/audio/translations?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles audio transcriptions', async () => {\n        expect(\n          await client.audio.transcriptions.create({\n            model,\n            file: new File([], ''),\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/audio/transcriptions?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles text to speech', async () => {\n        expect(\n          await (\n            await client.audio.speech.create({\n              model,\n              input: '',\n              voice: 'alloy',\n            })\n          ).json(),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/audio/speech?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles image generation', async () => {\n        expect(\n          await client.images.generate({\n            model,\n            prompt: 'prompt',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/images/generations?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles assistants', async () => {\n        expect(\n          await client.beta.assistants.create({\n            model,\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/assistants?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles files', async () => {\n        expect(\n          await client.files.create({\n            file: new File([], ''),\n            purpose: 'assistants',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/files?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles fine tuning', async () => {\n        expect(\n          await client.fineTuning.jobs.create({\n            model,\n            training_file: '',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/fine_tuning/jobs?api-version=${apiVersion}`,\n        });\n      });\n    });\n\n    describe('with no client-level deployment', function () {\n      const client = new AzureOpenAI({\n        endpoint: 'https://example.com',\n        apiKey: 'My API Key',\n        apiVersion,\n        fetch: testFetch,\n      });\n\n      test('Batch is not handled', async () => {\n        expect(\n          await client.batches.create({\n            completion_window: '24h',\n            endpoint: '/v1/chat/completions',\n            input_file_id: 'file-id',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/batches?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles completions', async () => {\n        expect(\n          await client.completions.create({\n            model: deployment,\n            prompt: 'prompt',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/completions?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles chat completions', async () => {\n        expect(\n          await client.chat.completions.create({\n            model: deployment,\n            messages: [{ role: 'system', content: 'Hello' }],\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/chat/completions?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles embeddings', async () => {\n        expect(\n          await client.embeddings.create({\n            model: deployment,\n            input: 'input',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/embeddings?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles audio translations', async () => {\n        expect(\n          await client.audio.translations.create({ model: deployment, file: new File([], '') }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/audio/translations?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles audio transcriptions', async () => {\n        expect(\n          await client.audio.transcriptions.create({ model: deployment, file: new File([], '') }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/audio/transcriptions?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles text to speech', async () => {\n        expect(\n          await (\n            await client.audio.speech.create({\n              model: deployment,\n              input: '',\n              voice: 'alloy',\n            })\n          ).json(),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/audio/speech?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles image generation', async () => {\n        expect(\n          await client.images.generate({\n            model: deployment,\n            prompt: 'prompt',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/deployments/${deployment}/images/generations?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles assistants', async () => {\n        expect(\n          await client.beta.assistants.create({\n            model,\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/assistants?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles files', async () => {\n        expect(\n          await client.files.create({\n            file: new File([], ''),\n            purpose: 'assistants',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/files?api-version=${apiVersion}`,\n        });\n      });\n\n      test('handles fine tuning', async () => {\n        expect(\n          await client.fineTuning.jobs.create({\n            model,\n            training_file: '',\n          }),\n        ).toMatchObject({\n          url: `https://example.com/openai/fine_tuning/jobs?api-version=${apiVersion}`,\n        });\n      });\n    });\n  });\n\n  describe('custom headers', () => {\n    test('handles undefined', async () => {\n      const { req } = await client.buildRequest({\n        path: '/foo',\n        method: 'post',\n        body: { value: 'hello' },\n        headers: { 'X-Foo': 'baz', 'x-foo': 'bar', 'x-Foo': undefined, 'x-baz': 'bam', 'X-Baz': null },\n      });\n      expect(req.headers.get('x-foo')).toEqual('bar');\n      expect(req.headers.get('x-Foo')).toEqual('bar');\n      expect(req.headers.get('X-Foo')).toEqual('bar');\n      expect(req.headers.get('x-baz')).toEqual(null);\n    });\n  });\n});\n\ndescribe('retries', () => {\n  test('retry on timeout', async () => {\n    let count = 0;\n    const testFetch = async (url: RequestInfo, { signal }: RequestInit = {}): Promise<Response> => {\n      if (count++ === 0) {\n        return new Promise(\n          (resolve, reject) => signal?.addEventListener('abort', () => reject(new Error('timed out'))),\n        );\n      }\n      return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });\n    };\n\n    const client = new AzureOpenAI({\n      baseURL: 'https://example.com',\n      apiKey: 'My API Key',\n      apiVersion,\n      timeout: 10,\n      fetch: testFetch,\n    });\n\n    expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });\n    expect(count).toEqual(2);\n    expect(\n      await client\n        .request({ path: '/foo', method: 'get' })\n        .asResponse()\n        .then((r) => r.text()),\n    ).toEqual(JSON.stringify({ a: 1 }));\n    expect(count).toEqual(3);\n  });\n\n  test('retry on 429 with retry-after', async () => {\n    let count = 0;\n    const testFetch = async (url: RequestInfo, { signal }: RequestInit = {}): Promise<Response> => {\n      if (count++ === 0) {\n        return new Response(undefined, {\n          status: 429,\n          headers: {\n            'Retry-After': '0.1',\n          },\n        });\n      }\n      return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });\n    };\n\n    const client = new AzureOpenAI({\n      baseURL: 'https://example.com',\n      apiKey: 'My API Key',\n      apiVersion,\n      fetch: testFetch,\n    });\n\n    expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });\n    expect(count).toEqual(2);\n    expect(\n      await client\n        .request({ path: '/foo', method: 'get' })\n        .asResponse()\n        .then((r) => r.text()),\n    ).toEqual(JSON.stringify({ a: 1 }));\n    expect(count).toEqual(3);\n  });\n\n  test('retry on 429 with retry-after-ms', async () => {\n    let count = 0;\n    const testFetch = async (url: RequestInfo, { signal }: RequestInit = {}): Promise<Response> => {\n      if (count++ === 0) {\n        return new Response(undefined, {\n          status: 429,\n          headers: {\n            'Retry-After-Ms': '10',\n          },\n        });\n      }\n      return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });\n    };\n\n    const client = new AzureOpenAI({\n      baseURL: 'https://example.com',\n      apiKey: 'My API Key',\n      apiVersion,\n      fetch: testFetch,\n    });\n\n    expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });\n    expect(count).toEqual(2);\n    expect(\n      await client\n        .request({ path: '/foo', method: 'get' })\n        .asResponse()\n        .then((r) => r.text()),\n    ).toEqual(JSON.stringify({ a: 1 }));\n    expect(count).toEqual(3);\n  });\n});\n"
  },
  {
    "path": "tests/lib/parser.test.ts",
    "content": "import { z as z4 } from 'zod/v4';\nimport { z as z3 } from 'zod/v3';\nimport { zodResponseFormat } from 'openai/helpers/zod';\nimport { makeSnapshotRequest } from '../utils/mock-snapshots';\n\njest.setTimeout(1000 * 30);\n\ndescribe.each([\n  { version: 'v3', z: z3 },\n  { version: 'v4', z: z4 as any as typeof z3 },\n])('.parse()', ({ z, version }) => {\n  describe('zod', () => {\n    it('deserialises response_format', async () => {\n      const completion = await makeSnapshotRequest((openai) =>\n        openai.chat.completions.parse({\n          model: 'gpt-4o-2024-08-06',\n          messages: [\n            {\n              role: 'user',\n              content: \"What's the weather like in SF?\",\n            },\n          ],\n          response_format: zodResponseFormat(\n            z.object({\n              city: z.string(),\n              units: z.enum(['c', 'f']).default('f'),\n            }),\n            'location',\n          ),\n        }),\n      );\n\n      expect(completion.choices[0]).toMatchInlineSnapshot(`\n        {\n          \"finish_reason\": \"stop\",\n          \"index\": 0,\n          \"logprobs\": null,\n          \"message\": {\n            \"content\": \"{\"city\":\"San Francisco\",\"units\":\"c\"}\",\n            \"parsed\": {\n              \"city\": \"San Francisco\",\n              \"units\": \"c\",\n            },\n            \"refusal\": null,\n            \"role\": \"assistant\",\n          },\n        }\n      `);\n    });\n\n    test('top-level recursive schemas', async () => {\n      const UI: any = z.lazy(() =>\n        z.object({\n          type: z.enum(['div', 'button', 'header', 'section', 'field', 'form']),\n          label: z.string(),\n          children: z.array(UI),\n          attributes: z.array(\n            z.object({\n              name: z.string(),\n              value: z.string(),\n            }),\n          ),\n        }),\n      );\n\n      const completion = await makeSnapshotRequest((openai) =>\n        openai.chat.completions.parse({\n          model: 'gpt-4o-2024-08-06',\n          messages: [\n            {\n              role: 'system',\n              content: 'You are a UI generator AI. Convert the user input into a UI.',\n            },\n            { role: 'user', content: 'Make a User Profile Form with 3 fields' },\n          ],\n          response_format: zodResponseFormat(UI, 'ui'),\n        }),\n      );\n\n      expect(completion.choices[0]?.message).toMatchInlineSnapshot(`\n        {\n          \"content\": \"{\"type\":\"form\",\"label\":\"User Profile Form\",\"children\":[{\"type\":\"field\",\"label\":\"First Name\",\"children\":[],\"attributes\":[{\"name\":\"type\",\"value\":\"text\"},{\"name\":\"name\",\"value\":\"firstName\"},{\"name\":\"placeholder\",\"value\":\"Enter your first name\"}]},{\"type\":\"field\",\"label\":\"Last Name\",\"children\":[],\"attributes\":[{\"name\":\"type\",\"value\":\"text\"},{\"name\":\"name\",\"value\":\"lastName\"},{\"name\":\"placeholder\",\"value\":\"Enter your last name\"}]},{\"type\":\"field\",\"label\":\"Email Address\",\"children\":[],\"attributes\":[{\"name\":\"type\",\"value\":\"email\"},{\"name\":\"name\",\"value\":\"email\"},{\"name\":\"placeholder\",\"value\":\"Enter your email address\"}]},{\"type\":\"button\",\"label\":\"Submit\",\"children\":[],\"attributes\":[{\"name\":\"type\",\"value\":\"submit\"}]}],\"attributes\":[]}\",\n          \"parsed\": {\n            \"attributes\": [],\n            \"children\": [\n              {\n                \"attributes\": [\n                  {\n                    \"name\": \"type\",\n                    \"value\": \"text\",\n                  },\n                  {\n                    \"name\": \"name\",\n                    \"value\": \"firstName\",\n                  },\n                  {\n                    \"name\": \"placeholder\",\n                    \"value\": \"Enter your first name\",\n                  },\n                ],\n                \"children\": [],\n                \"label\": \"First Name\",\n                \"type\": \"field\",\n              },\n              {\n                \"attributes\": [\n                  {\n                    \"name\": \"type\",\n                    \"value\": \"text\",\n                  },\n                  {\n                    \"name\": \"name\",\n                    \"value\": \"lastName\",\n                  },\n                  {\n                    \"name\": \"placeholder\",\n                    \"value\": \"Enter your last name\",\n                  },\n                ],\n                \"children\": [],\n                \"label\": \"Last Name\",\n                \"type\": \"field\",\n              },\n              {\n                \"attributes\": [\n                  {\n                    \"name\": \"type\",\n                    \"value\": \"email\",\n                  },\n                  {\n                    \"name\": \"name\",\n                    \"value\": \"email\",\n                  },\n                  {\n                    \"name\": \"placeholder\",\n                    \"value\": \"Enter your email address\",\n                  },\n                ],\n                \"children\": [],\n                \"label\": \"Email Address\",\n                \"type\": \"field\",\n              },\n              {\n                \"attributes\": [\n                  {\n                    \"name\": \"type\",\n                    \"value\": \"submit\",\n                  },\n                ],\n                \"children\": [],\n                \"label\": \"Submit\",\n                \"type\": \"button\",\n              },\n            ],\n            \"label\": \"User Profile Form\",\n            \"type\": \"form\",\n          },\n          \"refusal\": null,\n          \"role\": \"assistant\",\n        }\n      `);\n\n      if (version === 'v3') {\n        expect(zodResponseFormat(UI, 'ui').json_schema).toMatchInlineSnapshot(`\n        {\n          \"name\": \"ui\",\n          \"schema\": {\n            \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n            \"additionalProperties\": false,\n            \"definitions\": {\n              \"ui\": {\n                \"additionalProperties\": false,\n                \"properties\": {\n                  \"attributes\": {\n                    \"items\": {\n                      \"additionalProperties\": false,\n                      \"properties\": {\n                        \"name\": {\n                          \"type\": \"string\",\n                        },\n                        \"value\": {\n                          \"type\": \"string\",\n                        },\n                      },\n                      \"required\": [\n                        \"name\",\n                        \"value\",\n                      ],\n                      \"type\": \"object\",\n                    },\n                    \"type\": \"array\",\n                  },\n                  \"children\": {\n                    \"items\": {\n                      \"$ref\": \"#/definitions/ui\",\n                    },\n                    \"type\": \"array\",\n                  },\n                  \"label\": {\n                    \"type\": \"string\",\n                  },\n                  \"type\": {\n                    \"enum\": [\n                      \"div\",\n                      \"button\",\n                      \"header\",\n                      \"section\",\n                      \"field\",\n                      \"form\",\n                    ],\n                    \"type\": \"string\",\n                  },\n                },\n                \"required\": [\n                  \"type\",\n                  \"label\",\n                  \"children\",\n                  \"attributes\",\n                ],\n                \"type\": \"object\",\n              },\n            },\n            \"properties\": {\n              \"attributes\": {\n                \"items\": {\n                  \"additionalProperties\": false,\n                  \"properties\": {\n                    \"name\": {\n                      \"type\": \"string\",\n                    },\n                    \"value\": {\n                      \"type\": \"string\",\n                    },\n                  },\n                  \"required\": [\n                    \"name\",\n                    \"value\",\n                  ],\n                  \"type\": \"object\",\n                },\n                \"type\": \"array\",\n              },\n              \"children\": {\n                \"items\": {\n                  \"$ref\": \"#/definitions/ui\",\n                },\n                \"type\": \"array\",\n              },\n              \"label\": {\n                \"type\": \"string\",\n              },\n              \"type\": {\n                \"enum\": [\n                  \"div\",\n                  \"button\",\n                  \"header\",\n                  \"section\",\n                  \"field\",\n                  \"form\",\n                ],\n                \"type\": \"string\",\n              },\n            },\n            \"required\": [\n              \"type\",\n              \"label\",\n              \"children\",\n              \"attributes\",\n            ],\n            \"type\": \"object\",\n          },\n          \"strict\": true,\n        }\n      `);\n      } else {\n        expect(zodResponseFormat(UI, 'ui').json_schema).toMatchInlineSnapshot(`\n{\n  \"name\": \"ui\",\n  \"schema\": {\n    \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n    \"additionalProperties\": false,\n    \"properties\": {\n      \"attributes\": {\n        \"items\": {\n          \"additionalProperties\": false,\n          \"properties\": {\n            \"name\": {\n              \"type\": \"string\",\n            },\n            \"value\": {\n              \"type\": \"string\",\n            },\n          },\n          \"required\": [\n            \"name\",\n            \"value\",\n          ],\n          \"type\": \"object\",\n        },\n        \"type\": \"array\",\n      },\n      \"children\": {\n        \"items\": {\n          \"$ref\": \"#\",\n        },\n        \"type\": \"array\",\n      },\n      \"label\": {\n        \"type\": \"string\",\n      },\n      \"type\": {\n        \"enum\": [\n          \"div\",\n          \"button\",\n          \"header\",\n          \"section\",\n          \"field\",\n          \"form\",\n        ],\n        \"type\": \"string\",\n      },\n    },\n    \"required\": [\n      \"type\",\n      \"label\",\n      \"children\",\n      \"attributes\",\n    ],\n    \"type\": \"object\",\n  },\n  \"strict\": true,\n}\n`);\n      }\n    });\n\n    test('merged schemas', async () => {\n      const personSchema = z.object({\n        name: z.string(),\n        phone_number: z.string().nullable(),\n      });\n\n      const contactPersonSchema = z.object({\n        person1: personSchema.merge(\n          z.object({\n            roles: z\n              .array(z.enum(['parent', 'child', 'sibling', 'spouse', 'friend', 'other']))\n              .describe('Any roles for which the contact is important, use other for custom roles'),\n            description: z\n              .string()\n              .nullable()\n              .describe('Open text for any other relevant information about what the contact does.'),\n          }),\n        ),\n        person2: personSchema.merge(\n          z.object({\n            differentField: z.string(),\n          }),\n        ),\n      });\n\n      if (version === 'v3') {\n        expect(zodResponseFormat(contactPersonSchema, 'contactPerson').json_schema.schema)\n          .toMatchInlineSnapshot(`\n        {\n          \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n          \"additionalProperties\": false,\n          \"definitions\": {\n            \"contactPerson\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"person1\": {\n                  \"additionalProperties\": false,\n                  \"properties\": {\n                    \"description\": {\n                      \"description\": \"Open text for any other relevant information about what the contact does.\",\n                      \"nullable\": true,\n                      \"type\": \"string\",\n                    },\n                    \"name\": {\n                      \"type\": \"string\",\n                    },\n                    \"phone_number\": {\n                      \"nullable\": true,\n                      \"type\": \"string\",\n                    },\n                    \"roles\": {\n                      \"description\": \"Any roles for which the contact is important, use other for custom roles\",\n                      \"items\": {\n                        \"enum\": [\n                          \"parent\",\n                          \"child\",\n                          \"sibling\",\n                          \"spouse\",\n                          \"friend\",\n                          \"other\",\n                        ],\n                        \"type\": \"string\",\n                      },\n                      \"type\": \"array\",\n                    },\n                  },\n                  \"required\": [\n                    \"name\",\n                    \"phone_number\",\n                    \"roles\",\n                    \"description\",\n                  ],\n                  \"type\": \"object\",\n                },\n                \"person2\": {\n                  \"additionalProperties\": false,\n                  \"properties\": {\n                    \"differentField\": {\n                      \"type\": \"string\",\n                    },\n                    \"name\": {\n                      \"$ref\": \"#/definitions/contactPerson_properties_person1_properties_name\",\n                    },\n                    \"phone_number\": {\n                      \"$ref\": \"#/definitions/contactPerson_properties_person1_properties_phone_number\",\n                    },\n                  },\n                  \"required\": [\n                    \"name\",\n                    \"phone_number\",\n                    \"differentField\",\n                  ],\n                  \"type\": \"object\",\n                },\n              },\n              \"required\": [\n                \"person1\",\n                \"person2\",\n              ],\n              \"type\": \"object\",\n            },\n            \"contactPerson_properties_person1_properties_name\": {\n              \"type\": \"string\",\n            },\n            \"contactPerson_properties_person1_properties_phone_number\": {\n              \"nullable\": true,\n              \"type\": \"string\",\n            },\n          },\n          \"properties\": {\n            \"person1\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"description\": {\n                  \"description\": \"Open text for any other relevant information about what the contact does.\",\n                  \"nullable\": true,\n                  \"type\": \"string\",\n                },\n                \"name\": {\n                  \"type\": \"string\",\n                },\n                \"phone_number\": {\n                  \"nullable\": true,\n                  \"type\": \"string\",\n                },\n                \"roles\": {\n                  \"description\": \"Any roles for which the contact is important, use other for custom roles\",\n                  \"items\": {\n                    \"enum\": [\n                      \"parent\",\n                      \"child\",\n                      \"sibling\",\n                      \"spouse\",\n                      \"friend\",\n                      \"other\",\n                    ],\n                    \"type\": \"string\",\n                  },\n                  \"type\": \"array\",\n                },\n              },\n              \"required\": [\n                \"name\",\n                \"phone_number\",\n                \"roles\",\n                \"description\",\n              ],\n              \"type\": \"object\",\n            },\n            \"person2\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"differentField\": {\n                  \"type\": \"string\",\n                },\n                \"name\": {\n                  \"$ref\": \"#/definitions/contactPerson_properties_person1_properties_name\",\n                },\n                \"phone_number\": {\n                  \"$ref\": \"#/definitions/contactPerson_properties_person1_properties_phone_number\",\n                },\n              },\n              \"required\": [\n                \"name\",\n                \"phone_number\",\n                \"differentField\",\n              ],\n              \"type\": \"object\",\n            },\n          },\n          \"required\": [\n            \"person1\",\n            \"person2\",\n          ],\n          \"type\": \"object\",\n        }\n      `);\n      } else {\n        expect(zodResponseFormat(contactPersonSchema, 'contactPerson').json_schema.schema)\n          .toMatchInlineSnapshot(`\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"additionalProperties\": false,\n  \"properties\": {\n    \"person1\": {\n      \"additionalProperties\": false,\n      \"properties\": {\n        \"description\": {\n          \"anyOf\": [\n            {\n              \"type\": \"string\",\n            },\n            {\n              \"type\": \"null\",\n            },\n          ],\n          \"description\": \"Open text for any other relevant information about what the contact does.\",\n        },\n        \"name\": {\n          \"type\": \"string\",\n        },\n        \"phone_number\": {\n          \"anyOf\": [\n            {\n              \"type\": \"string\",\n            },\n            {\n              \"type\": \"null\",\n            },\n          ],\n        },\n        \"roles\": {\n          \"description\": \"Any roles for which the contact is important, use other for custom roles\",\n          \"items\": {\n            \"enum\": [\n              \"parent\",\n              \"child\",\n              \"sibling\",\n              \"spouse\",\n              \"friend\",\n              \"other\",\n            ],\n            \"type\": \"string\",\n          },\n          \"type\": \"array\",\n        },\n      },\n      \"required\": [\n        \"name\",\n        \"phone_number\",\n        \"roles\",\n        \"description\",\n      ],\n      \"type\": \"object\",\n    },\n    \"person2\": {\n      \"additionalProperties\": false,\n      \"properties\": {\n        \"differentField\": {\n          \"type\": \"string\",\n        },\n        \"name\": {\n          \"type\": \"string\",\n        },\n        \"phone_number\": {\n          \"anyOf\": [\n            {\n              \"type\": \"string\",\n            },\n            {\n              \"type\": \"null\",\n            },\n          ],\n        },\n      },\n      \"required\": [\n        \"name\",\n        \"phone_number\",\n        \"differentField\",\n      ],\n      \"type\": \"object\",\n    },\n  },\n  \"required\": [\n    \"person1\",\n    \"person2\",\n  ],\n  \"type\": \"object\",\n}\n`);\n      }\n\n      const completion = await makeSnapshotRequest(\n        (openai) =>\n          openai.chat.completions.parse({\n            model: 'gpt-4o-2024-08-06',\n            messages: [\n              {\n                role: 'system',\n                content: 'You are a helpful assistant.',\n              },\n              {\n                role: 'user',\n                content:\n                  'jane doe, born nov 16, engineer at openai, jane@openai.com. john smith, born march 1, enigneer at openai, john@openai.com',\n              },\n            ],\n            response_format: zodResponseFormat(contactPersonSchema, 'contactPerson'),\n          }),\n        2,\n      );\n\n      expect(completion.choices[0]?.message).toMatchInlineSnapshot(`\n        {\n          \"content\": \"{\"person1\":{\"name\":\"Jane Doe\",\"phone_number\":\".\",\"roles\":[\"other\"],\"description\":\"Engineer at OpenAI, born Nov 16, contact email: jane@openai.com\"},\"person2\":{\"name\":\"John Smith\",\"phone_number\":\"john@openai.com\",\"differentField\":\"Engineer at OpenAI, born March 1.\"}}\",\n          \"parsed\": {\n            \"person1\": {\n              \"description\": \"Engineer at OpenAI, born Nov 16, contact email: jane@openai.com\",\n              \"name\": \"Jane Doe\",\n              \"phone_number\": \".\",\n              \"roles\": [\n                \"other\",\n              ],\n            },\n            \"person2\": {\n              \"differentField\": \"Engineer at OpenAI, born March 1.\",\n              \"name\": \"John Smith\",\n              \"phone_number\": \"john@openai.com\",\n            },\n          },\n          \"refusal\": null,\n          \"role\": \"assistant\",\n        }\n      `);\n    });\n\n    test('nested schema extraction', async () => {\n      // optional object that can be on each field, mark it as nullable to comply with structured output restrictions\n      const metadata = z.nullable(\n        z.object({\n          foo: z.string(),\n        }),\n      );\n\n      // union element a\n      const fieldA = z.object({\n        type: z.literal('string'),\n        name: z.string(),\n        metadata,\n      });\n\n      // union element b, both referring to above nullable object\n      const fieldB = z.object({\n        type: z.literal('number'),\n        metadata,\n      });\n\n      // top level input object with array of union element\n      const model = z.object({\n        name: z.string(),\n        fields: z.array(z.union([fieldA, fieldB])),\n      });\n\n      if (version === 'v3') {\n        expect(zodResponseFormat(model, 'query').json_schema.schema).toMatchInlineSnapshot(`\n        {\n          \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n          \"additionalProperties\": false,\n          \"definitions\": {\n            \"query\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"fields\": {\n                  \"items\": {\n                    \"anyOf\": [\n                      {\n                        \"additionalProperties\": false,\n                        \"properties\": {\n                          \"metadata\": {\n                            \"anyOf\": [\n                              {\n                                \"additionalProperties\": false,\n                                \"properties\": {\n                                  \"foo\": {\n                                    \"type\": \"string\",\n                                  },\n                                },\n                                \"required\": [\n                                  \"foo\",\n                                ],\n                                \"type\": \"object\",\n                              },\n                              {\n                                \"type\": \"null\",\n                              },\n                            ],\n                          },\n                          \"name\": {\n                            \"type\": \"string\",\n                          },\n                          \"type\": {\n                            \"const\": \"string\",\n                            \"type\": \"string\",\n                          },\n                        },\n                        \"required\": [\n                          \"type\",\n                          \"name\",\n                          \"metadata\",\n                        ],\n                        \"type\": \"object\",\n                      },\n                      {\n                        \"additionalProperties\": false,\n                        \"properties\": {\n                          \"metadata\": {\n                            \"$ref\": \"#/definitions/query_properties_fields_items_anyOf_0_properties_metadata\",\n                          },\n                          \"type\": {\n                            \"const\": \"number\",\n                            \"type\": \"string\",\n                          },\n                        },\n                        \"required\": [\n                          \"type\",\n                          \"metadata\",\n                        ],\n                        \"type\": \"object\",\n                      },\n                    ],\n                  },\n                  \"type\": \"array\",\n                },\n                \"name\": {\n                  \"type\": \"string\",\n                },\n              },\n              \"required\": [\n                \"name\",\n                \"fields\",\n              ],\n              \"type\": \"object\",\n            },\n            \"query_properties_fields_items_anyOf_0_properties_metadata\": {\n              \"anyOf\": [\n                {\n                  \"$ref\": \"#/definitions/query_properties_fields_items_anyOf_0_properties_metadata_anyOf_0\",\n                },\n                {\n                  \"type\": \"null\",\n                },\n              ],\n            },\n            \"query_properties_fields_items_anyOf_0_properties_metadata_anyOf_0\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"foo\": {\n                  \"$ref\": \"#/definitions/query_properties_fields_items_anyOf_0_properties_metadata_anyOf_0_properties_foo\",\n                },\n              },\n              \"required\": [\n                \"foo\",\n              ],\n              \"type\": \"object\",\n            },\n            \"query_properties_fields_items_anyOf_0_properties_metadata_anyOf_0_properties_foo\": {\n              \"type\": \"string\",\n            },\n          },\n          \"properties\": {\n            \"fields\": {\n              \"items\": {\n                \"anyOf\": [\n                  {\n                    \"additionalProperties\": false,\n                    \"properties\": {\n                      \"metadata\": {\n                        \"anyOf\": [\n                          {\n                            \"additionalProperties\": false,\n                            \"properties\": {\n                              \"foo\": {\n                                \"type\": \"string\",\n                              },\n                            },\n                            \"required\": [\n                              \"foo\",\n                            ],\n                            \"type\": \"object\",\n                          },\n                          {\n                            \"type\": \"null\",\n                          },\n                        ],\n                      },\n                      \"name\": {\n                        \"type\": \"string\",\n                      },\n                      \"type\": {\n                        \"const\": \"string\",\n                        \"type\": \"string\",\n                      },\n                    },\n                    \"required\": [\n                      \"type\",\n                      \"name\",\n                      \"metadata\",\n                    ],\n                    \"type\": \"object\",\n                  },\n                  {\n                    \"additionalProperties\": false,\n                    \"properties\": {\n                      \"metadata\": {\n                        \"$ref\": \"#/definitions/query_properties_fields_items_anyOf_0_properties_metadata\",\n                      },\n                      \"type\": {\n                        \"const\": \"number\",\n                        \"type\": \"string\",\n                      },\n                    },\n                    \"required\": [\n                      \"type\",\n                      \"metadata\",\n                    ],\n                    \"type\": \"object\",\n                  },\n                ],\n              },\n              \"type\": \"array\",\n            },\n            \"name\": {\n              \"type\": \"string\",\n            },\n          },\n          \"required\": [\n            \"name\",\n            \"fields\",\n          ],\n          \"type\": \"object\",\n        }\n      `);\n      } else {\n        expect(zodResponseFormat(model, 'query').json_schema.schema).toMatchInlineSnapshot(`\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"additionalProperties\": false,\n  \"properties\": {\n    \"fields\": {\n      \"items\": {\n        \"anyOf\": [\n          {\n            \"additionalProperties\": false,\n            \"properties\": {\n              \"metadata\": {\n                \"anyOf\": [\n                  {\n                    \"additionalProperties\": false,\n                    \"properties\": {\n                      \"foo\": {\n                        \"type\": \"string\",\n                      },\n                    },\n                    \"required\": [\n                      \"foo\",\n                    ],\n                    \"type\": \"object\",\n                  },\n                  {\n                    \"type\": \"null\",\n                  },\n                ],\n              },\n              \"name\": {\n                \"type\": \"string\",\n              },\n              \"type\": {\n                \"const\": \"string\",\n                \"type\": \"string\",\n              },\n            },\n            \"required\": [\n              \"type\",\n              \"name\",\n              \"metadata\",\n            ],\n            \"type\": \"object\",\n          },\n          {\n            \"additionalProperties\": false,\n            \"properties\": {\n              \"metadata\": {\n                \"anyOf\": [\n                  {\n                    \"additionalProperties\": false,\n                    \"properties\": {\n                      \"foo\": {\n                        \"type\": \"string\",\n                      },\n                    },\n                    \"required\": [\n                      \"foo\",\n                    ],\n                    \"type\": \"object\",\n                  },\n                  {\n                    \"type\": \"null\",\n                  },\n                ],\n              },\n              \"type\": {\n                \"const\": \"number\",\n                \"type\": \"string\",\n              },\n            },\n            \"required\": [\n              \"type\",\n              \"metadata\",\n            ],\n            \"type\": \"object\",\n          },\n        ],\n      },\n      \"type\": \"array\",\n    },\n    \"name\": {\n      \"type\": \"string\",\n    },\n  },\n  \"required\": [\n    \"name\",\n    \"fields\",\n  ],\n  \"type\": \"object\",\n}\n`);\n      }\n\n      const completion = await makeSnapshotRequest(\n        (openai) =>\n          openai.chat.completions.parse({\n            model: 'gpt-4o-2024-08-06',\n            messages: [\n              {\n                role: 'system',\n                content:\n                  \"You are a helpful assistant. Generate a data model according to the user's instructions.\",\n              },\n              { role: 'user', content: 'create a todo app data model' },\n            ],\n            response_format: zodResponseFormat(model, 'query'),\n          }),\n        2,\n      );\n\n      expect(completion.choices[0]?.message).toMatchInlineSnapshot(`\n        {\n          \"content\": \"{\"name\":\"TodoApp\",\"fields\":[{\"type\":\"string\",\"name\":\"taskId\",\"metadata\":{\"foo\":\"unique identifier for each task\"}},{\"type\":\"string\",\"name\":\"title\",\"metadata\":{\"foo\":\"title of the task\"}},{\"type\":\"string\",\"name\":\"description\",\"metadata\":{\"foo\":\"detailed description of the task. This is optional.\"}},{\"type\":\"string\",\"name\":\"status\",\"metadata\":{\"foo\":\"status of the task, e.g., pending, completed, etc.\"}},{\"type\":\"string\",\"name\":\"dueDate\",\"metadata\":null},{\"type\":\"string\",\"name\":\"priority\",\"metadata\":{\"foo\":\"priority level of the task, e.g., low, medium, high\"}},{\"type\":\"string\",\"name\":\"creationDate\",\"metadata\":{\"foo\":\"date when the task was created\"}},{\"type\":\"string\",\"name\":\"lastModifiedDate\",\"metadata\":{\"foo\":\"date when the task was last modified\"}},{\"type\":\"string\",\"name\":\"tags\",\"metadata\":{\"foo\":\"tags associated with the task, for categorization\"}}]}\",\n          \"parsed\": {\n            \"fields\": [\n              {\n                \"metadata\": {\n                  \"foo\": \"unique identifier for each task\",\n                },\n                \"name\": \"taskId\",\n                \"type\": \"string\",\n              },\n              {\n                \"metadata\": {\n                  \"foo\": \"title of the task\",\n                },\n                \"name\": \"title\",\n                \"type\": \"string\",\n              },\n              {\n                \"metadata\": {\n                  \"foo\": \"detailed description of the task. This is optional.\",\n                },\n                \"name\": \"description\",\n                \"type\": \"string\",\n              },\n              {\n                \"metadata\": {\n                  \"foo\": \"status of the task, e.g., pending, completed, etc.\",\n                },\n                \"name\": \"status\",\n                \"type\": \"string\",\n              },\n              {\n                \"metadata\": null,\n                \"name\": \"dueDate\",\n                \"type\": \"string\",\n              },\n              {\n                \"metadata\": {\n                  \"foo\": \"priority level of the task, e.g., low, medium, high\",\n                },\n                \"name\": \"priority\",\n                \"type\": \"string\",\n              },\n              {\n                \"metadata\": {\n                  \"foo\": \"date when the task was created\",\n                },\n                \"name\": \"creationDate\",\n                \"type\": \"string\",\n              },\n              {\n                \"metadata\": {\n                  \"foo\": \"date when the task was last modified\",\n                },\n                \"name\": \"lastModifiedDate\",\n                \"type\": \"string\",\n              },\n              {\n                \"metadata\": {\n                  \"foo\": \"tags associated with the task, for categorization\",\n                },\n                \"name\": \"tags\",\n                \"type\": \"string\",\n              },\n            ],\n            \"name\": \"TodoApp\",\n          },\n          \"refusal\": null,\n          \"role\": \"assistant\",\n        }\n      `);\n    });\n\n    test('recursive schema extraction', async () => {\n      const baseLinkedListNodeSchema = z.object({\n        value: z.number(),\n      });\n\n      type LinkedListNode = z3.infer<typeof baseLinkedListNodeSchema> & {\n        next: LinkedListNode | null;\n      };\n\n      const linkedListNodeSchema: z3.ZodType<LinkedListNode> = baseLinkedListNodeSchema.extend({\n        next: z.lazy(() => z.union([linkedListNodeSchema, z.null()])),\n      });\n\n      // Define the main schema\n      const mainSchema = z.object({\n        linked_list: linkedListNodeSchema,\n      });\n\n      if (version === 'v3') {\n        expect(zodResponseFormat(mainSchema, 'query').json_schema.schema).toMatchInlineSnapshot(`\n        {\n          \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n          \"additionalProperties\": false,\n          \"definitions\": {\n            \"query\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"linked_list\": {\n                  \"additionalProperties\": false,\n                  \"properties\": {\n                    \"next\": {\n                      \"anyOf\": [\n                        {\n                          \"$ref\": \"#/definitions/query_properties_linked_list\",\n                        },\n                        {\n                          \"type\": \"null\",\n                        },\n                      ],\n                    },\n                    \"value\": {\n                      \"type\": \"number\",\n                    },\n                  },\n                  \"required\": [\n                    \"value\",\n                    \"next\",\n                  ],\n                  \"type\": \"object\",\n                },\n              },\n              \"required\": [\n                \"linked_list\",\n              ],\n              \"type\": \"object\",\n            },\n            \"query_properties_linked_list\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"next\": {\n                  \"$ref\": \"#/definitions/query_properties_linked_list_properties_next\",\n                },\n                \"value\": {\n                  \"$ref\": \"#/definitions/query_properties_linked_list_properties_value\",\n                },\n              },\n              \"required\": [\n                \"value\",\n                \"next\",\n              ],\n              \"type\": \"object\",\n            },\n            \"query_properties_linked_list_properties_next\": {\n              \"anyOf\": [\n                {\n                  \"$ref\": \"#/definitions/query_properties_linked_list\",\n                },\n                {\n                  \"type\": \"null\",\n                },\n              ],\n            },\n            \"query_properties_linked_list_properties_value\": {\n              \"type\": \"number\",\n            },\n          },\n          \"properties\": {\n            \"linked_list\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"next\": {\n                  \"anyOf\": [\n                    {\n                      \"$ref\": \"#/definitions/query_properties_linked_list\",\n                    },\n                    {\n                      \"type\": \"null\",\n                    },\n                  ],\n                },\n                \"value\": {\n                  \"type\": \"number\",\n                },\n              },\n              \"required\": [\n                \"value\",\n                \"next\",\n              ],\n              \"type\": \"object\",\n            },\n          },\n          \"required\": [\n            \"linked_list\",\n          ],\n          \"type\": \"object\",\n        }\n      `);\n      } else {\n        expect(zodResponseFormat(mainSchema, 'query').json_schema.schema).toMatchInlineSnapshot(`\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"additionalProperties\": false,\n  \"definitions\": {\n    \"__schema0\": {\n      \"additionalProperties\": false,\n      \"properties\": {\n        \"next\": {\n          \"anyOf\": [\n            {\n              \"$ref\": \"#/definitions/__schema0\",\n            },\n            {\n              \"type\": \"null\",\n            },\n          ],\n        },\n        \"value\": {\n          \"type\": \"number\",\n        },\n      },\n      \"required\": [\n        \"value\",\n        \"next\",\n      ],\n      \"type\": \"object\",\n    },\n  },\n  \"properties\": {\n    \"linked_list\": {\n      \"$ref\": \"#/definitions/__schema0\",\n    },\n  },\n  \"required\": [\n    \"linked_list\",\n  ],\n  \"type\": \"object\",\n}\n`);\n      }\n\n      const completion = await makeSnapshotRequest(\n        (openai) =>\n          openai.chat.completions.parse({\n            model: 'gpt-4o-2024-08-06',\n            messages: [\n              {\n                role: 'system',\n                content:\n                  \"You are a helpful assistant. Generate a data model according to the user's instructions.\",\n              },\n              { role: 'user', content: 'create a linklist from 1 to 5' },\n            ],\n            response_format: zodResponseFormat(mainSchema, 'query'),\n          }),\n        2,\n      );\n\n      expect(completion.choices[0]?.message).toMatchInlineSnapshot(`\n        {\n          \"content\": \"{\"linked_list\":{\"value\":1,\"next\":{\"value\":2,\"next\":{\"value\":3,\"next\":{\"value\":4,\"next\":{\"value\":5,\"next\":null}}}}}}\",\n          \"parsed\": {\n            \"linked_list\": {\n              \"next\": {\n                \"next\": {\n                  \"next\": {\n                    \"next\": {\n                      \"next\": null,\n                      \"value\": 5,\n                    },\n                    \"value\": 4,\n                  },\n                  \"value\": 3,\n                },\n                \"value\": 2,\n              },\n              \"value\": 1,\n            },\n          },\n          \"refusal\": null,\n          \"role\": \"assistant\",\n        }\n      `);\n    });\n\n    test('ref schemas with `.transform()`', async () => {\n      let Inner = z.object({\n        baz:\n          version === 'v3' ?\n            z.boolean().transform((v: any) => v ?? true)\n          : z\n              .boolean()\n              .transform((v: any) => v ?? true)\n              .pipe(z.boolean()),\n      });\n      const Outer = z.object({\n        first: Inner,\n        second: Inner,\n      });\n      if (version === 'v3') {\n        expect(zodResponseFormat(Outer, 'data').json_schema.schema).toMatchInlineSnapshot(`\n        {\n          \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n          \"additionalProperties\": false,\n          \"definitions\": {\n            \"data\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"first\": {\n                  \"additionalProperties\": false,\n                  \"properties\": {\n                    \"baz\": {\n                      \"type\": \"boolean\",\n                    },\n                  },\n                  \"required\": [\n                    \"baz\",\n                  ],\n                  \"type\": \"object\",\n                },\n                \"second\": {\n                  \"$ref\": \"#/definitions/data_properties_first\",\n                },\n              },\n              \"required\": [\n                \"first\",\n                \"second\",\n              ],\n              \"type\": \"object\",\n            },\n            \"data_properties_first\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"baz\": {\n                  \"$ref\": \"#/definitions/data_properties_first_properties_baz\",\n                },\n              },\n              \"required\": [\n                \"baz\",\n              ],\n              \"type\": \"object\",\n            },\n            \"data_properties_first_properties_baz\": {\n              \"type\": \"boolean\",\n            },\n          },\n          \"properties\": {\n            \"first\": {\n              \"additionalProperties\": false,\n              \"properties\": {\n                \"baz\": {\n                  \"type\": \"boolean\",\n                },\n              },\n              \"required\": [\n                \"baz\",\n              ],\n              \"type\": \"object\",\n            },\n            \"second\": {\n              \"$ref\": \"#/definitions/data_properties_first\",\n            },\n          },\n          \"required\": [\n            \"first\",\n            \"second\",\n          ],\n          \"type\": \"object\",\n        }\n      `);\n      } else {\n        expect(zodResponseFormat(Outer, 'data').json_schema.schema).toMatchInlineSnapshot(`\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"additionalProperties\": false,\n  \"properties\": {\n    \"first\": {\n      \"additionalProperties\": false,\n      \"properties\": {\n        \"baz\": {\n          \"type\": \"boolean\",\n        },\n      },\n      \"required\": [\n        \"baz\",\n      ],\n      \"type\": \"object\",\n    },\n    \"second\": {\n      \"additionalProperties\": false,\n      \"properties\": {\n        \"baz\": {\n          \"type\": \"boolean\",\n        },\n      },\n      \"required\": [\n        \"baz\",\n      ],\n      \"type\": \"object\",\n    },\n  },\n  \"required\": [\n    \"first\",\n    \"second\",\n  ],\n  \"type\": \"object\",\n}\n`);\n      }\n\n      const completion = await makeSnapshotRequest(\n        (openai) =>\n          openai.chat.completions.parse({\n            model: 'gpt-4o-2024-08-06',\n            messages: [\n              {\n                role: 'user',\n                content: 'can you generate fake data matching the given response format?',\n              },\n            ],\n            response_format: zodResponseFormat(Outer, 'fakeData'),\n          }),\n        2,\n      );\n\n      expect(completion.choices[0]?.message).toMatchInlineSnapshot(`\n        {\n          \"content\": \"{\"first\":{\"baz\":true},\"second\":{\"baz\":false}}\",\n          \"parsed\": {\n            \"first\": {\n              \"baz\": true,\n            },\n            \"second\": {\n              \"baz\": false,\n            },\n          },\n          \"refusal\": null,\n          \"role\": \"assistant\",\n        }\n      `);\n    });\n  });\n});\n"
  },
  {
    "path": "tests/lib/transform.test.ts",
    "content": "import { toStrictJsonSchema } from 'openai/lib/transform';\nimport { detailedDiff } from 'deep-object-diff';\nimport { JSONSchema } from 'openai/lib/jsonschema';\n\ndescribe('toStrictJsonSchema', () => {\n  describe('Root Schema Validation', () => {\n    test('throws error if root schema is not an object', () => {\n      const schema: any = { type: 'string' };\n\n      expect(() => toStrictJsonSchema(schema)).toThrow(\n        \"Root schema must have type: 'object' but got type: 'string'\",\n      );\n    });\n\n    test('throws error if root schema has no type', () => {\n      const schema: any = { properties: {} };\n\n      expect(() => toStrictJsonSchema(schema)).toThrow(\n        \"Root schema must have type: 'object' but got type: undefined\",\n      );\n    });\n  });\n\n  describe('Additional Properties', () => {\n    test('adds additionalProperties: false to object schemas', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          name: { type: 'string' },\n        },\n        required: ['name'],\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n          },\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n\n    test('preserves existing additionalProperties value', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          name: { type: 'string' },\n        },\n        required: ['name'],\n        additionalProperties: true,\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {},\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n\n    test('adds additionalProperties: false to nested objects', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          user: {\n            type: 'object',\n            properties: {\n              name: { type: 'string' },\n            },\n            required: ['name'],\n          },\n        },\n        required: ['user'],\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n            \"properties\": {\n              \"user\": {\n                \"additionalProperties\": false,\n              },\n            },\n          },\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n  });\n\n  describe('Required Properties', () => {\n    test('makes all properties required when nullable', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          name: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n          age: { anyOf: [{ type: 'number' }, { type: 'null' }] },\n        },\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n            \"required\": [\n              \"name\",\n              \"age\",\n            ],\n          },\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n\n    test('throws error for optional properties without nullable', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          name: { type: 'string' },\n        },\n      };\n\n      expect(() => toStrictJsonSchema(schema)).toThrow(\n        'Zod field at `properties/name` uses `.optional()` without `.nullable()` which is not supported by the API',\n      );\n    });\n  });\n\n  describe('Nested Schemas', () => {\n    test('processes nested object properties', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          address: {\n            type: 'object',\n            properties: {\n              street: { type: 'string' },\n              city: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n            },\n            required: ['street'],\n          },\n        },\n        required: ['address'],\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n            \"properties\": {\n              \"address\": {\n                \"additionalProperties\": false,\n                \"required\": {\n                  \"1\": \"city\",\n                },\n              },\n            },\n          },\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n\n    test('processes array items', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          tags: {\n            type: 'array',\n            items: {\n              type: 'object',\n              properties: {\n                name: { type: 'string' },\n              },\n              required: ['name'],\n            },\n          },\n        },\n        required: ['tags'],\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n            \"properties\": {\n              \"tags\": {\n                \"items\": {\n                  \"additionalProperties\": false,\n                },\n              },\n            },\n          },\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n  });\n\n  describe('anyOf Handling', () => {\n    test('processes anyOf variants', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          value: {\n            anyOf: [\n              {\n                type: 'object',\n                properties: { num: { type: 'number' } },\n                required: ['num'],\n              },\n              {\n                type: 'object',\n                properties: { str: { type: 'string' } },\n                required: ['str'],\n              },\n            ],\n          },\n        },\n        required: ['value'],\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n            \"properties\": {\n              \"value\": {\n                \"anyOf\": {\n                  \"0\": {\n                    \"additionalProperties\": false,\n                  },\n                  \"1\": {\n                    \"additionalProperties\": false,\n                  },\n                },\n              },\n            },\n          },\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n  });\n\n  describe('allOf Handling', () => {\n    test('inlines single allOf variant', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          value: {\n            allOf: [\n              {\n                type: 'object',\n                properties: { name: { type: 'string' } },\n                required: ['name'],\n              },\n            ],\n          },\n        },\n        required: ['value'],\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n            \"properties\": {\n              \"value\": {\n                \"additionalProperties\": false,\n                \"properties\": {\n                  \"name\": {\n                    \"type\": \"string\",\n                  },\n                },\n                \"required\": [\n                  \"name\",\n                ],\n                \"type\": \"object\",\n              },\n            },\n          },\n          \"deleted\": {\n            \"properties\": {\n              \"value\": {\n                \"allOf\": undefined,\n              },\n            },\n          },\n          \"updated\": {},\n        }\n      `);\n    });\n\n    test('processes multiple allOf variants', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          value: {\n            allOf: [\n              {\n                type: 'object',\n                properties: { name: { type: 'string' } },\n                required: ['name'],\n              },\n              {\n                type: 'object',\n                properties: { age: { type: 'number' } },\n                required: ['age'],\n              },\n            ],\n          },\n        },\n        required: ['value'],\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n            \"properties\": {\n              \"value\": {\n                \"allOf\": {\n                  \"0\": {\n                    \"additionalProperties\": false,\n                  },\n                  \"1\": {\n                    \"additionalProperties\": false,\n                  },\n                },\n              },\n            },\n          },\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n  });\n\n  describe('$ref Resolution', () => {\n    test('processes definitions', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          user: { $ref: '#/definitions/User' },\n        },\n        required: ['user'],\n        definitions: {\n          User: {\n            type: 'object',\n            properties: {\n              name: { type: 'string' },\n            },\n            required: ['name'],\n          },\n        },\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n            \"definitions\": {\n              \"User\": {\n                \"additionalProperties\": false,\n              },\n            },\n          },\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n  });\n\n  describe('$defs and definitions', () => {\n    test('processes $defs schemas', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          user: { $ref: '#/$defs/User' },\n        },\n        required: ['user'],\n        $defs: {\n          User: {\n            type: 'object',\n            properties: {\n              name: { type: 'string' },\n            },\n            required: ['name'],\n          },\n        },\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n{\n  \"added\": {\n    \"$defs\": {\n      \"User\": {\n        \"additionalProperties\": false,\n      },\n    },\n    \"additionalProperties\": false,\n  },\n  \"deleted\": {},\n  \"updated\": {},\n}\n`);\n    });\n\n    test('processes definitions schemas', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {},\n        definitions: {\n          User: {\n            type: 'object',\n            properties: {\n              name: { type: 'string' },\n            },\n            required: ['name'],\n          },\n        },\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n            \"definitions\": {\n              \"User\": {\n                \"additionalProperties\": false,\n              },\n            },\n            \"required\": [],\n          },\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n  });\n\n  describe('Complex Scenarios', () => {\n    test('handles deeply nested schemas', () => {\n      const schema: JSONSchema = {\n        type: 'object',\n        properties: {\n          level1: {\n            type: 'object',\n            properties: {\n              level2: {\n                type: 'object',\n                properties: {\n                  name: { type: 'string' },\n                },\n                required: ['name'],\n              },\n            },\n            required: ['level2'],\n          },\n        },\n        required: ['level1'],\n      };\n\n      const strict = toStrictJsonSchema(schema);\n      const diff = detailedDiff(schema, strict);\n\n      expect(diff).toMatchInlineSnapshot(`\n        {\n          \"added\": {\n            \"additionalProperties\": false,\n            \"properties\": {\n              \"level1\": {\n                \"additionalProperties\": false,\n                \"properties\": {\n                  \"level2\": {\n                    \"additionalProperties\": false,\n                  },\n                },\n              },\n            },\n          },\n          \"deleted\": {},\n          \"updated\": {},\n        }\n      `);\n    });\n  });\n});\n"
  },
  {
    "path": "tests/log.test.ts",
    "content": "import OpenAI, { ClientOptions } from 'openai/index';\n\nconst opts: ClientOptions = {\n  apiKey: 'example-api-key',\n  baseURL: 'http://localhost:5000/',\n  logLevel: 'debug',\n  fetch: (url) => {\n    return Promise.resolve(\n      new Response(JSON.stringify({ url, custom: true }), {\n        headers: { 'Content-Type': 'application/json' },\n      }),\n    );\n  },\n};\n\ndescribe('debug()', () => {\n  const env = process.env;\n  const spy = jest.spyOn(console, 'debug');\n\n  beforeEach(() => {\n    jest.resetModules();\n    process.env = { ...env };\n    process.env['DEBUG'] = 'true';\n  });\n\n  afterEach(() => {\n    process.env = env;\n  });\n\n  test('body request object with Authorization header', async function () {\n    const client = new OpenAI(opts);\n    await client.post('/example', {});\n\n    // Check that console.debug was called with the redacted authorization header\n    expect(spy).toHaveBeenCalledWith(\n      expect.stringContaining('[log_'),\n      expect.objectContaining({\n        headers: expect.objectContaining({\n          authorization: '***',\n        }),\n      }),\n    );\n  });\n\n  test('header object with Authorization header', async function () {\n    // Test headers object with authorization header\n    const client = new OpenAI({\n      ...opts,\n      defaultHeaders: {\n        authorization: 'fakeValue',\n      },\n    });\n    await client.post('/example', {});\n\n    expect(spy).toHaveBeenCalledWith(\n      expect.stringContaining('[log_'),\n      expect.objectContaining({\n        headers: expect.objectContaining({\n          authorization: '***',\n        }),\n      }),\n    );\n  });\n\n  test('input args are not mutated', async function () {\n    const authorizationTest = {\n      authorization: 'fakeValue',\n    };\n    const client = new OpenAI({\n      ...opts,\n      defaultHeaders: authorizationTest,\n    });\n\n    const { req } = await client.buildRequest({ path: '/foo', method: 'post' });\n    await client.post('/foo', {});\n\n    // Verify that the original headers weren't mutated\n    expect(authorizationTest.authorization).toEqual('fakeValue');\n    expect((req.headers as Headers).get('authorization')).toEqual('fakeValue');\n\n    expect(spy).toHaveBeenCalledWith(\n      expect.stringContaining('[log_'),\n      expect.objectContaining({\n        headers: expect.objectContaining({\n          authorization: '***',\n        }),\n      }),\n    );\n  });\n\n  test('input headers are not mutated', async function () {\n    const authorizationTest = {\n      authorization: 'fakeValue',\n    };\n    const client = new OpenAI({\n      baseURL: 'http://localhost:5000/',\n      defaultHeaders: authorizationTest,\n      apiKey: 'api-key',\n      logLevel: 'debug',\n      fetch: opts.fetch,\n    });\n\n    const { req } = await client.buildRequest({ path: '/foo', method: 'post' });\n    await client.post('/foo', {});\n\n    // Verify that the original headers weren't mutated\n    expect(authorizationTest.authorization).toEqual('fakeValue');\n    expect((req.headers as Headers).get('authorization')).toEqual('fakeValue');\n\n    expect(spy).toHaveBeenCalledWith(\n      expect.stringContaining('[log_'),\n      expect.objectContaining({\n        headers: expect.objectContaining({\n          authorization: '***',\n        }),\n      }),\n    );\n  });\n});\n"
  },
  {
    "path": "tests/path.test.ts",
    "content": "import { createPathTagFunction, encodeURIPath } from 'openai/internal/utils/path';\nimport { inspect } from 'node:util';\nimport { runInNewContext } from 'node:vm';\n\ndescribe('path template tag function', () => {\n  test('validates input', () => {\n    const testParams = ['', '.', '..', 'x', '%2e', '%2E', '%2e%2e', '%2E%2e', '%2e%2E', '%2E%2E'];\n    const testCases = [\n      ['/path_params/', '/a'],\n      ['/path_params/', '/'],\n      ['/path_params/', ''],\n      ['', '/a'],\n      ['', '/'],\n      ['', ''],\n      ['a'],\n      [''],\n      ['/path_params/', ':initiate'],\n      ['/path_params/', '.json'],\n      ['/path_params/', '?beta=true'],\n      ['/path_params/', '.?beta=true'],\n      ['/path_params/', '/', '/download'],\n      ['/path_params/', '-', '/download'],\n      ['/path_params/', '', '/download'],\n      ['/path_params/', '.', '/download'],\n      ['/path_params/', '..', '/download'],\n      ['/plain/path'],\n    ];\n\n    function paramPermutations(len: number): string[][] {\n      if (len === 0) return [];\n      if (len === 1) return testParams.map((e) => [e]);\n      const rest = paramPermutations(len - 1);\n      return testParams.flatMap((e) => rest.map((r) => [e, ...r]));\n    }\n\n    // We need to test how %2E is handled, so we use a custom encoder that does no escaping.\n    const rawPath = createPathTagFunction((s) => s);\n\n    const emptyObject = {};\n    const mathObject = Math;\n    const numberObject = new Number();\n    const stringObject = new String();\n    const basicClass = new (class {})();\n    const classWithToString = new (class {\n      toString() {\n        return 'ok';\n      }\n    })();\n\n    // Invalid values\n    expect(() => rawPath`/a/${null}/b`).toThrow(\n      'Path parameters result in path with invalid segments:\\n' +\n        'Value of type Null is not a valid path parameter\\n' +\n        '/a/null/b\\n' +\n        '   ^^^^',\n    );\n    expect(() => rawPath`/a/${undefined}/b`).toThrow(\n      'Path parameters result in path with invalid segments:\\n' +\n        'Value of type Undefined is not a valid path parameter\\n' +\n        '/a/undefined/b\\n' +\n        '   ^^^^^^^^^',\n    );\n    expect(() => rawPath`/a/${emptyObject}/b`).toThrow(\n      'Path parameters result in path with invalid segments:\\n' +\n        'Value of type Object is not a valid path parameter\\n' +\n        '/a/[object Object]/b\\n' +\n        '   ^^^^^^^^^^^^^^^',\n    );\n    expect(() => rawPath`?${mathObject}`).toThrow(\n      'Path parameters result in path with invalid segments:\\n' +\n        'Value of type Math is not a valid path parameter\\n' +\n        '?[object Math]\\n' +\n        ' ^^^^^^^^^^^^^',\n    );\n    expect(() => rawPath`/${basicClass}`).toThrow(\n      'Path parameters result in path with invalid segments:\\n' +\n        'Value of type Object is not a valid path parameter\\n' +\n        '/[object Object]\\n' +\n        ' ^^^^^^^^^^^^^^',\n    );\n    expect(() => rawPath`/../${''}`).toThrow(\n      'Path parameters result in path with invalid segments:\\n' +\n        'Value \"..\" can\\'t be safely passed as a path parameter\\n' +\n        '/../\\n' +\n        ' ^^',\n    );\n    expect(() => rawPath`/../${{}}`).toThrow(\n      'Path parameters result in path with invalid segments:\\n' +\n        'Value \"..\" can\\'t be safely passed as a path parameter\\n' +\n        'Value of type Object is not a valid path parameter\\n' +\n        '/../[object Object]\\n' +\n        ' ^^ ^^^^^^^^^^^^^^',\n    );\n\n    // Valid values\n    expect(rawPath`/${0}`).toBe('/0');\n    expect(rawPath`/${''}`).toBe('/');\n    expect(rawPath`/${numberObject}`).toBe('/0');\n    expect(rawPath`${stringObject}/`).toBe('/');\n    expect(rawPath`/${classWithToString}`).toBe('/ok');\n\n    // We need to check what happens with cross-realm values, which we might get from\n    // Jest or other frames in a browser.\n\n    const newRealm = runInNewContext('globalThis');\n    expect(newRealm.Object).not.toBe(Object);\n\n    const crossRealmObject = newRealm.Object();\n    const crossRealmMathObject = newRealm.Math;\n    const crossRealmNumber = new newRealm.Number();\n    const crossRealmString = new newRealm.String();\n    const crossRealmClass = new (class extends newRealm.Object {})();\n    const crossRealmClassWithToString = new (class extends newRealm.Object {\n      toString() {\n        return 'ok';\n      }\n    })();\n\n    // Invalid cross-realm values\n    expect(() => rawPath`/a/${crossRealmObject}/b`).toThrow(\n      'Path parameters result in path with invalid segments:\\n' +\n        'Value of type Object is not a valid path parameter\\n' +\n        '/a/[object Object]/b\\n' +\n        '   ^^^^^^^^^^^^^^^',\n    );\n    expect(() => rawPath`?${crossRealmMathObject}`).toThrow(\n      'Path parameters result in path with invalid segments:\\n' +\n        'Value of type Math is not a valid path parameter\\n' +\n        '?[object Math]\\n' +\n        ' ^^^^^^^^^^^^^',\n    );\n    expect(() => rawPath`/${crossRealmClass}`).toThrow(\n      'Path parameters result in path with invalid segments:\\n' +\n        'Value of type Object is not a valid path parameter\\n' +\n        '/[object Object]\\n' +\n        ' ^^^^^^^^^^^^^^^',\n    );\n\n    // Valid cross-realm values\n    expect(rawPath`/${crossRealmNumber}`).toBe('/0');\n    expect(rawPath`${crossRealmString}/`).toBe('/');\n    expect(rawPath`/${crossRealmClassWithToString}`).toBe('/ok');\n\n    const results: {\n      [pathParts: string]: {\n        [params: string]: { valid: boolean; result?: string; error?: string };\n      };\n    } = {};\n\n    for (const pathParts of testCases) {\n      const pathResults: Record<string, { valid: boolean; result?: string; error?: string }> = {};\n      results[JSON.stringify(pathParts)] = pathResults;\n      for (const params of paramPermutations(pathParts.length - 1)) {\n        const stringRaw = String.raw({ raw: pathParts }, ...params);\n        const plainString = String.raw(\n          { raw: pathParts.map((e) => e.replace(/\\./g, 'x')) },\n          ...params.map((e) => 'X'.repeat(e.length)),\n        );\n        const normalizedStringRaw = new URL(stringRaw, 'https://example.com').href;\n        const normalizedPlainString = new URL(plainString, 'https://example.com').href;\n        const pathResultsKey = JSON.stringify(params);\n        try {\n          const result = rawPath(pathParts, ...params);\n          expect(result).toBe(stringRaw);\n          // there are no special segments, so the length of the normalized path is\n          // equal to the length of the normalized plain path.\n          expect(normalizedStringRaw.length).toBe(normalizedPlainString.length);\n          pathResults[pathResultsKey] = {\n            valid: true,\n            result,\n          };\n        } catch (e) {\n          const error = String(e);\n          expect(error).toMatch(/Path parameters result in path with invalid segment/);\n          // there are special segments, so the length of the normalized path is\n          // different than the length of the normalized plain path.\n          expect(normalizedStringRaw.length).not.toBe(normalizedPlainString.length);\n          pathResults[pathResultsKey] = {\n            valid: false,\n            error,\n          };\n        }\n      }\n    }\n\n    expect(results).toMatchObject({\n      '[\"/path_params/\",\"/a\"]': {\n        '[\"x\"]': { valid: true, result: '/path_params/x/a' },\n        '[\"\"]': { valid: true, result: '/path_params//a' },\n        '[\"%2E%2e\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2E%2e\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2E%2e/a\\n' +\n            '             ^^^^^^',\n        },\n        '[\"%2E\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2E\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2E/a\\n' +\n            '             ^^^',\n        },\n      },\n      '[\"/path_params/\",\"/\"]': {\n        '[\"x\"]': { valid: true, result: '/path_params/x/' },\n        '[\"\"]': { valid: true, result: '/path_params//' },\n        '[\"%2e%2E\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2e%2E\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2e%2E/\\n' +\n            '             ^^^^^^',\n        },\n        '[\"%2e\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2e\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2e/\\n' +\n            '             ^^^',\n        },\n      },\n      '[\"/path_params/\",\"\"]': {\n        '[\"\"]': { valid: true, result: '/path_params/' },\n        '[\"x\"]': { valid: true, result: '/path_params/x' },\n        '[\"%2E\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2E\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2E\\n' +\n            '             ^^^',\n        },\n        '[\"%2E%2e\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2E%2e\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2E%2e\\n' +\n            '             ^^^^^^',\n        },\n      },\n      '[\"\",\"/a\"]': {\n        '[\"\"]': { valid: true, result: '/a' },\n        '[\"x\"]': { valid: true, result: 'x/a' },\n        '[\"%2E\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2E\" can\\'t be safely passed as a path parameter\\n%2E/a\\n^^^',\n        },\n        '[\"%2e%2E\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2e%2E\" can\\'t be safely passed as a path parameter\\n' +\n            '%2e%2E/a\\n' +\n            '^^^^^^',\n        },\n      },\n      '[\"\",\"/\"]': {\n        '[\"x\"]': { valid: true, result: 'x/' },\n        '[\"\"]': { valid: true, result: '/' },\n        '[\"%2E%2e\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2E%2e\" can\\'t be safely passed as a path parameter\\n' +\n            '%2E%2e/\\n' +\n            '^^^^^^',\n        },\n        '[\".\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \".\" can\\'t be safely passed as a path parameter\\n' +\n            './\\n^',\n        },\n      },\n      '[\"\",\"\"]': {\n        '[\"\"]': { valid: true, result: '' },\n        '[\"x\"]': { valid: true, result: 'x' },\n        '[\"..\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"..\" can\\'t be safely passed as a path parameter\\n' +\n            '..\\n^^',\n        },\n        '[\".\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \".\" can\\'t be safely passed as a path parameter\\n' +\n            '.\\n^',\n        },\n      },\n      '[\"a\"]': {},\n      '[\"\"]': {},\n      '[\"/path_params/\",\":initiate\"]': {\n        '[\"\"]': { valid: true, result: '/path_params/:initiate' },\n        '[\".\"]': { valid: true, result: '/path_params/.:initiate' },\n      },\n      '[\"/path_params/\",\".json\"]': {\n        '[\"x\"]': { valid: true, result: '/path_params/x.json' },\n        '[\".\"]': { valid: true, result: '/path_params/..json' },\n      },\n      '[\"/path_params/\",\"?beta=true\"]': {\n        '[\"x\"]': { valid: true, result: '/path_params/x?beta=true' },\n        '[\"\"]': { valid: true, result: '/path_params/?beta=true' },\n        '[\"%2E%2E\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2E%2E\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2E%2E?beta=true\\n' +\n            '             ^^^^^^',\n        },\n        '[\"%2e%2E\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2e%2E\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2e%2E?beta=true\\n' +\n            '             ^^^^^^',\n        },\n      },\n      '[\"/path_params/\",\".?beta=true\"]': {\n        '[\"..\"]': { valid: true, result: '/path_params/...?beta=true' },\n        '[\"x\"]': { valid: true, result: '/path_params/x.?beta=true' },\n        '[\"\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \".\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/.?beta=true\\n' +\n            '             ^',\n        },\n        '[\"%2e\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2e.\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2e.?beta=true\\n' +\n            '             ^^^^',\n        },\n      },\n      '[\"/path_params/\",\"/\",\"/download\"]': {\n        '[\"\",\"\"]': { valid: true, result: '/path_params///download' },\n        '[\"\",\"x\"]': { valid: true, result: '/path_params//x/download' },\n        '[\".\",\"%2e\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \".\" can\\'t be safely passed as a path parameter\\n' +\n            'Value \"%2e\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/./%2e/download\\n' +\n            '             ^ ^^^',\n        },\n        '[\"%2E%2e\",\"%2e\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2E%2e\" can\\'t be safely passed as a path parameter\\n' +\n            'Value \"%2e\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2E%2e/%2e/download\\n' +\n            '             ^^^^^^ ^^^',\n        },\n      },\n      '[\"/path_params/\",\"-\",\"/download\"]': {\n        '[\"\",\"%2e\"]': { valid: true, result: '/path_params/-%2e/download' },\n        '[\"%2E\",\"..\"]': { valid: true, result: '/path_params/%2E-../download' },\n      },\n      '[\"/path_params/\",\"\",\"/download\"]': {\n        '[\"%2E%2e\",\"%2e%2E\"]': { valid: true, result: '/path_params/%2E%2e%2e%2E/download' },\n        '[\"%2E\",\"..\"]': { valid: true, result: '/path_params/%2E../download' },\n        '[\"\",\"%2E\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2E\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2E/download\\n' +\n            '             ^^^',\n        },\n        '[\"%2E\",\".\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"%2E.\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/%2E./download\\n' +\n            '             ^^^^',\n        },\n      },\n      '[\"/path_params/\",\".\",\"/download\"]': {\n        '[\"%2e%2e\",\"\"]': { valid: true, result: '/path_params/%2e%2e./download' },\n        '[\"\",\"%2e%2e\"]': { valid: true, result: '/path_params/.%2e%2e/download' },\n        '[\"\",\"\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \".\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/./download\\n' +\n            '             ^',\n        },\n        '[\"\",\".\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"..\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/../download\\n' +\n            '             ^^',\n        },\n      },\n      '[\"/path_params/\",\"..\",\"/download\"]': {\n        '[\"\",\"%2E\"]': { valid: true, result: '/path_params/..%2E/download' },\n        '[\"\",\"x\"]': { valid: true, result: '/path_params/..x/download' },\n        '[\"\",\"\"]': {\n          valid: false,\n          error:\n            'Error: Path parameters result in path with invalid segments:\\n' +\n            'Value \"..\" can\\'t be safely passed as a path parameter\\n' +\n            '/path_params/../download\\n' +\n            '             ^^',\n        },\n      },\n    });\n  });\n});\n\ndescribe('encodeURIPath', () => {\n  const testCases: string[] = [\n    '',\n    // Every ASCII character\n    ...Array.from({ length: 0x7f }, (_, i) => String.fromCharCode(i)),\n    // Unicode BMP codepoint\n    'å',\n    // Unicode supplementary codepoint\n    '😃',\n  ];\n\n  for (const param of testCases) {\n    test('properly encodes ' + inspect(param), () => {\n      const encoded = encodeURIPath(param);\n      const naiveEncoded = encodeURIComponent(param);\n      // we should never encode more characters than encodeURIComponent\n      expect(naiveEncoded.length).toBeGreaterThanOrEqual(encoded.length);\n      expect(decodeURIComponent(encoded)).toBe(param);\n    });\n  }\n\n  test(\"leaves ':' intact\", () => {\n    expect(encodeURIPath(':')).toBe(':');\n  });\n\n  test(\"leaves '@' intact\", () => {\n    expect(encodeURIPath('@')).toBe('@');\n  });\n});\n"
  },
  {
    "path": "tests/qs/empty-keys-cases.ts",
    "content": "export const empty_test_cases = [\n  {\n    input: '&',\n    with_empty_keys: {},\n    stringify_output: {\n      brackets: '',\n      indices: '',\n      repeat: '',\n    },\n    no_empty_keys: {},\n  },\n  {\n    input: '&&',\n    with_empty_keys: {},\n    stringify_output: {\n      brackets: '',\n      indices: '',\n      repeat: '',\n    },\n    no_empty_keys: {},\n  },\n  {\n    input: '&=',\n    with_empty_keys: { '': '' },\n    stringify_output: {\n      brackets: '=',\n      indices: '=',\n      repeat: '=',\n    },\n    no_empty_keys: {},\n  },\n  {\n    input: '&=&',\n    with_empty_keys: { '': '' },\n    stringify_output: {\n      brackets: '=',\n      indices: '=',\n      repeat: '=',\n    },\n    no_empty_keys: {},\n  },\n  {\n    input: '&=&=',\n    with_empty_keys: { '': ['', ''] },\n    stringify_output: {\n      brackets: '[]=&[]=',\n      indices: '[0]=&[1]=',\n      repeat: '=&=',\n    },\n    no_empty_keys: {},\n  },\n  {\n    input: '&=&=&',\n    with_empty_keys: { '': ['', ''] },\n    stringify_output: {\n      brackets: '[]=&[]=',\n      indices: '[0]=&[1]=',\n      repeat: '=&=',\n    },\n    no_empty_keys: {},\n  },\n  {\n    input: '=',\n    with_empty_keys: { '': '' },\n    no_empty_keys: {},\n    stringify_output: {\n      brackets: '=',\n      indices: '=',\n      repeat: '=',\n    },\n  },\n  {\n    input: '=&',\n    with_empty_keys: { '': '' },\n    stringify_output: {\n      brackets: '=',\n      indices: '=',\n      repeat: '=',\n    },\n    no_empty_keys: {},\n  },\n  {\n    input: '=&&&',\n    with_empty_keys: { '': '' },\n    stringify_output: {\n      brackets: '=',\n      indices: '=',\n      repeat: '=',\n    },\n    no_empty_keys: {},\n  },\n  {\n    input: '=&=&=&',\n    with_empty_keys: { '': ['', '', ''] },\n    stringify_output: {\n      brackets: '[]=&[]=&[]=',\n      indices: '[0]=&[1]=&[2]=',\n      repeat: '=&=&=',\n    },\n    no_empty_keys: {},\n  },\n  {\n    input: '=&a[]=b&a[1]=c',\n    with_empty_keys: { '': '', a: ['b', 'c'] },\n    stringify_output: {\n      brackets: '=&a[]=b&a[]=c',\n      indices: '=&a[0]=b&a[1]=c',\n      repeat: '=&a=b&a=c',\n    },\n    no_empty_keys: { a: ['b', 'c'] },\n  },\n  {\n    input: '=a',\n    with_empty_keys: { '': 'a' },\n    no_empty_keys: {},\n    stringify_output: {\n      brackets: '=a',\n      indices: '=a',\n      repeat: '=a',\n    },\n  },\n  {\n    input: 'a==a',\n    with_empty_keys: { a: '=a' },\n    no_empty_keys: { a: '=a' },\n    stringify_output: {\n      brackets: 'a==a',\n      indices: 'a==a',\n      repeat: 'a==a',\n    },\n  },\n  {\n    input: '=&a[]=b',\n    with_empty_keys: { '': '', a: ['b'] },\n    stringify_output: {\n      brackets: '=&a[]=b',\n      indices: '=&a[0]=b',\n      repeat: '=&a=b',\n    },\n    no_empty_keys: { a: ['b'] },\n  },\n  {\n    input: '=&a[]=b&a[]=c&a[2]=d',\n    with_empty_keys: { '': '', a: ['b', 'c', 'd'] },\n    stringify_output: {\n      brackets: '=&a[]=b&a[]=c&a[]=d',\n      indices: '=&a[0]=b&a[1]=c&a[2]=d',\n      repeat: '=&a=b&a=c&a=d',\n    },\n    no_empty_keys: { a: ['b', 'c', 'd'] },\n  },\n  {\n    input: '=a&=b',\n    with_empty_keys: { '': ['a', 'b'] },\n    stringify_output: {\n      brackets: '[]=a&[]=b',\n      indices: '[0]=a&[1]=b',\n      repeat: '=a&=b',\n    },\n    no_empty_keys: {},\n  },\n  {\n    input: '=a&foo=b',\n    with_empty_keys: { '': 'a', foo: 'b' },\n    no_empty_keys: { foo: 'b' },\n    stringify_output: {\n      brackets: '=a&foo=b',\n      indices: '=a&foo=b',\n      repeat: '=a&foo=b',\n    },\n  },\n  {\n    input: 'a[]=b&a=c&=',\n    with_empty_keys: { '': '', a: ['b', 'c'] },\n    stringify_output: {\n      brackets: '=&a[]=b&a[]=c',\n      indices: '=&a[0]=b&a[1]=c',\n      repeat: '=&a=b&a=c',\n    },\n    no_empty_keys: { a: ['b', 'c'] },\n  },\n  {\n    input: 'a[]=b&a=c&=',\n    with_empty_keys: { '': '', a: ['b', 'c'] },\n    stringify_output: {\n      brackets: '=&a[]=b&a[]=c',\n      indices: '=&a[0]=b&a[1]=c',\n      repeat: '=&a=b&a=c',\n    },\n    no_empty_keys: { a: ['b', 'c'] },\n  },\n  {\n    input: 'a[0]=b&a=c&=',\n    with_empty_keys: { '': '', a: ['b', 'c'] },\n    stringify_output: {\n      brackets: '=&a[]=b&a[]=c',\n      indices: '=&a[0]=b&a[1]=c',\n      repeat: '=&a=b&a=c',\n    },\n    no_empty_keys: { a: ['b', 'c'] },\n  },\n  {\n    input: 'a=b&a[]=c&=',\n    with_empty_keys: { '': '', a: ['b', 'c'] },\n    stringify_output: {\n      brackets: '=&a[]=b&a[]=c',\n      indices: '=&a[0]=b&a[1]=c',\n      repeat: '=&a=b&a=c',\n    },\n    no_empty_keys: { a: ['b', 'c'] },\n  },\n  {\n    input: 'a=b&a[0]=c&=',\n    with_empty_keys: { '': '', a: ['b', 'c'] },\n    stringify_output: {\n      brackets: '=&a[]=b&a[]=c',\n      indices: '=&a[0]=b&a[1]=c',\n      repeat: '=&a=b&a=c',\n    },\n    no_empty_keys: { a: ['b', 'c'] },\n  },\n  {\n    input: '[]=a&[]=b& []=1',\n    with_empty_keys: { '': ['a', 'b'], ' ': ['1'] },\n    stringify_output: {\n      brackets: '[]=a&[]=b& []=1',\n      indices: '[0]=a&[1]=b& [0]=1',\n      repeat: '=a&=b& =1',\n    },\n    no_empty_keys: { 0: 'a', 1: 'b', ' ': ['1'] },\n  },\n  {\n    input: '[0]=a&[1]=b&a[0]=1&a[1]=2',\n    with_empty_keys: { '': ['a', 'b'], a: ['1', '2'] },\n    no_empty_keys: { 0: 'a', 1: 'b', a: ['1', '2'] },\n    stringify_output: {\n      brackets: '[]=a&[]=b&a[]=1&a[]=2',\n      indices: '[0]=a&[1]=b&a[0]=1&a[1]=2',\n      repeat: '=a&=b&a=1&a=2',\n    },\n  },\n  {\n    input: '[deep]=a&[deep]=2',\n    with_empty_keys: { '': { deep: ['a', '2'] } },\n    stringify_output: {\n      brackets: '[deep][]=a&[deep][]=2',\n      indices: '[deep][0]=a&[deep][1]=2',\n      repeat: '[deep]=a&[deep]=2',\n    },\n    no_empty_keys: { deep: ['a', '2'] },\n  },\n  {\n    input: '%5B0%5D=a&%5B1%5D=b',\n    with_empty_keys: { '': ['a', 'b'] },\n    stringify_output: {\n      brackets: '[]=a&[]=b',\n      indices: '[0]=a&[1]=b',\n      repeat: '=a&=b',\n    },\n    no_empty_keys: { 0: 'a', 1: 'b' },\n  },\n] satisfies {\n  input: string;\n  with_empty_keys: Record<string, unknown>;\n  stringify_output: {\n    brackets: string;\n    indices: string;\n    repeat: string;\n  };\n  no_empty_keys: Record<string, unknown>;\n}[];\n"
  },
  {
    "path": "tests/qs/stringify.test.ts",
    "content": "import iconv from 'iconv-lite';\nimport { stringify } from 'openai/internal/qs';\nimport { encode } from 'openai/internal/qs/utils';\nimport { StringifyOptions } from 'openai/internal/qs/types';\nimport { empty_test_cases } from './empty-keys-cases';\nimport assert from 'assert';\n\ndescribe('stringify()', function () {\n  test('stringifies a querystring object', function () {\n    expect(stringify({ a: 'b' })).toBe('a=b');\n    expect(stringify({ a: 1 })).toBe('a=1');\n    expect(stringify({ a: 1, b: 2 })).toBe('a=1&b=2');\n    expect(stringify({ a: 'A_Z' })).toBe('a=A_Z');\n    expect(stringify({ a: '€' })).toBe('a=%E2%82%AC');\n    expect(stringify({ a: '' })).toBe('a=%EE%80%80');\n    expect(stringify({ a: 'א' })).toBe('a=%D7%90');\n    expect(stringify({ a: '𐐷' })).toBe('a=%F0%90%90%B7');\n  });\n\n  test('stringifies falsy values', function () {\n    expect(stringify(undefined)).toBe('');\n    expect(stringify(null)).toBe('');\n    expect(stringify(null, { strictNullHandling: true })).toBe('');\n    expect(stringify(false)).toBe('');\n    expect(stringify(0)).toBe('');\n  });\n\n  test('stringifies symbols', function () {\n    expect(stringify(Symbol.iterator)).toBe('');\n    expect(stringify([Symbol.iterator])).toBe('0=Symbol%28Symbol.iterator%29');\n    expect(stringify({ a: Symbol.iterator })).toBe('a=Symbol%28Symbol.iterator%29');\n    expect(stringify({ a: [Symbol.iterator] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe(\n      'a[]=Symbol%28Symbol.iterator%29',\n    );\n  });\n\n  test('stringifies bigints', function () {\n    var three = BigInt(3);\n    // @ts-expect-error\n    var encodeWithN = function (value, defaultEncoder, charset) {\n      var result = defaultEncoder(value, defaultEncoder, charset);\n      return typeof value === 'bigint' ? result + 'n' : result;\n    };\n\n    expect(stringify(three)).toBe('');\n    expect(stringify([three])).toBe('0=3');\n    expect(stringify([three], { encoder: encodeWithN })).toBe('0=3n');\n    expect(stringify({ a: three })).toBe('a=3');\n    expect(stringify({ a: three }, { encoder: encodeWithN })).toBe('a=3n');\n    expect(stringify({ a: [three] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe('a[]=3');\n    expect(\n      stringify({ a: [three] }, { encodeValuesOnly: true, encoder: encodeWithN, arrayFormat: 'brackets' }),\n    ).toBe('a[]=3n');\n  });\n\n  test('encodes dot in key of object when encodeDotInKeys and allowDots is provided', function () {\n    expect(\n      stringify({ 'name.obj': { first: 'John', last: 'Doe' } }, { allowDots: false, encodeDotInKeys: false }),\n    ).toBe('name.obj%5Bfirst%5D=John&name.obj%5Blast%5D=Doe');\n    expect(\n      stringify({ 'name.obj': { first: 'John', last: 'Doe' } }, { allowDots: true, encodeDotInKeys: false }),\n    ).toBe('name.obj.first=John&name.obj.last=Doe');\n    expect(\n      stringify({ 'name.obj': { first: 'John', last: 'Doe' } }, { allowDots: false, encodeDotInKeys: true }),\n    ).toBe('name%252Eobj%5Bfirst%5D=John&name%252Eobj%5Blast%5D=Doe');\n    expect(\n      stringify({ 'name.obj': { first: 'John', last: 'Doe' } }, { allowDots: true, encodeDotInKeys: true }),\n    ).toBe('name%252Eobj.first=John&name%252Eobj.last=Doe');\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n    // \t\t{ allowDots: false, encodeDotInKeys: false },\n    // \t),\n    // \t'name.obj.subobject%5Bfirst.godly.name%5D=John&name.obj.subobject%5Blast%5D=Doe',\n    // \t'with allowDots false and encodeDotInKeys false',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n    // \t\t{ allowDots: true, encodeDotInKeys: false },\n    // \t),\n    // \t'name.obj.subobject.first.godly.name=John&name.obj.subobject.last=Doe',\n    // \t'with allowDots false and encodeDotInKeys false',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n    // \t\t{ allowDots: false, encodeDotInKeys: true },\n    // \t),\n    // \t'name%252Eobj%252Esubobject%5Bfirst.godly.name%5D=John&name%252Eobj%252Esubobject%5Blast%5D=Doe',\n    // \t'with allowDots false and encodeDotInKeys true',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n    // \t\t{ allowDots: true, encodeDotInKeys: true },\n    // \t),\n    // \t'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',\n    // \t'with allowDots true and encodeDotInKeys true',\n    // );\n    expect(\n      stringify(\n        { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n        { allowDots: false, encodeDotInKeys: false },\n      ),\n    ).toBe('name.obj.subobject%5Bfirst.godly.name%5D=John&name.obj.subobject%5Blast%5D=Doe');\n    expect(\n      stringify(\n        { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n        { allowDots: true, encodeDotInKeys: false },\n      ),\n    ).toBe('name.obj.subobject.first.godly.name=John&name.obj.subobject.last=Doe');\n    expect(\n      stringify(\n        { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n        { allowDots: false, encodeDotInKeys: true },\n      ),\n    ).toBe('name%252Eobj%252Esubobject%5Bfirst.godly.name%5D=John&name%252Eobj%252Esubobject%5Blast%5D=Doe');\n    expect(\n      stringify(\n        { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n        { allowDots: true, encodeDotInKeys: true },\n      ),\n    ).toBe('name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe');\n  });\n\n  test('should encode dot in key of object, and automatically set allowDots to `true` when encodeDotInKeys is true and allowDots in undefined', function () {\n    // st.equal(\n    // \tstringify(\n    // \t\t{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n    // \t\t{ encodeDotInKeys: true },\n    // \t),\n    // \t'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',\n    // \t'with allowDots undefined and encodeDotInKeys true',\n    // );\n    expect(\n      stringify(\n        { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n        { encodeDotInKeys: true },\n      ),\n    ).toBe('name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe');\n  });\n\n  test('should encode dot in key of object when encodeDotInKeys and allowDots is provided, and nothing else when encodeValuesOnly is provided', function () {\n    // st.equal(\n    // \tstringify(\n    // \t\t{ 'name.obj': { first: 'John', last: 'Doe' } },\n    // \t\t{\n    // \t\t\tencodeDotInKeys: true,\n    // \t\t\tallowDots: true,\n    // \t\t\tencodeValuesOnly: true,\n    // \t\t},\n    // \t),\n    // \t'name%2Eobj.first=John&name%2Eobj.last=Doe',\n    // );\n    expect(\n      stringify(\n        { 'name.obj': { first: 'John', last: 'Doe' } },\n        {\n          encodeDotInKeys: true,\n          allowDots: true,\n          encodeValuesOnly: true,\n        },\n      ),\n    ).toBe('name%2Eobj.first=John&name%2Eobj.last=Doe');\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n    // \t\t{ allowDots: true, encodeDotInKeys: true, encodeValuesOnly: true },\n    // \t),\n    // \t'name%2Eobj%2Esubobject.first%2Egodly%2Ename=John&name%2Eobj%2Esubobject.last=Doe',\n    // );\n    expect(\n      stringify(\n        { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },\n        { allowDots: true, encodeDotInKeys: true, encodeValuesOnly: true },\n      ),\n    ).toBe('name%2Eobj%2Esubobject.first%2Egodly%2Ename=John&name%2Eobj%2Esubobject.last=Doe');\n  });\n\n  test('throws when `commaRoundTrip` is not a boolean', function () {\n    // st['throws'](\n    // \tfunction () {\n    // \t\tstringify({}, { commaRoundTrip: 'not a boolean' });\n    // \t},\n    // \tTypeError,\n    // \t'throws when `commaRoundTrip` is not a boolean',\n    // );\n    expect(() => {\n      // @ts-expect-error\n      stringify({}, { commaRoundTrip: 'not a boolean' });\n    }).toThrow(TypeError);\n  });\n\n  test('throws when `encodeDotInKeys` is not a boolean', function () {\n    // st['throws'](function () {\n    // \tstringify({ a: [], b: 'zz' }, { encodeDotInKeys: 'foobar' });\n    // }, TypeError);\n    expect(() => {\n      // @ts-expect-error\n      stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 'foobar' });\n    }).toThrow(TypeError);\n\n    // st['throws'](function () {\n    // \tstringify({ a: [], b: 'zz' }, { encodeDotInKeys: 0 });\n    // }, TypeError);\n    expect(() => {\n      // @ts-expect-error\n      stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 0 });\n    }).toThrow(TypeError);\n\n    // st['throws'](function () {\n    // \tstringify({ a: [], b: 'zz' }, { encodeDotInKeys: NaN });\n    // }, TypeError);\n    expect(() => {\n      // @ts-expect-error\n      stringify({ a: [], b: 'zz' }, { encodeDotInKeys: NaN });\n    }).toThrow(TypeError);\n\n    // st['throws'](function () {\n    // \tstringify({ a: [], b: 'zz' }, { encodeDotInKeys: null });\n    // }, TypeError);\n    expect(() => {\n      // @ts-expect-error\n      stringify({ a: [], b: 'zz' }, { encodeDotInKeys: null });\n    }).toThrow(TypeError);\n  });\n\n  test('adds query prefix', function () {\n    // st.equal(stringify({ a: 'b' }, { addQueryPrefix: true }), '?a=b');\n    expect(stringify({ a: 'b' }, { addQueryPrefix: true })).toBe('?a=b');\n  });\n\n  test('with query prefix, outputs blank string given an empty object', function () {\n    // st.equal(stringify({}, { addQueryPrefix: true }), '');\n    expect(stringify({}, { addQueryPrefix: true })).toBe('');\n  });\n\n  test('stringifies nested falsy values', function () {\n    // st.equal(stringify({ a: { b: { c: null } } }), 'a%5Bb%5D%5Bc%5D=');\n    // st.equal(\n    // \tstringify({ a: { b: { c: null } } }, { strictNullHandling: true }),\n    // \t'a%5Bb%5D%5Bc%5D',\n    // );\n    // st.equal(stringify({ a: { b: { c: false } } }), 'a%5Bb%5D%5Bc%5D=false');\n    expect(stringify({ a: { b: { c: null } } })).toBe('a%5Bb%5D%5Bc%5D=');\n    expect(stringify({ a: { b: { c: null } } }, { strictNullHandling: true })).toBe('a%5Bb%5D%5Bc%5D');\n    expect(stringify({ a: { b: { c: false } } })).toBe('a%5Bb%5D%5Bc%5D=false');\n  });\n\n  test('stringifies a nested object', function () {\n    // st.equal(stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');\n    // st.equal(stringify({ a: { b: { c: { d: 'e' } } } }), 'a%5Bb%5D%5Bc%5D%5Bd%5D=e');\n    expect(stringify({ a: { b: 'c' } })).toBe('a%5Bb%5D=c');\n    expect(stringify({ a: { b: { c: { d: 'e' } } } })).toBe('a%5Bb%5D%5Bc%5D%5Bd%5D=e');\n  });\n\n  test('`allowDots` option: stringifies a nested object with dots notation', function () {\n    // st.equal(stringify({ a: { b: 'c' } }, { allowDots: true }), 'a.b=c');\n    // st.equal(stringify({ a: { b: { c: { d: 'e' } } } }, { allowDots: true }), 'a.b.c.d=e');\n    expect(stringify({ a: { b: 'c' } }, { allowDots: true })).toBe('a.b=c');\n    expect(stringify({ a: { b: { c: { d: 'e' } } } }, { allowDots: true })).toBe('a.b.c.d=e');\n  });\n\n  test('stringifies an array value', function () {\n    // st.equal(\n    // \tstringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'indices' }),\n    // \t'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',\n    // \t'indices => indices',\n    // );\n    // st.equal(\n    // \tstringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'brackets' }),\n    // \t'a%5B%5D=b&a%5B%5D=c&a%5B%5D=d',\n    // \t'brackets => brackets',\n    // );\n    // st.equal(\n    // \tstringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma' }),\n    // \t'a=b%2Cc%2Cd',\n    // \t'comma => comma',\n    // );\n    // st.equal(\n    // \tstringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma', commaRoundTrip: true }),\n    // \t'a=b%2Cc%2Cd',\n    // \t'comma round trip => comma',\n    // );\n    // st.equal(\n    // \tstringify({ a: ['b', 'c', 'd'] }),\n    // \t'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',\n    // \t'default => indices',\n    // );\n    expect(stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'indices' })).toBe(\n      'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',\n    );\n    expect(stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'brackets' })).toBe(\n      'a%5B%5D=b&a%5B%5D=c&a%5B%5D=d',\n    );\n    expect(stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma' })).toBe('a=b%2Cc%2Cd');\n    expect(stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma', commaRoundTrip: true })).toBe(\n      'a=b%2Cc%2Cd',\n    );\n    expect(stringify({ a: ['b', 'c', 'd'] })).toBe('a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d');\n  });\n\n  test('`skipNulls` option', function () {\n    // st.equal(\n    // \tstringify({ a: 'b', c: null }, { skipNulls: true }),\n    // \t'a=b',\n    // \t'omits nulls when asked',\n    // );\n    expect(stringify({ a: 'b', c: null }, { skipNulls: true })).toBe('a=b');\n\n    // st.equal(\n    // \tstringify({ a: { b: 'c', d: null } }, { skipNulls: true }),\n    // \t'a%5Bb%5D=c',\n    // \t'omits nested nulls when asked',\n    // );\n    expect(stringify({ a: { b: 'c', d: null } }, { skipNulls: true })).toBe('a%5Bb%5D=c');\n  });\n\n  test('omits array indices when asked', function () {\n    // st.equal(stringify({ a: ['b', 'c', 'd'] }, { indices: false }), 'a=b&a=c&a=d');\n    expect(stringify({ a: ['b', 'c', 'd'] }, { indices: false })).toBe('a=b&a=c&a=d');\n  });\n\n  test('omits object key/value pair when value is empty array', function () {\n    // st.equal(stringify({ a: [], b: 'zz' }), 'b=zz');\n    expect(stringify({ a: [], b: 'zz' })).toBe('b=zz');\n  });\n\n  test('should not omit object key/value pair when value is empty array and when asked', function () {\n    // st.equal(stringify({ a: [], b: 'zz' }), 'b=zz');\n    // st.equal(stringify({ a: [], b: 'zz' }, { allowEmptyArrays: false }), 'b=zz');\n    // st.equal(stringify({ a: [], b: 'zz' }, { allowEmptyArrays: true }), 'a[]&b=zz');\n    expect(stringify({ a: [], b: 'zz' })).toBe('b=zz');\n    expect(stringify({ a: [], b: 'zz' }, { allowEmptyArrays: false })).toBe('b=zz');\n    expect(stringify({ a: [], b: 'zz' }, { allowEmptyArrays: true })).toBe('a[]&b=zz');\n  });\n\n  test('should throw when allowEmptyArrays is not of type boolean', function () {\n    // st['throws'](function () {\n    // \tstringify({ a: [], b: 'zz' }, { allowEmptyArrays: 'foobar' });\n    // }, TypeError);\n    expect(() => {\n      // @ts-expect-error\n      stringify({ a: [], b: 'zz' }, { allowEmptyArrays: 'foobar' });\n    }).toThrow(TypeError);\n\n    // st['throws'](function () {\n    // \tstringify({ a: [], b: 'zz' }, { allowEmptyArrays: 0 });\n    // }, TypeError);\n    expect(() => {\n      // @ts-expect-error\n      stringify({ a: [], b: 'zz' }, { allowEmptyArrays: 0 });\n    }).toThrow(TypeError);\n\n    // st['throws'](function () {\n    // \tstringify({ a: [], b: 'zz' }, { allowEmptyArrays: NaN });\n    // }, TypeError);\n    expect(() => {\n      // @ts-expect-error\n      stringify({ a: [], b: 'zz' }, { allowEmptyArrays: NaN });\n    }).toThrow(TypeError);\n\n    // st['throws'](function () {\n    // \tstringify({ a: [], b: 'zz' }, { allowEmptyArrays: null });\n    // }, TypeError);\n    expect(() => {\n      // @ts-expect-error\n      stringify({ a: [], b: 'zz' }, { allowEmptyArrays: null });\n    }).toThrow(TypeError);\n  });\n\n  test('allowEmptyArrays + strictNullHandling', function () {\n    // st.equal(\n    // \tstringify({ testEmptyArray: [] }, { strictNullHandling: true, allowEmptyArrays: true }),\n    // \t'testEmptyArray[]',\n    // );\n    expect(stringify({ testEmptyArray: [] }, { strictNullHandling: true, allowEmptyArrays: true })).toBe(\n      'testEmptyArray[]',\n    );\n  });\n\n  describe('stringifies an array value with one item vs multiple items', function () {\n    test('non-array item', function () {\n      // s2t.equal(\n      // \tstringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'indices' }),\n      // \t'a=c',\n      // );\n      // s2t.equal(\n      // \tstringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),\n      // \t'a=c',\n      // );\n      // s2t.equal(stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c');\n      // s2t.equal(stringify({ a: 'c' }, { encodeValuesOnly: true }), 'a=c');\n      expect(stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe('a=c');\n      expect(stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe('a=c');\n      expect(stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'comma' })).toBe('a=c');\n      expect(stringify({ a: 'c' }, { encodeValuesOnly: true })).toBe('a=c');\n    });\n\n    test('array with a single item', function () {\n      // s2t.equal(\n      // \tstringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),\n      // \t'a[0]=c',\n      // );\n      // s2t.equal(\n      // \tstringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),\n      // \t'a[]=c',\n      // );\n      // s2t.equal(\n      // \tstringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),\n      // \t'a=c',\n      // );\n      // s2t.equal(\n      // \tstringify(\n      // \t\t{ a: ['c'] },\n      // \t\t{ encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true },\n      // \t),\n      // \t'a[]=c',\n      // ); // so it parses back as an array\n      // s2t.equal(stringify({ a: ['c'] }, { encodeValuesOnly: true }), 'a[0]=c');\n      expect(stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe('a[0]=c');\n      expect(stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe('a[]=c');\n      expect(stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma' })).toBe('a=c');\n      expect(\n        stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true }),\n      ).toBe('a[]=c');\n      expect(stringify({ a: ['c'] }, { encodeValuesOnly: true })).toBe('a[0]=c');\n    });\n\n    test('array with multiple items', function () {\n      // s2t.equal(\n      // \tstringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),\n      // \t'a[0]=c&a[1]=d',\n      // );\n      // s2t.equal(\n      // \tstringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),\n      // \t'a[]=c&a[]=d',\n      // );\n      // s2t.equal(\n      // \tstringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),\n      // \t'a=c,d',\n      // );\n      // s2t.equal(\n      // \tstringify(\n      // \t\t{ a: ['c', 'd'] },\n      // \t\t{ encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true },\n      // \t),\n      // \t'a=c,d',\n      // );\n      // s2t.equal(stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true }), 'a[0]=c&a[1]=d');\n      expect(stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe(\n        'a[0]=c&a[1]=d',\n      );\n      expect(stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe(\n        'a[]=c&a[]=d',\n      );\n      expect(stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma' })).toBe('a=c,d');\n      expect(\n        stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true }),\n      ).toBe('a=c,d');\n      expect(stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true })).toBe('a[0]=c&a[1]=d');\n    });\n\n    test('array with multiple items with a comma inside', function () {\n      // s2t.equal(\n      // \tstringify({ a: ['c,d', 'e'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),\n      // \t'a=c%2Cd,e',\n      // );\n      // s2t.equal(stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma' }), 'a=c%2Cd%2Ce');\n      expect(stringify({ a: ['c,d', 'e'] }, { encodeValuesOnly: true, arrayFormat: 'comma' })).toBe(\n        'a=c%2Cd,e',\n      );\n      expect(stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma' })).toBe('a=c%2Cd%2Ce');\n\n      // s2t.equal(\n      // \tstringify(\n      // \t\t{ a: ['c,d', 'e'] },\n      // \t\t{ encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true },\n      // \t),\n      // \t'a=c%2Cd,e',\n      // );\n      // s2t.equal(\n      // \tstringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma', commaRoundTrip: true }),\n      // \t'a=c%2Cd%2Ce',\n      // );\n      expect(\n        stringify(\n          { a: ['c,d', 'e'] },\n          { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true },\n        ),\n      ).toBe('a=c%2Cd,e');\n      expect(stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma', commaRoundTrip: true })).toBe(\n        'a=c%2Cd%2Ce',\n      );\n    });\n  });\n\n  test('stringifies a nested array value', function () {\n    expect(stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe(\n      'a[b][0]=c&a[b][1]=d',\n    );\n    expect(stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe(\n      'a[b][]=c&a[b][]=d',\n    );\n    expect(stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'comma' })).toBe(\n      'a[b]=c,d',\n    );\n    expect(stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true })).toBe('a[b][0]=c&a[b][1]=d');\n  });\n\n  test('stringifies comma and empty array values', function () {\n    // st.equal(\n    // \tstringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'indices' }),\n    // \t'a[0]=,&a[1]=&a[2]=c,d%',\n    // );\n    // st.equal(\n    // \tstringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'brackets' }),\n    // \t'a[]=,&a[]=&a[]=c,d%',\n    // );\n    // st.equal(\n    // \tstringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'comma' }),\n    // \t'a=,,,c,d%',\n    // );\n    // st.equal(\n    // \tstringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'repeat' }),\n    // \t'a=,&a=&a=c,d%',\n    // );\n    expect(stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'indices' })).toBe(\n      'a[0]=,&a[1]=&a[2]=c,d%',\n    );\n    expect(stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'brackets' })).toBe(\n      'a[]=,&a[]=&a[]=c,d%',\n    );\n    expect(stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'comma' })).toBe('a=,,,c,d%');\n    expect(stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'repeat' })).toBe(\n      'a=,&a=&a=c,d%',\n    );\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [',', '', 'c,d%'] },\n    // \t\t{ encode: true, encodeValuesOnly: true, arrayFormat: 'indices' },\n    // \t),\n    // \t'a[0]=%2C&a[1]=&a[2]=c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [',', '', 'c,d%'] },\n    // \t\t{ encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a[]=%2C&a[]=&a[]=c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [',', '', 'c,d%'] },\n    // \t\t{ encode: true, encodeValuesOnly: true, arrayFormat: 'comma' },\n    // \t),\n    // \t'a=%2C,,c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [',', '', 'c,d%'] },\n    // \t\t{ encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' },\n    // \t),\n    // \t'a=%2C&a=&a=c%2Cd%25',\n    // );\n    expect(\n      stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' }),\n    ).toBe('a%5B0%5D=%2C&a%5B1%5D=&a%5B2%5D=c%2Cd%25');\n    expect(\n      stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' }),\n    ).toBe('a[]=%2C&a[]=&a[]=c%2Cd%25');\n    expect(\n      stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' }),\n    ).toBe('a=%2C%2C%2Cc%2Cd%25');\n    expect(\n      stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }),\n    ).toBe('a=%2C&a=&a=c%2Cd%25');\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [',', '', 'c,d%'] },\n    // \t\t{ encode: true, encodeValuesOnly: false, arrayFormat: 'indices' },\n    // \t),\n    // \t'a%5B0%5D=%2C&a%5B1%5D=&a%5B2%5D=c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [',', '', 'c,d%'] },\n    // \t\t{ encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a%5B%5D=%2C&a%5B%5D=&a%5B%5D=c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [',', '', 'c,d%'] },\n    // \t\t{ encode: true, encodeValuesOnly: false, arrayFormat: 'comma' },\n    // \t),\n    // \t'a=%2C%2C%2Cc%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [',', '', 'c,d%'] },\n    // \t\t{ encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' },\n    // \t),\n    // \t'a=%2C&a=&a=c%2Cd%25',\n    // );\n    expect(\n      stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }),\n    ).toBe('a=%2C&a=&a=c%2Cd%25');\n    expect(\n      stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' }),\n    ).toBe('a%5B0%5D=%2C&a%5B1%5D=&a%5B2%5D=c%2Cd%25');\n    expect(\n      stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' }),\n    ).toBe('a[]=%2C&a[]=&a[]=c%2Cd%25');\n    expect(\n      stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' }),\n    ).toBe('a=%2C%2C%2Cc%2Cd%25');\n    expect(\n      stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }),\n    ).toBe('a=%2C&a=&a=c%2Cd%25');\n  });\n\n  test('stringifies comma and empty non-array values', function () {\n    // st.equal(\n    // \tstringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'indices' }),\n    // \t'a=,&b=&c=c,d%',\n    // );\n    // st.equal(\n    // \tstringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'brackets' }),\n    // \t'a=,&b=&c=c,d%',\n    // );\n    // st.equal(\n    // \tstringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'comma' }),\n    // \t'a=,&b=&c=c,d%',\n    // );\n    // st.equal(\n    // \tstringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'repeat' }),\n    // \t'a=,&b=&c=c,d%',\n    // );\n    expect(stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'indices' })).toBe(\n      'a=,&b=&c=c,d%',\n    );\n    expect(stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'brackets' })).toBe(\n      'a=,&b=&c=c,d%',\n    );\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: ',', b: '', c: 'c,d%' },\n    // \t\t{ encode: true, encodeValuesOnly: true, arrayFormat: 'indices' },\n    // \t),\n    // \t'a=%2C&b=&c=c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: ',', b: '', c: 'c,d%' },\n    // \t\t{ encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a=%2C&b=&c=c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: ',', b: '', c: 'c,d%' },\n    // \t\t{ encode: true, encodeValuesOnly: true, arrayFormat: 'comma' },\n    // \t),\n    // \t'a=%2C&b=&c=c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: ',', b: '', c: 'c,d%' },\n    // \t\t{ encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' },\n    // \t),\n    // \t'a=%2C&b=&c=c%2Cd%25',\n    // );\n    expect(\n      stringify(\n        { a: ',', b: '', c: 'c,d%' },\n        { encode: true, encodeValuesOnly: true, arrayFormat: 'indices' },\n      ),\n    ).toBe('a=%2C&b=&c=c%2Cd%25');\n    expect(\n      stringify(\n        { a: ',', b: '', c: 'c,d%' },\n        { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' },\n      ),\n    ).toBe('a=%2C&b=&c=c%2Cd%25');\n    expect(\n      stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'comma' }),\n    ).toBe('a=%2C&b=&c=c%2Cd%25');\n    expect(\n      stringify(\n        { a: ',', b: '', c: 'c,d%' },\n        { encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' },\n      ),\n    ).toBe('a=%2C&b=&c=c%2Cd%25');\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: ',', b: '', c: 'c,d%' },\n    // \t\t{ encode: true, encodeValuesOnly: false, arrayFormat: 'indices' },\n    // \t),\n    // \t'a=%2C&b=&c=c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: ',', b: '', c: 'c,d%' },\n    // \t\t{ encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a=%2C&b=&c=c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: ',', b: '', c: 'c,d%' },\n    // \t\t{ encode: true, encodeValuesOnly: false, arrayFormat: 'comma' },\n    // \t),\n    // \t'a=%2C&b=&c=c%2Cd%25',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: ',', b: '', c: 'c,d%' },\n    // \t\t{ encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' },\n    // \t),\n    // \t'a=%2C&b=&c=c%2Cd%25',\n    // );\n    expect(\n      stringify(\n        { a: ',', b: '', c: 'c,d%' },\n        { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' },\n      ),\n    ).toBe('a=%2C&b=&c=c%2Cd%25');\n    expect(\n      stringify(\n        { a: ',', b: '', c: 'c,d%' },\n        { encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' },\n      ),\n    ).toBe('a=%2C&b=&c=c%2Cd%25');\n    expect(\n      stringify(\n        { a: ',', b: '', c: 'c,d%' },\n        { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' },\n      ),\n    ).toBe('a=%2C&b=&c=c%2Cd%25');\n    expect(\n      stringify(\n        { a: ',', b: '', c: 'c,d%' },\n        { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' },\n      ),\n    ).toBe('a=%2C&b=&c=c%2Cd%25');\n  });\n\n  test('stringifies a nested array value with dots notation', function () {\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: { b: ['c', 'd'] } },\n    // \t\t{ allowDots: true, encodeValuesOnly: true, arrayFormat: 'indices' },\n    // \t),\n    // \t'a.b[0]=c&a.b[1]=d',\n    // \t'indices: stringifies with dots + indices',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: { b: ['c', 'd'] } },\n    // \t\t{ allowDots: true, encodeValuesOnly: true, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a.b[]=c&a.b[]=d',\n    // \t'brackets: stringifies with dots + brackets',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: { b: ['c', 'd'] } },\n    // \t\t{ allowDots: true, encodeValuesOnly: true, arrayFormat: 'comma' },\n    // \t),\n    // \t'a.b=c,d',\n    // \t'comma: stringifies with dots + comma',\n    // );\n    // st.equal(\n    // \tstringify({ a: { b: ['c', 'd'] } }, { allowDots: true, encodeValuesOnly: true }),\n    // \t'a.b[0]=c&a.b[1]=d',\n    // \t'default: stringifies with dots + indices',\n    // );\n    expect(\n      stringify(\n        { a: { b: ['c', 'd'] } },\n        { allowDots: true, encodeValuesOnly: true, arrayFormat: 'indices' },\n      ),\n    ).toBe('a.b[0]=c&a.b[1]=d');\n    expect(\n      stringify(\n        { a: { b: ['c', 'd'] } },\n        { allowDots: true, encodeValuesOnly: true, arrayFormat: 'brackets' },\n      ),\n    ).toBe('a.b[]=c&a.b[]=d');\n    expect(\n      stringify({ a: { b: ['c', 'd'] } }, { allowDots: true, encodeValuesOnly: true, arrayFormat: 'comma' }),\n    ).toBe('a.b=c,d');\n    expect(stringify({ a: { b: ['c', 'd'] } }, { allowDots: true, encodeValuesOnly: true })).toBe(\n      'a.b[0]=c&a.b[1]=d',\n    );\n  });\n\n  test('stringifies an object inside an array', function () {\n    // st.equal(\n    // \tstringify({ a: [{ b: 'c' }] }, { arrayFormat: 'indices', encodeValuesOnly: true }),\n    // \t'a[0][b]=c',\n    // \t'indices => indices',\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: 'c' }] }, { arrayFormat: 'repeat', encodeValuesOnly: true }),\n    // \t'a[b]=c',\n    // \t'repeat => repeat',\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: 'c' }] }, { arrayFormat: 'brackets', encodeValuesOnly: true }),\n    // \t'a[][b]=c',\n    // \t'brackets => brackets',\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: 'c' }] }, { encodeValuesOnly: true }),\n    // \t'a[0][b]=c',\n    // \t'default => indices',\n    // );\n    expect(stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'indices', encodeValuesOnly: true })).toBe(\n      'a[0][b]=c',\n    );\n    expect(stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'repeat', encodeValuesOnly: true })).toBe('a[b]=c');\n    expect(stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'brackets', encodeValuesOnly: true })).toBe(\n      'a[][b]=c',\n    );\n    expect(stringify({ a: [{ b: 'c' }] }, { encodeValuesOnly: true })).toBe('a[0][b]=c');\n\n    // st.equal(\n    // \tstringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'indices', encodeValuesOnly: true }),\n    // \t'a[0][b][c][0]=1',\n    // \t'indices => indices',\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'repeat', encodeValuesOnly: true }),\n    // \t'a[b][c]=1',\n    // \t'repeat => repeat',\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'brackets', encodeValuesOnly: true }),\n    // \t'a[][b][c][]=1',\n    // \t'brackets => brackets',\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: { c: [1] } }] }, { encodeValuesOnly: true }),\n    // \t'a[0][b][c][0]=1',\n    // \t'default => indices',\n    // );\n    expect(stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'indices', encodeValuesOnly: true })).toBe(\n      'a[0][b][c][0]=1',\n    );\n    expect(stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'repeat', encodeValuesOnly: true })).toBe(\n      'a[b][c]=1',\n    );\n    expect(stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'brackets', encodeValuesOnly: true })).toBe(\n      'a[][b][c][]=1',\n    );\n    expect(stringify({ a: [{ b: { c: [1] } }] }, { encodeValuesOnly: true })).toBe('a[0][b][c][0]=1');\n  });\n\n  test('stringifies an array with mixed objects and primitives', function () {\n    // st.equal(\n    // \tstringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),\n    // \t'a[0][b]=1&a[1]=2&a[2]=3',\n    // \t'indices => indices',\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),\n    // \t'a[][b]=1&a[]=2&a[]=3',\n    // \t'brackets => brackets',\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),\n    // \t'???',\n    // \t'brackets => brackets',\n    // \t{ skip: 'TODO: figure out what this should do' },\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true }),\n    // \t'a[0][b]=1&a[1]=2&a[2]=3',\n    // \t'default => indices',\n    // );\n    expect(stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe(\n      'a[0][b]=1&a[1]=2&a[2]=3',\n    );\n    expect(stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe(\n      'a[][b]=1&a[]=2&a[]=3',\n    );\n    // !Skipped: Figure out what this should do\n    // expect(\n    // \tstringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),\n    // ).toBe('???');\n    expect(stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true })).toBe('a[0][b]=1&a[1]=2&a[2]=3');\n  });\n\n  test('stringifies an object inside an array with dots notation', function () {\n    // st.equal(\n    // \tstringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false, arrayFormat: 'indices' }),\n    // \t'a[0].b=c',\n    // \t'indices => indices',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [{ b: 'c' }] },\n    // \t\t{ allowDots: true, encode: false, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a[].b=c',\n    // \t'brackets => brackets',\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false }),\n    // \t'a[0].b=c',\n    // \t'default => indices',\n    // );\n    expect(stringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false, arrayFormat: 'indices' })).toBe(\n      'a[0].b=c',\n    );\n    expect(stringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false, arrayFormat: 'brackets' })).toBe(\n      'a[].b=c',\n    );\n    expect(stringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false })).toBe('a[0].b=c');\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [{ b: { c: [1] } }] },\n    // \t\t{ allowDots: true, encode: false, arrayFormat: 'indices' },\n    // \t),\n    // \t'a[0].b.c[0]=1',\n    // \t'indices => indices',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [{ b: { c: [1] } }] },\n    // \t\t{ allowDots: true, encode: false, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a[].b.c[]=1',\n    // \t'brackets => brackets',\n    // );\n    // st.equal(\n    // \tstringify({ a: [{ b: { c: [1] } }] }, { allowDots: true, encode: false }),\n    // \t'a[0].b.c[0]=1',\n    // \t'default => indices',\n    // );\n    expect(\n      stringify({ a: [{ b: { c: [1] } }] }, { allowDots: true, encode: false, arrayFormat: 'indices' }),\n    ).toBe('a[0].b.c[0]=1');\n    expect(\n      stringify({ a: [{ b: { c: [1] } }] }, { allowDots: true, encode: false, arrayFormat: 'brackets' }),\n    ).toBe('a[].b.c[]=1');\n    expect(stringify({ a: [{ b: { c: [1] } }] }, { allowDots: true, encode: false })).toBe('a[0].b.c[0]=1');\n  });\n\n  test('does not omit object keys when indices = false', function () {\n    // st.equal(stringify({ a: [{ b: 'c' }] }, { indices: false }), 'a%5Bb%5D=c');\n    expect(stringify({ a: [{ b: 'c' }] }, { indices: false })).toBe('a%5Bb%5D=c');\n  });\n\n  test('uses indices notation for arrays when indices=true', function () {\n    // st.equal(stringify({ a: ['b', 'c'] }, { indices: true }), 'a%5B0%5D=b&a%5B1%5D=c');\n    expect(stringify({ a: ['b', 'c'] }, { indices: true })).toBe('a%5B0%5D=b&a%5B1%5D=c');\n  });\n\n  test('uses indices notation for arrays when no arrayFormat is specified', function () {\n    // st.equal(stringify({ a: ['b', 'c'] }), 'a%5B0%5D=b&a%5B1%5D=c');\n    expect(stringify({ a: ['b', 'c'] })).toBe('a%5B0%5D=b&a%5B1%5D=c');\n  });\n\n  test('uses indices notation for arrays when arrayFormat=indices', function () {\n    // st.equal(stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' }), 'a%5B0%5D=b&a%5B1%5D=c');\n    expect(stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })).toBe('a%5B0%5D=b&a%5B1%5D=c');\n  });\n\n  test('uses repeat notation for arrays when arrayFormat=repeat', function () {\n    // st.equal(stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' }), 'a=b&a=c');\n    expect(stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })).toBe('a=b&a=c');\n  });\n\n  test('uses brackets notation for arrays when arrayFormat=brackets', function () {\n    // st.equal(stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' }), 'a%5B%5D=b&a%5B%5D=c');\n    expect(stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })).toBe('a%5B%5D=b&a%5B%5D=c');\n  });\n\n  test('stringifies a complicated object', function () {\n    // st.equal(stringify({ a: { b: 'c', d: 'e' } }), 'a%5Bb%5D=c&a%5Bd%5D=e');\n    expect(stringify({ a: { b: 'c', d: 'e' } })).toBe('a%5Bb%5D=c&a%5Bd%5D=e');\n  });\n\n  test('stringifies an empty value', function () {\n    // st.equal(stringify({ a: '' }), 'a=');\n    // st.equal(stringify({ a: null }, { strictNullHandling: true }), 'a');\n    expect(stringify({ a: '' })).toBe('a=');\n    expect(stringify({ a: null }, { strictNullHandling: true })).toBe('a');\n\n    // st.equal(stringify({ a: '', b: '' }), 'a=&b=');\n    // st.equal(stringify({ a: null, b: '' }, { strictNullHandling: true }), 'a&b=');\n    expect(stringify({ a: '', b: '' })).toBe('a=&b=');\n    expect(stringify({ a: null, b: '' }, { strictNullHandling: true })).toBe('a&b=');\n\n    // st.equal(stringify({ a: { b: '' } }), 'a%5Bb%5D=');\n    // st.equal(stringify({ a: { b: null } }, { strictNullHandling: true }), 'a%5Bb%5D');\n    // st.equal(stringify({ a: { b: null } }, { strictNullHandling: false }), 'a%5Bb%5D=');\n    expect(stringify({ a: { b: '' } })).toBe('a%5Bb%5D=');\n    expect(stringify({ a: { b: null } }, { strictNullHandling: true })).toBe('a%5Bb%5D');\n    expect(stringify({ a: { b: null } }, { strictNullHandling: false })).toBe('a%5Bb%5D=');\n  });\n\n  test('stringifies an empty array in different arrayFormat', function () {\n    // st.equal(stringify({ a: [], b: [null], c: 'c' }, { encode: false }), 'b[0]=&c=c');\n    expect(stringify({ a: [], b: [null], c: 'c' }, { encode: false })).toBe('b[0]=&c=c');\n    // arrayFormat default\n    // st.equal(\n    // \tstringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices' }),\n    // \t'b[0]=&c=c',\n    // );\n    // st.equal(\n    // \tstringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets' }),\n    // \t'b[]=&c=c',\n    // );\n    // st.equal(\n    // \tstringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat' }),\n    // \t'b=&c=c',\n    // );\n    // st.equal(\n    // \tstringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma' }),\n    // \t'b=&c=c',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [], b: [null], c: 'c' },\n    // \t\t{ encode: false, arrayFormat: 'comma', commaRoundTrip: true },\n    // \t),\n    // \t'b[]=&c=c',\n    // );\n    expect(stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices' })).toBe(\n      'b[0]=&c=c',\n    );\n    expect(stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets' })).toBe(\n      'b[]=&c=c',\n    );\n    expect(stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat' })).toBe('b=&c=c');\n    expect(stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma' })).toBe('b=&c=c');\n    expect(\n      stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', commaRoundTrip: true }),\n    ).toBe('b[]=&c=c');\n\n    // with strictNullHandling\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [], b: [null], c: 'c' },\n    // \t\t{ encode: false, arrayFormat: 'indices', strictNullHandling: true },\n    // \t),\n    // \t'b[0]&c=c',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [], b: [null], c: 'c' },\n    // \t\t{ encode: false, arrayFormat: 'brackets', strictNullHandling: true },\n    // \t),\n    // \t'b[]&c=c',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [], b: [null], c: 'c' },\n    // \t\t{ encode: false, arrayFormat: 'repeat', strictNullHandling: true },\n    // \t),\n    // \t'b&c=c',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [], b: [null], c: 'c' },\n    // \t\t{ encode: false, arrayFormat: 'comma', strictNullHandling: true },\n    // \t),\n    // \t'b&c=c',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [], b: [null], c: 'c' },\n    // \t\t{ encode: false, arrayFormat: 'comma', strictNullHandling: true, commaRoundTrip: true },\n    // \t),\n    // \t'b[]&c=c',\n    // );\n\n    expect(\n      stringify(\n        { a: [], b: [null], c: 'c' },\n        { encode: false, arrayFormat: 'indices', strictNullHandling: true },\n      ),\n    ).toBe('b[0]&c=c');\n    expect(\n      stringify(\n        { a: [], b: [null], c: 'c' },\n        { encode: false, arrayFormat: 'brackets', strictNullHandling: true },\n      ),\n    ).toBe('b[]&c=c');\n    expect(\n      stringify(\n        { a: [], b: [null], c: 'c' },\n        { encode: false, arrayFormat: 'repeat', strictNullHandling: true },\n      ),\n    ).toBe('b&c=c');\n    expect(\n      stringify(\n        { a: [], b: [null], c: 'c' },\n        { encode: false, arrayFormat: 'comma', strictNullHandling: true },\n      ),\n    ).toBe('b&c=c');\n    expect(\n      stringify(\n        { a: [], b: [null], c: 'c' },\n        { encode: false, arrayFormat: 'comma', strictNullHandling: true, commaRoundTrip: true },\n      ),\n    ).toBe('b[]&c=c');\n\n    // with skipNulls\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [], b: [null], c: 'c' },\n    // \t\t{ encode: false, arrayFormat: 'indices', skipNulls: true },\n    // \t),\n    // \t'c=c',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [], b: [null], c: 'c' },\n    // \t\t{ encode: false, arrayFormat: 'brackets', skipNulls: true },\n    // \t),\n    // \t'c=c',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [], b: [null], c: 'c' },\n    // \t\t{ encode: false, arrayFormat: 'repeat', skipNulls: true },\n    // \t),\n    // \t'c=c',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [], b: [null], c: 'c' },\n    // \t\t{ encode: false, arrayFormat: 'comma', skipNulls: true },\n    // \t),\n    // \t'c=c',\n    // );\n    expect(\n      stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices', skipNulls: true }),\n    ).toBe('c=c');\n    expect(\n      stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets', skipNulls: true }),\n    ).toBe('c=c');\n    expect(\n      stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat', skipNulls: true }),\n    ).toBe('c=c');\n    expect(\n      stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', skipNulls: true }),\n    ).toBe('c=c');\n  });\n\n  test('stringifies a null object', function () {\n    var obj = Object.create(null);\n    obj.a = 'b';\n    // st.equal(stringify(obj), 'a=b');\n    expect(stringify(obj)).toBe('a=b');\n  });\n\n  test('returns an empty string for invalid input', function () {\n    // st.equal(stringify(undefined), '');\n    // st.equal(stringify(false), '');\n    // st.equal(stringify(null), '');\n    // st.equal(stringify(''), '');\n    expect(stringify(undefined)).toBe('');\n    expect(stringify(false)).toBe('');\n    expect(stringify(null)).toBe('');\n    expect(stringify('')).toBe('');\n  });\n\n  test('stringifies an object with a null object as a child', function () {\n    var obj = { a: Object.create(null) };\n\n    obj.a.b = 'c';\n    // st.equal(stringify(obj), 'a%5Bb%5D=c');\n    expect(stringify(obj)).toBe('a%5Bb%5D=c');\n  });\n\n  test('drops keys with a value of undefined', function () {\n    // st.equal(stringify({ a: undefined }), '');\n    expect(stringify({ a: undefined })).toBe('');\n\n    // st.equal(\n    // \tstringify({ a: { b: undefined, c: null } }, { strictNullHandling: true }),\n    // \t'a%5Bc%5D',\n    // );\n    // st.equal(\n    // \tstringify({ a: { b: undefined, c: null } }, { strictNullHandling: false }),\n    // \t'a%5Bc%5D=',\n    // );\n    // st.equal(stringify({ a: { b: undefined, c: '' } }), 'a%5Bc%5D=');\n    expect(stringify({ a: { b: undefined, c: null } }, { strictNullHandling: true })).toBe('a%5Bc%5D');\n    expect(stringify({ a: { b: undefined, c: null } }, { strictNullHandling: false })).toBe('a%5Bc%5D=');\n    expect(stringify({ a: { b: undefined, c: '' } })).toBe('a%5Bc%5D=');\n  });\n\n  test('url encodes values', function () {\n    // st.equal(stringify({ a: 'b c' }), 'a=b%20c');\n    expect(stringify({ a: 'b c' })).toBe('a=b%20c');\n  });\n\n  test('stringifies a date', function () {\n    var now = new Date();\n    var str = 'a=' + encodeURIComponent(now.toISOString());\n    // st.equal(stringify({ a: now }), str);\n    expect(stringify({ a: now })).toBe(str);\n  });\n\n  test('stringifies the weird object from qs', function () {\n    // st.equal(\n    // \tstringify({ 'my weird field': '~q1!2\"\\'w$5&7/z8)?' }),\n    // \t'my%20weird%20field=~q1%212%22%27w%245%267%2Fz8%29%3F',\n    // );\n    expect(stringify({ 'my weird field': '~q1!2\"\\'w$5&7/z8)?' })).toBe(\n      'my%20weird%20field=~q1%212%22%27w%245%267%2Fz8%29%3F',\n    );\n  });\n\n  // TODO: Investigate how to to intercept in vitest\n  // TODO(rob)\n  test('skips properties that are part of the object prototype', function () {\n    // st.intercept(Object.prototype, 'crash', { value: 'test' });\n    // @ts-expect-error\n    Object.prototype.crash = 'test';\n\n    // st.equal(stringify({ a: 'b' }), 'a=b');\n    // st.equal(stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');\n    expect(stringify({ a: 'b' })).toBe('a=b');\n    expect(stringify({ a: { b: 'c' } })).toBe('a%5Bb%5D=c');\n  });\n\n  test('stringifies boolean values', function () {\n    // st.equal(stringify({ a: true }), 'a=true');\n    // st.equal(stringify({ a: { b: true } }), 'a%5Bb%5D=true');\n    // st.equal(stringify({ b: false }), 'b=false');\n    // st.equal(stringify({ b: { c: false } }), 'b%5Bc%5D=false');\n    expect(stringify({ a: true })).toBe('a=true');\n    expect(stringify({ a: { b: true } })).toBe('a%5Bb%5D=true');\n    expect(stringify({ b: false })).toBe('b=false');\n    expect(stringify({ b: { c: false } })).toBe('b%5Bc%5D=false');\n  });\n\n  test('stringifies buffer values', function () {\n    // st.equal(stringify({ a: Buffer.from('test') }), 'a=test');\n    // st.equal(stringify({ a: { b: Buffer.from('test') } }), 'a%5Bb%5D=test');\n  });\n\n  test('stringifies an object using an alternative delimiter', function () {\n    // st.equal(stringify({ a: 'b', c: 'd' }, { delimiter: ';' }), 'a=b;c=d');\n    expect(stringify({ a: 'b', c: 'd' }, { delimiter: ';' })).toBe('a=b;c=d');\n  });\n\n  // We dont target environments which dont even have Buffer\n  // test('does not blow up when Buffer global is missing', function () {\n  // \tvar restore = mockProperty(global, 'Buffer', { delete: true });\n\n  // \tvar result = stringify({ a: 'b', c: 'd' });\n\n  // \trestore();\n\n  // \tst.equal(result, 'a=b&c=d');\n  // \tst.end();\n  // });\n\n  test('does not crash when parsing circular references', function () {\n    var a: any = {};\n    a.b = a;\n\n    // st['throws'](\n    // \tfunction () {\n    // \t\tstringify({ 'foo[bar]': 'baz', 'foo[baz]': a });\n    // \t},\n    // \t/RangeError: Cyclic object value/,\n    // \t'cyclic values throw',\n    // );\n    expect(() => {\n      stringify({ 'foo[bar]': 'baz', 'foo[baz]': a });\n    }).toThrow('Cyclic object value');\n\n    var circular: any = {\n      a: 'value',\n    };\n    circular.a = circular;\n    // st['throws'](\n    // \tfunction () {\n    // \t\tstringify(circular);\n    // \t},\n    // \t/RangeError: Cyclic object value/,\n    // \t'cyclic values throw',\n    // );\n    expect(() => {\n      stringify(circular);\n    }).toThrow('Cyclic object value');\n\n    var arr = ['a'];\n    // st.doesNotThrow(function () {\n    // \tstringify({ x: arr, y: arr });\n    // }, 'non-cyclic values do not throw');\n    expect(() => {\n      stringify({ x: arr, y: arr });\n    }).not.toThrow();\n  });\n\n  test('non-circular duplicated references can still work', function () {\n    var hourOfDay = {\n      function: 'hour_of_day',\n    };\n\n    var p1 = {\n      function: 'gte',\n      arguments: [hourOfDay, 0],\n    };\n    var p2 = {\n      function: 'lte',\n      arguments: [hourOfDay, 23],\n    };\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ filters: { $and: [p1, p2] } },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'indices' },\n    // \t),\n    // \t'filters[$and][0][function]=gte&filters[$and][0][arguments][0][function]=hour_of_day&filters[$and][0][arguments][1]=0&filters[$and][1][function]=lte&filters[$and][1][arguments][0][function]=hour_of_day&filters[$and][1][arguments][1]=23',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ filters: { $and: [p1, p2] } },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'brackets' },\n    // \t),\n    // \t'filters[$and][][function]=gte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=0&filters[$and][][function]=lte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=23',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ filters: { $and: [p1, p2] } },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'repeat' },\n    // \t),\n    // \t'filters[$and][function]=gte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=0&filters[$and][function]=lte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=23',\n    // );\n    expect(\n      stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'indices' }),\n    ).toBe(\n      'filters[$and][0][function]=gte&filters[$and][0][arguments][0][function]=hour_of_day&filters[$and][0][arguments][1]=0&filters[$and][1][function]=lte&filters[$and][1][arguments][0][function]=hour_of_day&filters[$and][1][arguments][1]=23',\n    );\n    expect(\n      stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),\n    ).toBe(\n      'filters[$and][][function]=gte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=0&filters[$and][][function]=lte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=23',\n    );\n    expect(\n      stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),\n    ).toBe(\n      'filters[$and][function]=gte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=0&filters[$and][function]=lte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=23',\n    );\n  });\n\n  test('selects properties when filter=array', function () {\n    // st.equal(stringify({ a: 'b' }, { filter: ['a'] }), 'a=b');\n    // st.equal(stringify({ a: 1 }, { filter: [] }), '');\n    expect(stringify({ a: 'b' }, { filter: ['a'] })).toBe('a=b');\n    expect(stringify({ a: 1 }, { filter: [] })).toBe('');\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },\n    // \t\t{ filter: ['a', 'b', 0, 2], arrayFormat: 'indices' },\n    // \t),\n    // \t'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3',\n    // \t'indices => indices',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },\n    // \t\t{ filter: ['a', 'b', 0, 2], arrayFormat: 'brackets' },\n    // \t),\n    // \t'a%5Bb%5D%5B%5D=1&a%5Bb%5D%5B%5D=3',\n    // \t'brackets => brackets',\n    // );\n    // st.equal(\n    // \tstringify({ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' }, { filter: ['a', 'b', 0, 2] }),\n    // \t'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3',\n    // \t'default => indices',\n    // );\n    expect(stringify({ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' }, { filter: ['a', 'b', 0, 2] })).toBe(\n      'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3',\n    );\n    expect(\n      stringify(\n        { a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },\n        { filter: ['a', 'b', 0, 2], arrayFormat: 'indices' },\n      ),\n    ).toBe('a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3');\n    expect(\n      stringify(\n        { a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },\n        { filter: ['a', 'b', 0, 2], arrayFormat: 'brackets' },\n      ),\n    ).toBe('a%5Bb%5D%5B%5D=1&a%5Bb%5D%5B%5D=3');\n  });\n\n  test('supports custom representations when filter=function', function () {\n    var calls = 0;\n    var obj = { a: 'b', c: 'd', e: { f: new Date(1257894000000) } };\n    var filterFunc: StringifyOptions['filter'] = function (prefix, value) {\n      calls += 1;\n      if (calls === 1) {\n        // st.equal(prefix, '', 'prefix is empty');\n        // st.equal(value, obj);\n        expect(prefix).toBe('');\n        expect(value).toBe(obj);\n      } else if (prefix === 'c') {\n        return void 0;\n      } else if (value instanceof Date) {\n        // st.equal(prefix, 'e[f]');\n        expect(prefix).toBe('e[f]');\n        return value.getTime();\n      }\n      return value;\n    };\n\n    // st.equal(stringify(obj, { filter: filterFunc }), 'a=b&e%5Bf%5D=1257894000000');\n    // st.equal(calls, 5);\n    expect(stringify(obj, { filter: filterFunc })).toBe('a=b&e%5Bf%5D=1257894000000');\n    expect(calls).toBe(5);\n  });\n\n  test('can disable uri encoding', function () {\n    // st.equal(stringify({ a: 'b' }, { encode: false }), 'a=b');\n    // st.equal(stringify({ a: { b: 'c' } }, { encode: false }), 'a[b]=c');\n    // st.equal(\n    // \tstringify({ a: 'b', c: null }, { strictNullHandling: true, encode: false }),\n    // \t'a=b&c',\n    // );\n    expect(stringify({ a: 'b' }, { encode: false })).toBe('a=b');\n    expect(stringify({ a: { b: 'c' } }, { encode: false })).toBe('a[b]=c');\n    expect(stringify({ a: 'b', c: null }, { strictNullHandling: true, encode: false })).toBe('a=b&c');\n  });\n\n  test('can sort the keys', function () {\n    // @ts-expect-error\n    var sort: NonNullable<StringifyOptions['sort']> = function (a: string, b: string) {\n      return a.localeCompare(b);\n    };\n    // st.equal(stringify({ a: 'c', z: 'y', b: 'f' }, { sort: sort }), 'a=c&b=f&z=y');\n    // st.equal(\n    // \tstringify({ a: 'c', z: { j: 'a', i: 'b' }, b: 'f' }, { sort: sort }),\n    // \t'a=c&b=f&z%5Bi%5D=b&z%5Bj%5D=a',\n    // );\n    expect(stringify({ a: 'c', z: 'y', b: 'f' }, { sort: sort })).toBe('a=c&b=f&z=y');\n    expect(stringify({ a: 'c', z: { j: 'a', i: 'b' }, b: 'f' }, { sort: sort })).toBe(\n      'a=c&b=f&z%5Bi%5D=b&z%5Bj%5D=a',\n    );\n  });\n\n  test('can sort the keys at depth 3 or more too', function () {\n    // @ts-expect-error\n    var sort: NonNullable<StringifyOptions['sort']> = function (a: string, b: string) {\n      return a.localeCompare(b);\n    };\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },\n    // \t\t{ sort: sort, encode: false },\n    // \t),\n    // \t'a=a&b=b&z[zi][zia]=zia&z[zi][zib]=zib&z[zj][zja]=zja&z[zj][zjb]=zjb',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },\n    // \t\t{ sort: null, encode: false },\n    // \t),\n    // \t'a=a&z[zj][zjb]=zjb&z[zj][zja]=zja&z[zi][zib]=zib&z[zi][zia]=zia&b=b',\n    // );\n    expect(\n      stringify(\n        { a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },\n        { sort: sort, encode: false },\n      ),\n    ).toBe('a=a&b=b&z[zi][zia]=zia&z[zi][zib]=zib&z[zj][zja]=zja&z[zj][zjb]=zjb');\n    expect(\n      stringify(\n        { a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },\n        { sort: null, encode: false },\n      ),\n    ).toBe('a=a&z[zj][zjb]=zjb&z[zj][zja]=zja&z[zi][zib]=zib&z[zi][zia]=zia&b=b');\n  });\n\n  test('can stringify with custom encoding', function () {\n    // st.equal(\n    // \tstringify(\n    // \t\t{ 県: '大阪府', '': '' },\n    // \t\t{\n    // \t\t\tencoder: function (str) {\n    // \t\t\t\tif (str.length === 0) {\n    // \t\t\t\t\treturn '';\n    // \t\t\t\t}\n    // \t\t\t\tvar buf = iconv.encode(str, 'shiftjis');\n    // \t\t\t\tvar result = [];\n    // \t\t\t\tfor (var i = 0; i < buf.length; ++i) {\n    // \t\t\t\t\tresult.push(buf.readUInt8(i).toString(16));\n    // \t\t\t\t}\n    // \t\t\t\treturn '%' + result.join('%');\n    // \t\t\t},\n    // \t\t},\n    // \t),\n    // \t'%8c%a7=%91%e5%8d%e3%95%7b&=',\n    // );\n    expect(\n      stringify(\n        { 県: '大阪府', '': '' },\n        {\n          encoder: function (str) {\n            if (str.length === 0) {\n              return '';\n            }\n            var buf = iconv.encode(str, 'shiftjis');\n            var result = [];\n            for (var i = 0; i < buf.length; ++i) {\n              result.push(buf.readUInt8(i).toString(16));\n            }\n            return '%' + result.join('%');\n          },\n        },\n      ),\n    ).toBe('%8c%a7=%91%e5%8d%e3%95%7b&=');\n  });\n\n  test('receives the default encoder as a second argument', function () {\n    // stringify(\n    // \t{ a: 1, b: new Date(), c: true, d: [1] },\n    // \t{\n    // \t\tencoder: function (str) {\n    // \t\t\tst.match(typeof str, /^(?:string|number|boolean)$/);\n    // \t\t\treturn '';\n    // \t\t},\n    // \t},\n    // );\n\n    stringify(\n      { a: 1, b: new Date(), c: true, d: [1] },\n      {\n        encoder: function (str) {\n          // st.match(typeof str, /^(?:string|number|boolean)$/);\n          assert.match(typeof str, /^(?:string|number|boolean)$/);\n          return '';\n        },\n      },\n    );\n  });\n\n  test('receives the default encoder as a second argument', function () {\n    // stringify(\n    // \t{ a: 1 },\n    // \t{\n    // \t\tencoder: function (str, defaultEncoder) {\n    // \t\t\tst.equal(defaultEncoder, utils.encode);\n    // \t\t},\n    // \t},\n    // );\n\n    stringify(\n      { a: 1 },\n      {\n        // @ts-ignore\n        encoder: function (_str, defaultEncoder) {\n          expect(defaultEncoder).toBe(encode);\n        },\n      },\n    );\n  });\n\n  test('throws error with wrong encoder', function () {\n    // st['throws'](function () {\n    // \tstringify({}, { encoder: 'string' });\n    // }, new TypeError('Encoder has to be a function.'));\n    // st.end();\n    expect(() => {\n      // @ts-expect-error\n      stringify({}, { encoder: 'string' });\n    }).toThrow(TypeError);\n  });\n\n  (typeof Buffer === 'undefined' ? test.skip : test)(\n    'can use custom encoder for a buffer object',\n    function () {\n      // st.equal(\n      // \tstringify(\n      // \t\t{ a: Buffer.from([1]) },\n      // \t\t{\n      // \t\t\tencoder: function (buffer) {\n      // \t\t\t\tif (typeof buffer === 'string') {\n      // \t\t\t\t\treturn buffer;\n      // \t\t\t\t}\n      // \t\t\t\treturn String.fromCharCode(buffer.readUInt8(0) + 97);\n      // \t\t\t},\n      // \t\t},\n      // \t),\n      // \t'a=b',\n      // );\n      expect(\n        stringify(\n          { a: Buffer.from([1]) },\n          {\n            encoder: function (buffer) {\n              if (typeof buffer === 'string') {\n                return buffer;\n              }\n              return String.fromCharCode(buffer.readUInt8(0) + 97);\n            },\n          },\n        ),\n      ).toBe('a=b');\n\n      // st.equal(\n      // \tstringify(\n      // \t\t{ a: Buffer.from('a b') },\n      // \t\t{\n      // \t\t\tencoder: function (buffer) {\n      // \t\t\t\treturn buffer;\n      // \t\t\t},\n      // \t\t},\n      // \t),\n      // \t'a=a b',\n      // );\n      expect(\n        stringify(\n          { a: Buffer.from('a b') },\n          {\n            encoder: function (buffer) {\n              return buffer;\n            },\n          },\n        ),\n      ).toBe('a=a b');\n    },\n  );\n\n  test('serializeDate option', function () {\n    var date = new Date();\n    // st.equal(\n    // \tstringify({ a: date }),\n    // \t'a=' + date.toISOString().replace(/:/g, '%3A'),\n    // \t'default is toISOString',\n    // );\n    expect(stringify({ a: date })).toBe('a=' + date.toISOString().replace(/:/g, '%3A'));\n\n    var mutatedDate = new Date();\n    mutatedDate.toISOString = function () {\n      throw new SyntaxError();\n    };\n    // st['throws'](function () {\n    // \tmutatedDate.toISOString();\n    // }, SyntaxError);\n    expect(() => {\n      mutatedDate.toISOString();\n    }).toThrow(SyntaxError);\n    // st.equal(\n    // \tstringify({ a: mutatedDate }),\n    // \t'a=' + Date.prototype.toISOString.call(mutatedDate).replace(/:/g, '%3A'),\n    // \t'toISOString works even when method is not locally present',\n    // );\n    expect(stringify({ a: mutatedDate })).toBe(\n      'a=' + Date.prototype.toISOString.call(mutatedDate).replace(/:/g, '%3A'),\n    );\n\n    var specificDate = new Date(6);\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: specificDate },\n    // \t\t{\n    // \t\t\tserializeDate: function (d) {\n    // \t\t\t\treturn d.getTime() * 7;\n    // \t\t\t},\n    // \t\t},\n    // \t),\n    // \t'a=42',\n    // \t'custom serializeDate function called',\n    // );\n    expect(\n      stringify(\n        { a: specificDate },\n        {\n          // @ts-ignore\n          serializeDate: function (d) {\n            return d.getTime() * 7;\n          },\n        },\n      ),\n    ).toBe('a=42');\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [date] },\n    // \t\t{\n    // \t\t\tserializeDate: function (d) {\n    // \t\t\t\treturn d.getTime();\n    // \t\t\t},\n    // \t\t\tarrayFormat: 'comma',\n    // \t\t},\n    // \t),\n    // \t'a=' + date.getTime(),\n    // \t'works with arrayFormat comma',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [date] },\n    // \t\t{\n    // \t\t\tserializeDate: function (d) {\n    // \t\t\t\treturn d.getTime();\n    // \t\t\t},\n    // \t\t\tarrayFormat: 'comma',\n    // \t\t\tcommaRoundTrip: true,\n    // \t\t},\n    // \t),\n    // \t'a%5B%5D=' + date.getTime(),\n    // \t'works with arrayFormat comma',\n    // );\n    expect(\n      stringify(\n        { a: [date] },\n        {\n          // @ts-expect-error\n          serializeDate: function (d) {\n            return d.getTime();\n          },\n          arrayFormat: 'comma',\n        },\n      ),\n    ).toBe('a=' + date.getTime());\n    expect(\n      stringify(\n        { a: [date] },\n        {\n          // @ts-expect-error\n          serializeDate: function (d) {\n            return d.getTime();\n          },\n          arrayFormat: 'comma',\n          commaRoundTrip: true,\n        },\n      ),\n    ).toBe('a%5B%5D=' + date.getTime());\n  });\n\n  test('RFC 1738 serialization', function () {\n    // st.equal(stringify({ a: 'b c' }, { format: formats.RFC1738 }), 'a=b+c');\n    // st.equal(stringify({ 'a b': 'c d' }, { format: formats.RFC1738 }), 'a+b=c+d');\n    // st.equal(\n    // \tstringify({ 'a b': Buffer.from('a b') }, { format: formats.RFC1738 }),\n    // \t'a+b=a+b',\n    // );\n    expect(stringify({ a: 'b c' }, { format: 'RFC1738' })).toBe('a=b+c');\n    expect(stringify({ 'a b': 'c d' }, { format: 'RFC1738' })).toBe('a+b=c+d');\n    expect(stringify({ 'a b': Buffer.from('a b') }, { format: 'RFC1738' })).toBe('a+b=a+b');\n\n    // st.equal(stringify({ 'foo(ref)': 'bar' }, { format: formats.RFC1738 }), 'foo(ref)=bar');\n    expect(stringify({ 'foo(ref)': 'bar' }, { format: 'RFC1738' })).toBe('foo(ref)=bar');\n  });\n\n  test('RFC 3986 spaces serialization', function () {\n    // st.equal(stringify({ a: 'b c' }, { format: formats.RFC3986 }), 'a=b%20c');\n    // st.equal(stringify({ 'a b': 'c d' }, { format: formats.RFC3986 }), 'a%20b=c%20d');\n    // st.equal(\n    // \tstringify({ 'a b': Buffer.from('a b') }, { format: formats.RFC3986 }),\n    // \t'a%20b=a%20b',\n    // );\n    expect(stringify({ a: 'b c' }, { format: 'RFC3986' })).toBe('a=b%20c');\n    expect(stringify({ 'a b': 'c d' }, { format: 'RFC3986' })).toBe('a%20b=c%20d');\n    expect(stringify({ 'a b': Buffer.from('a b') }, { format: 'RFC3986' })).toBe('a%20b=a%20b');\n  });\n\n  test('Backward compatibility to RFC 3986', function () {\n    // st.equal(stringify({ a: 'b c' }), 'a=b%20c');\n    // st.equal(stringify({ 'a b': Buffer.from('a b') }), 'a%20b=a%20b');\n    expect(stringify({ a: 'b c' })).toBe('a=b%20c');\n    expect(stringify({ 'a b': Buffer.from('a b') })).toBe('a%20b=a%20b');\n  });\n\n  test('Edge cases and unknown formats', function () {\n    ['UFO1234', false, 1234, null, {}, []].forEach(function (format) {\n      // st['throws'](function () {\n      // \tstringify({ a: 'b c' }, { format: format });\n      // }, new TypeError('Unknown format option provided.'));\n      expect(() => {\n        // @ts-expect-error\n        stringify({ a: 'b c' }, { format: format });\n      }).toThrow(TypeError);\n    });\n  });\n\n  test('encodeValuesOnly', function () {\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'indices' },\n    // \t),\n    // \t'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h',\n    // \t'encodeValuesOnly + indices',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a=b&c[]=d&c[]=e%3Df&f[][]=g&f[][]=h',\n    // \t'encodeValuesOnly + brackets',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'repeat' },\n    // \t),\n    // \t'a=b&c=d&c=e%3Df&f=g&f=h',\n    // \t'encodeValuesOnly + repeat',\n    // );\n    expect(\n      stringify(\n        { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },\n        { encodeValuesOnly: true, arrayFormat: 'indices' },\n      ),\n    ).toBe('a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h');\n    expect(\n      stringify(\n        { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },\n        { encodeValuesOnly: true, arrayFormat: 'brackets' },\n      ),\n    ).toBe('a=b&c[]=d&c[]=e%3Df&f[][]=g&f[][]=h');\n    expect(\n      stringify(\n        { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },\n        { encodeValuesOnly: true, arrayFormat: 'repeat' },\n      ),\n    ).toBe('a=b&c=d&c=e%3Df&f=g&f=h');\n\n    // st.equal(\n    // \tstringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'indices' }),\n    // \t'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h',\n    // \t'no encodeValuesOnly + indices',\n    // );\n    // st.equal(\n    // \tstringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'brackets' }),\n    // \t'a=b&c%5B%5D=d&c%5B%5D=e&f%5B%5D%5B%5D=g&f%5B%5D%5B%5D=h',\n    // \t'no encodeValuesOnly + brackets',\n    // );\n    // st.equal(\n    // \tstringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'repeat' }),\n    // \t'a=b&c=d&c=e&f=g&f=h',\n    // \t'no encodeValuesOnly + repeat',\n    // );\n    expect(stringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'indices' })).toBe(\n      'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h',\n    );\n    expect(stringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'brackets' })).toBe(\n      'a=b&c%5B%5D=d&c%5B%5D=e&f%5B%5D%5B%5D=g&f%5B%5D%5B%5D=h',\n    );\n    expect(stringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'repeat' })).toBe(\n      'a=b&c=d&c=e&f=g&f=h',\n    );\n  });\n\n  test('encodeValuesOnly - strictNullHandling', function () {\n    // st.equal(\n    // \tstringify({ a: { b: null } }, { encodeValuesOnly: true, strictNullHandling: true }),\n    // \t'a[b]',\n    // );\n    expect(stringify({ a: { b: null } }, { encodeValuesOnly: true, strictNullHandling: true })).toBe('a[b]');\n  });\n\n  test('throws if an invalid charset is specified', function () {\n    // st['throws'](function () {\n    // \tstringify({ a: 'b' }, { charset: 'foobar' });\n    // }, new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined'));\n    expect(() => {\n      // @ts-expect-error\n      stringify({ a: 'b' }, { charset: 'foobar' });\n    }).toThrow(TypeError);\n  });\n\n  test('respects a charset of iso-8859-1', function () {\n    // st.equal(stringify({ æ: 'æ' }, { charset: 'iso-8859-1' }), '%E6=%E6');\n    expect(stringify({ æ: 'æ' }, { charset: 'iso-8859-1' })).toBe('%E6=%E6');\n  });\n\n  test('encodes unrepresentable chars as numeric entities in iso-8859-1 mode', function () {\n    // st.equal(stringify({ a: '☺' }, { charset: 'iso-8859-1' }), 'a=%26%239786%3B');\n    expect(stringify({ a: '☺' }, { charset: 'iso-8859-1' })).toBe('a=%26%239786%3B');\n  });\n\n  test('respects an explicit charset of utf-8 (the default)', function () {\n    // st.equal(stringify({ a: 'æ' }, { charset: 'utf-8' }), 'a=%C3%A6');\n    expect(stringify({ a: 'æ' }, { charset: 'utf-8' })).toBe('a=%C3%A6');\n  });\n\n  test('`charsetSentinel` option', function () {\n    // st.equal(\n    // \tstringify({ a: 'æ' }, { charsetSentinel: true, charset: 'utf-8' }),\n    // \t'utf8=%E2%9C%93&a=%C3%A6',\n    // \t'adds the right sentinel when instructed to and the charset is utf-8',\n    // );\n    expect(stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'utf-8' })).toBe(\n      'utf8=%E2%9C%93&a=%C3%A6',\n    );\n\n    // st.equal(\n    // \tstringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' }),\n    // \t'utf8=%26%2310003%3B&a=%E6',\n    // \t'adds the right sentinel when instructed to and the charset is iso-8859-1',\n    // );\n    expect(stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' })).toBe(\n      'utf8=%26%2310003%3B&a=%E6',\n    );\n  });\n\n  test('does not mutate the options argument', function () {\n    var options = {};\n    stringify({}, options);\n    // st.deepEqual(options, {});\n    expect(options).toEqual({});\n  });\n\n  test('strictNullHandling works with custom filter', function () {\n    // @ts-expect-error\n    var filter = function (_prefix, value) {\n      return value;\n    };\n\n    var options = { strictNullHandling: true, filter: filter };\n    // st.equal(stringify({ key: null }, options), 'key');\n    expect(stringify({ key: null }, options)).toBe('key');\n  });\n\n  test('strictNullHandling works with null serializeDate', function () {\n    var serializeDate = function () {\n      return null;\n    };\n    var options = { strictNullHandling: true, serializeDate: serializeDate };\n    var date = new Date();\n    // st.equal(stringify({ key: date }, options), 'key');\n    // @ts-expect-error\n    expect(stringify({ key: date }, options)).toBe('key');\n  });\n\n  test('allows for encoding keys and values differently', function () {\n    // @ts-expect-error\n    var encoder = function (str, defaultEncoder, charset, type) {\n      if (type === 'key') {\n        return defaultEncoder(str, defaultEncoder, charset, type).toLowerCase();\n      }\n      if (type === 'value') {\n        return defaultEncoder(str, defaultEncoder, charset, type).toUpperCase();\n      }\n      throw 'this should never happen! type: ' + type;\n    };\n\n    // st.deepEqual(stringify({ KeY: 'vAlUe' }, { encoder: encoder }), 'key=VALUE');\n    expect(stringify({ KeY: 'vAlUe' }, { encoder: encoder })).toBe('key=VALUE');\n  });\n\n  test('objects inside arrays', function () {\n    var obj = { a: { b: { c: 'd', e: 'f' } } };\n    var withArray = { a: { b: [{ c: 'd', e: 'f' }] } };\n\n    // st.equal(\n    // \tstringify(obj, { encode: false }),\n    // \t'a[b][c]=d&a[b][e]=f',\n    // \t'no array, no arrayFormat',\n    // );\n    // st.equal(\n    // \tstringify(obj, { encode: false, arrayFormat: 'brackets' }),\n    // \t'a[b][c]=d&a[b][e]=f',\n    // \t'no array, bracket',\n    // );\n    // st.equal(\n    // \tstringify(obj, { encode: false, arrayFormat: 'indices' }),\n    // \t'a[b][c]=d&a[b][e]=f',\n    // \t'no array, indices',\n    // );\n    // st.equal(\n    // \tstringify(obj, { encode: false, arrayFormat: 'repeat' }),\n    // \t'a[b][c]=d&a[b][e]=f',\n    // \t'no array, repeat',\n    // );\n    // st.equal(\n    // \tstringify(obj, { encode: false, arrayFormat: 'comma' }),\n    // \t'a[b][c]=d&a[b][e]=f',\n    // \t'no array, comma',\n    // );\n    expect(stringify(obj, { encode: false })).toBe('a[b][c]=d&a[b][e]=f');\n    expect(stringify(obj, { encode: false, arrayFormat: 'brackets' })).toBe('a[b][c]=d&a[b][e]=f');\n    expect(stringify(obj, { encode: false, arrayFormat: 'indices' })).toBe('a[b][c]=d&a[b][e]=f');\n    expect(stringify(obj, { encode: false, arrayFormat: 'repeat' })).toBe('a[b][c]=d&a[b][e]=f');\n    expect(stringify(obj, { encode: false, arrayFormat: 'comma' })).toBe('a[b][c]=d&a[b][e]=f');\n\n    // st.equal(\n    // \tstringify(withArray, { encode: false }),\n    // \t'a[b][0][c]=d&a[b][0][e]=f',\n    // \t'array, no arrayFormat',\n    // );\n    // st.equal(\n    // \tstringify(withArray, { encode: false, arrayFormat: 'brackets' }),\n    // \t'a[b][][c]=d&a[b][][e]=f',\n    // \t'array, bracket',\n    // );\n    // st.equal(\n    // \tstringify(withArray, { encode: false, arrayFormat: 'indices' }),\n    // \t'a[b][0][c]=d&a[b][0][e]=f',\n    // \t'array, indices',\n    // );\n    // st.equal(\n    // \tstringify(withArray, { encode: false, arrayFormat: 'repeat' }),\n    // \t'a[b][c]=d&a[b][e]=f',\n    // \t'array, repeat',\n    // );\n    // st.equal(\n    // \tstringify(withArray, { encode: false, arrayFormat: 'comma' }),\n    // \t'???',\n    // \t'array, comma',\n    // \t{ skip: 'TODO: figure out what this should do' },\n    // );\n    expect(stringify(withArray, { encode: false })).toBe('a[b][0][c]=d&a[b][0][e]=f');\n    expect(stringify(withArray, { encode: false, arrayFormat: 'brackets' })).toBe('a[b][][c]=d&a[b][][e]=f');\n    expect(stringify(withArray, { encode: false, arrayFormat: 'indices' })).toBe('a[b][0][c]=d&a[b][0][e]=f');\n    expect(stringify(withArray, { encode: false, arrayFormat: 'repeat' })).toBe('a[b][c]=d&a[b][e]=f');\n    // !TODo: Figure out what this should do\n    // expect(stringify(withArray, { encode: false, arrayFormat: 'comma' })).toBe(\n    // \t'a[b][c]=d&a[b][e]=f',\n    // );\n  });\n\n  test('stringifies sparse arrays', function () {\n    // st.equal(\n    // \tstringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),\n    // \t'a[1]=2&a[4]=1',\n    // );\n    // st.equal(\n    // \tstringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),\n    // \t'a[]=2&a[]=1',\n    // );\n    // st.equal(\n    // \tstringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),\n    // \t'a=2&a=1',\n    // );\n    expect(stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe(\n      'a[1]=2&a[4]=1',\n    );\n    expect(stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe(\n      'a[]=2&a[]=1',\n    );\n    expect(stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'repeat' })).toBe(\n      'a=2&a=1',\n    );\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [, { b: [, , { c: '1' }] }] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'indices' },\n    // \t),\n    // \t'a[1][b][2][c]=1',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [, { b: [, , { c: '1' }] }] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a[][b][][c]=1',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [, { b: [, , { c: '1' }] }] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'repeat' },\n    // \t),\n    // \t'a[b][c]=1',\n    // );\n    expect(\n      stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),\n    ).toBe('a[1][b][2][c]=1');\n    expect(\n      stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),\n    ).toBe('a[][b][][c]=1');\n    expect(\n      stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),\n    ).toBe('a[b][c]=1');\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [, [, , [, , , { c: '1' }]]] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'indices' },\n    // \t),\n    // \t'a[1][2][3][c]=1',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [, [, , [, , , { c: '1' }]]] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a[][][][c]=1',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [, [, , [, , , { c: '1' }]]] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'repeat' },\n    // \t),\n    // \t'a[c]=1',\n    // );\n    expect(\n      stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),\n    ).toBe('a[1][2][3][c]=1');\n    expect(\n      stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),\n    ).toBe('a[][][][c]=1');\n    expect(\n      stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),\n    ).toBe('a[c]=1');\n\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [, [, , [, , , { c: [, '1'] }]]] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'indices' },\n    // \t),\n    // \t'a[1][2][3][c][1]=1',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [, [, , [, , , { c: [, '1'] }]]] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'brackets' },\n    // \t),\n    // \t'a[][][][c][]=1',\n    // );\n    // st.equal(\n    // \tstringify(\n    // \t\t{ a: [, [, , [, , , { c: [, '1'] }]]] },\n    // \t\t{ encodeValuesOnly: true, arrayFormat: 'repeat' },\n    // \t),\n    // \t'a[c]=1',\n    // );\n    expect(\n      stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),\n    ).toBe('a[1][2][3][c][1]=1');\n    expect(\n      stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),\n    ).toBe('a[][][][c][]=1');\n    expect(\n      stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),\n    ).toBe('a[c]=1');\n  });\n\n  test('encodes a very long string', function () {\n    var chars = [];\n    var expected = [];\n    for (var i = 0; i < 5e3; i++) {\n      chars.push(' ' + i);\n\n      expected.push('%20' + i);\n    }\n\n    var obj = {\n      foo: chars.join(''),\n    };\n\n    // st.equal(\n    // \tstringify(obj, { arrayFormat: 'bracket', charset: 'utf-8' }),\n    // \t'foo=' + expected.join(''),\n    // );\n    // @ts-expect-error\n    expect(stringify(obj, { arrayFormat: 'bracket', charset: 'utf-8' })).toBe('foo=' + expected.join(''));\n  });\n});\n\ndescribe('stringifies empty keys', function () {\n  empty_test_cases.forEach(function (testCase) {\n    test('stringifies an object with empty string key with ' + testCase.input, function () {\n      // st.deepEqual(\n      // \tstringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'indices' }),\n      // \ttestCase.stringifyOutput.indices,\n      // \t'test case: ' + testCase.input + ', indices',\n      // );\n      // st.deepEqual(\n      // \tstringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'brackets' }),\n      // \ttestCase.stringifyOutput.brackets,\n      // \t'test case: ' + testCase.input + ', brackets',\n      // );\n      // st.deepEqual(\n      // \tstringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'repeat' }),\n      // \ttestCase.stringifyOutput.repeat,\n      // \t'test case: ' + testCase.input + ', repeat',\n      // );\n      expect(stringify(testCase.with_empty_keys, { encode: false, arrayFormat: 'indices' })).toBe(\n        testCase.stringify_output.indices,\n      );\n      expect(stringify(testCase.with_empty_keys, { encode: false, arrayFormat: 'brackets' })).toBe(\n        testCase.stringify_output.brackets,\n      );\n      expect(stringify(testCase.with_empty_keys, { encode: false, arrayFormat: 'repeat' })).toBe(\n        testCase.stringify_output.repeat,\n      );\n    });\n  });\n\n  test('edge case with object/arrays', function () {\n    // st.deepEqual(stringify({ '': { '': [2, 3] } }, { encode: false }), '[][0]=2&[][1]=3');\n    // st.deepEqual(\n    // \tstringify({ '': { '': [2, 3], a: 2 } }, { encode: false }),\n    // \t'[][0]=2&[][1]=3&[a]=2',\n    // );\n    // st.deepEqual(\n    // \tstringify({ '': { '': [2, 3] } }, { encode: false, arrayFormat: 'indices' }),\n    // \t'[][0]=2&[][1]=3',\n    // );\n    // st.deepEqual(\n    // \tstringify({ '': { '': [2, 3], a: 2 } }, { encode: false, arrayFormat: 'indices' }),\n    // \t'[][0]=2&[][1]=3&[a]=2',\n    // );\n    expect(stringify({ '': { '': [2, 3] } }, { encode: false })).toBe('[][0]=2&[][1]=3');\n    expect(stringify({ '': { '': [2, 3], a: 2 } }, { encode: false })).toBe('[][0]=2&[][1]=3&[a]=2');\n    expect(stringify({ '': { '': [2, 3] } }, { encode: false, arrayFormat: 'indices' })).toBe(\n      '[][0]=2&[][1]=3',\n    );\n    expect(stringify({ '': { '': [2, 3], a: 2 } }, { encode: false, arrayFormat: 'indices' })).toBe(\n      '[][0]=2&[][1]=3&[a]=2',\n    );\n  });\n});\n"
  },
  {
    "path": "tests/qs/utils.test.ts",
    "content": "import { combine, merge, is_buffer, assign_single_source } from 'openai/internal/qs/utils';\n\ndescribe('merge()', function () {\n  // t.deepEqual(merge(null, true), [null, true], 'merges true into null');\n  expect(merge(null, true)).toEqual([null, true]);\n\n  // t.deepEqual(merge(null, [42]), [null, 42], 'merges null into an array');\n  expect(merge(null, [42])).toEqual([null, 42]);\n\n  // t.deepEqual(\n  // \tmerge({ a: 'b' }, { a: 'c' }),\n  // \t{ a: ['b', 'c'] },\n  // \t'merges two objects with the same key',\n  // );\n  expect(merge({ a: 'b' }, { a: 'c' })).toEqual({ a: ['b', 'c'] });\n\n  var oneMerged = merge({ foo: 'bar' }, { foo: { first: '123' } });\n  // t.deepEqual(\n  // \toneMerged,\n  // \t{ foo: ['bar', { first: '123' }] },\n  // \t'merges a standalone and an object into an array',\n  // );\n  expect(oneMerged).toEqual({ foo: ['bar', { first: '123' }] });\n\n  var twoMerged = merge({ foo: ['bar', { first: '123' }] }, { foo: { second: '456' } });\n  // t.deepEqual(\n  // \ttwoMerged,\n  // \t{ foo: { 0: 'bar', 1: { first: '123' }, second: '456' } },\n  // \t'merges a standalone and two objects into an array',\n  // );\n  expect(twoMerged).toEqual({ foo: { 0: 'bar', 1: { first: '123' }, second: '456' } });\n\n  var sandwiched = merge({ foo: ['bar', { first: '123', second: '456' }] }, { foo: 'baz' });\n  // t.deepEqual(\n  // \tsandwiched,\n  // \t{ foo: ['bar', { first: '123', second: '456' }, 'baz'] },\n  // \t'merges an object sandwiched by two standalones into an array',\n  // );\n  expect(sandwiched).toEqual({ foo: ['bar', { first: '123', second: '456' }, 'baz'] });\n\n  var nestedArrays = merge({ foo: ['baz'] }, { foo: ['bar', 'xyzzy'] });\n  // t.deepEqual(nestedArrays, { foo: ['baz', 'bar', 'xyzzy'] });\n  expect(nestedArrays).toEqual({ foo: ['baz', 'bar', 'xyzzy'] });\n\n  var noOptionsNonObjectSource = merge({ foo: 'baz' }, 'bar');\n  // t.deepEqual(noOptionsNonObjectSource, { foo: 'baz', bar: true });\n  expect(noOptionsNonObjectSource).toEqual({ foo: 'baz', bar: true });\n\n  (typeof Object.defineProperty !== 'function' ? test.skip : test)(\n    'avoids invoking array setters unnecessarily',\n    function () {\n      var setCount = 0;\n      var getCount = 0;\n      var observed: any[] = [];\n      Object.defineProperty(observed, 0, {\n        get: function () {\n          getCount += 1;\n          return { bar: 'baz' };\n        },\n        set: function () {\n          setCount += 1;\n        },\n      });\n      merge(observed, [null]);\n      // st.equal(setCount, 0);\n      // st.equal(getCount, 1);\n      expect(setCount).toEqual(0);\n      expect(getCount).toEqual(1);\n      observed[0] = observed[0];\n      // st.equal(setCount, 1);\n      // st.equal(getCount, 2);\n      expect(setCount).toEqual(1);\n      expect(getCount).toEqual(2);\n    },\n  );\n});\n\ntest('assign()', function () {\n  var target = { a: 1, b: 2 };\n  var source = { b: 3, c: 4 };\n  var result = assign_single_source(target, source);\n\n  expect(result).toEqual(target);\n  expect(target).toEqual({ a: 1, b: 3, c: 4 });\n  expect(source).toEqual({ b: 3, c: 4 });\n});\n\ndescribe('combine()', function () {\n  test('both arrays', function () {\n    var a = [1];\n    var b = [2];\n    var combined = combine(a, b);\n\n    // st.deepEqual(a, [1], 'a is not mutated');\n    // st.deepEqual(b, [2], 'b is not mutated');\n    // st.notEqual(a, combined, 'a !== combined');\n    // st.notEqual(b, combined, 'b !== combined');\n    // st.deepEqual(combined, [1, 2], 'combined is a + b');\n    expect(a).toEqual([1]);\n    expect(b).toEqual([2]);\n    expect(combined).toEqual([1, 2]);\n    expect(a).not.toEqual(combined);\n    expect(b).not.toEqual(combined);\n  });\n\n  test('one array, one non-array', function () {\n    var aN = 1;\n    var a = [aN];\n    var bN = 2;\n    var b = [bN];\n\n    var combinedAnB = combine(aN, b);\n    // st.deepEqual(b, [bN], 'b is not mutated');\n    // st.notEqual(aN, combinedAnB, 'aN + b !== aN');\n    // st.notEqual(a, combinedAnB, 'aN + b !== a');\n    // st.notEqual(bN, combinedAnB, 'aN + b !== bN');\n    // st.notEqual(b, combinedAnB, 'aN + b !== b');\n    // st.deepEqual([1, 2], combinedAnB, 'first argument is array-wrapped when not an array');\n    expect(b).toEqual([bN]);\n    expect(combinedAnB).not.toEqual(aN);\n    expect(combinedAnB).not.toEqual(a);\n    expect(combinedAnB).not.toEqual(bN);\n    expect(combinedAnB).not.toEqual(b);\n    expect(combinedAnB).toEqual([1, 2]);\n\n    var combinedABn = combine(a, bN);\n    // st.deepEqual(a, [aN], 'a is not mutated');\n    // st.notEqual(aN, combinedABn, 'a + bN !== aN');\n    // st.notEqual(a, combinedABn, 'a + bN !== a');\n    // st.notEqual(bN, combinedABn, 'a + bN !== bN');\n    // st.notEqual(b, combinedABn, 'a + bN !== b');\n    // st.deepEqual([1, 2], combinedABn, 'second argument is array-wrapped when not an array');\n    expect(a).toEqual([aN]);\n    expect(combinedABn).not.toEqual(aN);\n    expect(combinedABn).not.toEqual(a);\n    expect(combinedABn).not.toEqual(bN);\n    expect(combinedABn).not.toEqual(b);\n    expect(combinedABn).toEqual([1, 2]);\n  });\n\n  test('neither is an array', function () {\n    var combined = combine(1, 2);\n    // st.notEqual(1, combined, '1 + 2 !== 1');\n    // st.notEqual(2, combined, '1 + 2 !== 2');\n    // st.deepEqual([1, 2], combined, 'both arguments are array-wrapped when not an array');\n    expect(combined).not.toEqual(1);\n    expect(combined).not.toEqual(2);\n    expect(combined).toEqual([1, 2]);\n  });\n});\n\ntest('is_buffer()', function () {\n  for (const x of [null, undefined, true, false, '', 'abc', 42, 0, NaN, {}, [], function () {}, /a/g]) {\n    // t.equal(is_buffer(x), false, inspect(x) + ' is not a buffer');\n    expect(is_buffer(x)).toEqual(false);\n  }\n\n  var fakeBuffer = { constructor: Buffer };\n  // t.equal(is_buffer(fakeBuffer), false, 'fake buffer is not a buffer');\n  expect(is_buffer(fakeBuffer)).toEqual(false);\n\n  var saferBuffer = Buffer.from('abc');\n  // t.equal(is_buffer(saferBuffer), true, 'SaferBuffer instance is a buffer');\n  expect(is_buffer(saferBuffer)).toEqual(true);\n\n  var buffer = Buffer.from('abc');\n  // t.equal(is_buffer(buffer), true, 'real Buffer instance is a buffer');\n  expect(is_buffer(buffer)).toEqual(true);\n});\n"
  },
  {
    "path": "tests/responses.test.ts",
    "content": "import { APIPromise } from 'openai/api-promise';\nimport OpenAI from 'openai/index';\nimport { compareType } from './utils/typing';\n\nconst client = new OpenAI({ apiKey: 'example-api-key' });\n\ndescribe('request id', () => {\n  test('types', () => {\n    compareType<Awaited<APIPromise<string>>, string>(true);\n    compareType<Awaited<APIPromise<number>>, number>(true);\n    compareType<Awaited<APIPromise<null>>, null>(true);\n    compareType<Awaited<APIPromise<void>>, void>(true);\n    compareType<Awaited<APIPromise<Response>>, Response>(true);\n    compareType<Awaited<APIPromise<Response>>, Response>(true);\n    compareType<Awaited<APIPromise<{ foo: string }>>, { foo: string } & { _request_id?: string | null }>(\n      true,\n    );\n    compareType<Awaited<APIPromise<Array<{ foo: string }>>>, Array<{ foo: string }>>(true);\n  });\n\n  test('withResponse', async () => {\n    const client = new OpenAI({\n      apiKey: 'dummy',\n      fetch: async () =>\n        new Response(JSON.stringify({ id: 'bar' }), {\n          headers: { 'x-request-id': 'req_id_xxx', 'content-type': 'application/json' },\n        }),\n    });\n\n    const {\n      data: completion,\n      response,\n      request_id,\n    } = await client.chat.completions.create({ messages: [], model: 'gpt-4' }).withResponse();\n\n    expect(request_id).toBe('req_id_xxx');\n    expect(response.headers.get('x-request-id')).toBe('req_id_xxx');\n    expect(completion.id).toBe('bar');\n    expect(JSON.stringify(completion)).toBe('{\"id\":\"bar\"}');\n  });\n\n  test('object response', async () => {\n    const client = new OpenAI({\n      apiKey: 'dummy',\n      fetch: async () =>\n        new Response(JSON.stringify({ id: 'bar' }), {\n          headers: { 'x-request-id': 'req_id_xxx', 'content-type': 'application/json' },\n        }),\n    });\n\n    const rsp = await client.chat.completions.create({ messages: [], model: 'gpt-4' });\n    expect(rsp.id).toBe('bar');\n    expect(rsp._request_id).toBe('req_id_xxx');\n    expect(JSON.stringify(rsp)).toBe('{\"id\":\"bar\"}');\n  });\n\n  test('envelope response', async () => {\n    const promise = new APIPromise<{ data: { foo: string } }>(\n      client,\n      (async () => {\n        return {\n          response: new Response(JSON.stringify({ data: { foo: 'bar' } }), {\n            headers: { 'x-request-id': 'req_id_xxx', 'content-type': 'application/json' },\n          }),\n          controller: {} as any,\n          options: {} as any,\n          requestLogID: 'log_...',\n          retryOfRequestLogID: undefined,\n          startTime: Date.now(),\n        };\n      })(),\n    )._thenUnwrap((d) => d.data);\n\n    const rsp = await promise;\n    expect(rsp.foo).toBe('bar');\n    expect(rsp._request_id).toBe('req_id_xxx');\n  });\n\n  test('page response', async () => {\n    const client = new OpenAI({\n      apiKey: 'dummy',\n      fetch: async () =>\n        new Response(JSON.stringify({ data: [{ foo: 'bar' }] }), {\n          headers: { 'x-request-id': 'req_id_xxx', 'content-type': 'application/json' },\n        }),\n    });\n\n    const page = await client.fineTuning.jobs.list();\n    expect(page.data).toMatchObject([{ foo: 'bar' }]);\n    expect((page as any)._request_id).toBeUndefined();\n  });\n\n  test('array response', async () => {\n    const promise = new APIPromise<Array<{ foo: string }>>(\n      client,\n      (async () => {\n        return {\n          response: new Response(JSON.stringify([{ foo: 'bar' }]), {\n            headers: { 'x-request-id': 'req_id_xxx', 'content-type': 'application/json' },\n          }),\n          controller: {} as any,\n          options: {} as any,\n          requestLogID: 'log_...',\n          retryOfRequestLogID: undefined,\n          startTime: Date.now(),\n        };\n      })(),\n    );\n\n    const rsp = await promise;\n    expect(rsp.length).toBe(1);\n    expect(rsp[0]).toMatchObject({ foo: 'bar' });\n    expect((rsp as any)._request_id).toBeUndefined();\n  });\n\n  test('string response', async () => {\n    const promise = new APIPromise<string>(\n      client,\n      (async () => {\n        return {\n          response: new Response('hello world', {\n            headers: { 'x-request-id': 'req_id_xxx', 'content-type': 'application/text' },\n          }),\n          controller: {} as any,\n          options: {} as any,\n          requestLogID: 'log_...',\n          retryOfRequestLogID: undefined,\n          startTime: Date.now(),\n        };\n      })(),\n    );\n\n    const result = await promise;\n    expect(result).toBe('hello world');\n    expect((result as any)._request_id).toBeUndefined();\n  });\n});\n"
  },
  {
    "path": "tests/responsesItems.test.ts",
    "content": "import OpenAI from 'openai/index';\nconst openai = new OpenAI({ apiKey: 'example-api-key' });\n\ndescribe('responses item types', () => {\n  test('response output items are compatible with input items', async () => {\n    expect(true).toBe(true);\n  });\n});\n\nconst unused = async () => {\n  const response = await openai.responses.create({\n    model: 'gpt-5.1',\n    input: 'You are a helpful assistant.',\n  });\n  await openai.responses.create({\n    model: 'gpt-5.1',\n    // check type compatibility\n    input: response.output,\n  });\n  expect(true).toBe(true);\n};\n"
  },
  {
    "path": "tests/streaming/assistants/assistant.test.ts",
    "content": "import OpenAI from 'openai';\nimport { AssistantStream } from 'openai/lib/AssistantStream';\n\nconst openai = new OpenAI({\n  apiKey: 'My API Key',\n  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',\n});\n\ndescribe('assistant tests', () => {\n  test('delta accumulation', () => {\n    expect(AssistantStream.accumulateDelta({}, {})).toEqual({});\n    expect(AssistantStream.accumulateDelta({}, { a: 'apple' })).toEqual({ a: 'apple' });\n\n    // strings\n    expect(AssistantStream.accumulateDelta({ a: 'foo' }, { a: ' bar' })).toEqual({ a: 'foo bar' });\n\n    // dictionaries\n    expect(AssistantStream.accumulateDelta({ a: { foo: '1' } }, { a: { bar: '2' } })).toEqual({\n      a: {\n        foo: '1',\n        bar: '2',\n      },\n    });\n    expect(AssistantStream.accumulateDelta({ a: { foo: 'hello,' } }, { a: { foo: ' world' } })).toEqual({\n      a: { foo: 'hello, world' },\n    });\n\n    expect(AssistantStream.accumulateDelta({}, { a: null })).toEqual({ a: null });\n    expect(AssistantStream.accumulateDelta({ a: null }, { a: 'apple' })).toEqual({ a: 'apple' });\n    expect(AssistantStream.accumulateDelta({ a: null }, { a: null })).toEqual({ a: null });\n  });\n});\n"
  },
  {
    "path": "tests/streaming.test.ts",
    "content": "import assert from 'assert';\nimport { _iterSSEMessages } from 'openai/core/streaming';\nimport { ReadableStreamFrom } from 'openai/internal/shims';\n\ndescribe('streaming decoding', () => {\n  test('basic', async () => {\n    async function* body(): AsyncGenerator<Buffer> {\n      yield Buffer.from('event: completion\\n');\n      yield Buffer.from('data: {\"foo\":true}\\n');\n      yield Buffer.from('\\n');\n    }\n\n    const stream = _iterSSEMessages(new Response(ReadableStreamFrom(body())), new AbortController())[\n      Symbol.asyncIterator\n    ]();\n\n    let event = await stream.next();\n    assert(event.value);\n    expect(JSON.parse(event.value.data)).toEqual({ foo: true });\n\n    event = await stream.next();\n    expect(event.done).toBeTruthy();\n  });\n\n  test('data without event', async () => {\n    async function* body(): AsyncGenerator<Buffer> {\n      yield Buffer.from('data: {\"foo\":true}\\n');\n      yield Buffer.from('\\n');\n    }\n\n    const stream = _iterSSEMessages(new Response(ReadableStreamFrom(body())), new AbortController())[\n      Symbol.asyncIterator\n    ]();\n\n    let event = await stream.next();\n    assert(event.value);\n    expect(event.value.event).toBeNull();\n    expect(JSON.parse(event.value.data)).toEqual({ foo: true });\n\n    event = await stream.next();\n    expect(event.done).toBeTruthy();\n  });\n\n  test('event without data', async () => {\n    async function* body(): AsyncGenerator<Buffer> {\n      yield Buffer.from('event: foo\\n');\n      yield Buffer.from('\\n');\n    }\n\n    const stream = _iterSSEMessages(new Response(ReadableStreamFrom(body())), new AbortController())[\n      Symbol.asyncIterator\n    ]();\n\n    let event = await stream.next();\n    assert(event.value);\n    expect(event.value.event).toEqual('foo');\n    expect(event.value.data).toEqual('');\n\n    event = await stream.next();\n    expect(event.done).toBeTruthy();\n  });\n\n  test('multiple events', async () => {\n    async function* body(): AsyncGenerator<Buffer> {\n      yield Buffer.from('event: foo\\n');\n      yield Buffer.from('\\n');\n      yield Buffer.from('event: ping\\n');\n      yield Buffer.from('\\n');\n    }\n\n    const stream = _iterSSEMessages(new Response(ReadableStreamFrom(body())), new AbortController())[\n      Symbol.asyncIterator\n    ]();\n\n    let event = await stream.next();\n    assert(event.value);\n    expect(event.value.event).toEqual('foo');\n    expect(event.value.data).toEqual('');\n\n    event = await stream.next();\n    assert(event.value);\n    expect(event.value.event).toEqual('ping');\n    expect(event.value.data).toEqual('');\n\n    event = await stream.next();\n    expect(event.done).toBeTruthy();\n  });\n\n  test('multiple events with data', async () => {\n    async function* body(): AsyncGenerator<Buffer> {\n      yield Buffer.from('event: foo\\n');\n      yield Buffer.from('data: {\"foo\":true}\\n');\n      yield Buffer.from('\\n');\n      yield Buffer.from('event: ping\\n');\n      yield Buffer.from('data: {\"bar\":false}\\n');\n      yield Buffer.from('\\n');\n    }\n\n    const stream = _iterSSEMessages(new Response(ReadableStreamFrom(body())), new AbortController())[\n      Symbol.asyncIterator\n    ]();\n\n    let event = await stream.next();\n    assert(event.value);\n    expect(event.value.event).toEqual('foo');\n    expect(JSON.parse(event.value.data)).toEqual({ foo: true });\n\n    event = await stream.next();\n    assert(event.value);\n    expect(event.value.event).toEqual('ping');\n    expect(JSON.parse(event.value.data)).toEqual({ bar: false });\n\n    event = await stream.next();\n    expect(event.done).toBeTruthy();\n  });\n\n  test('multiple data lines with empty line', async () => {\n    async function* body(): AsyncGenerator<Buffer> {\n      yield Buffer.from('event: ping\\n');\n      yield Buffer.from('data: {\\n');\n      yield Buffer.from('data: \"foo\":\\n');\n      yield Buffer.from('data: \\n');\n      yield Buffer.from('data:\\n');\n      yield Buffer.from('data: true}\\n');\n      yield Buffer.from('\\n\\n');\n    }\n\n    const stream = _iterSSEMessages(new Response(ReadableStreamFrom(body())), new AbortController())[\n      Symbol.asyncIterator\n    ]();\n\n    let event = await stream.next();\n    assert(event.value);\n    expect(event.value.event).toEqual('ping');\n    expect(JSON.parse(event.value.data)).toEqual({ foo: true });\n    expect(event.value.data).toEqual('{\\n\"foo\":\\n\\n\\ntrue}');\n\n    event = await stream.next();\n    expect(event.done).toBeTruthy();\n  });\n\n  test('data json escaped double new line', async () => {\n    async function* body(): AsyncGenerator<Buffer> {\n      yield Buffer.from('event: ping\\n');\n      yield Buffer.from('data: {\"foo\": \"my long\\\\n\\\\ncontent\"}');\n      yield Buffer.from('\\n\\n');\n    }\n\n    const stream = _iterSSEMessages(new Response(ReadableStreamFrom(body())), new AbortController())[\n      Symbol.asyncIterator\n    ]();\n\n    let event = await stream.next();\n    assert(event.value);\n    expect(event.value.event).toEqual('ping');\n    expect(JSON.parse(event.value.data)).toEqual({ foo: 'my long\\n\\ncontent' });\n\n    event = await stream.next();\n    expect(event.done).toBeTruthy();\n  });\n\n  test('special new line characters', async () => {\n    async function* body(): AsyncGenerator<Buffer> {\n      yield Buffer.from('data: {\"content\": \"culpa \"}\\n');\n      yield Buffer.from('\\n');\n      yield Buffer.from('data: {\"content\": \"');\n      yield Buffer.from([0xe2, 0x80, 0xa8]);\n      yield Buffer.from('\"}\\n');\n      yield Buffer.from('\\n');\n      yield Buffer.from('data: {\"content\": \"foo\"}\\n');\n      yield Buffer.from('\\n');\n    }\n\n    const stream = _iterSSEMessages(new Response(ReadableStreamFrom(body())), new AbortController())[\n      Symbol.asyncIterator\n    ]();\n\n    let event = await stream.next();\n    assert(event.value);\n    expect(JSON.parse(event.value.data)).toEqual({ content: 'culpa ' });\n\n    event = await stream.next();\n    assert(event.value);\n    expect(JSON.parse(event.value.data)).toEqual({ content: Buffer.from([0xe2, 0x80, 0xa8]).toString() });\n\n    event = await stream.next();\n    assert(event.value);\n    expect(JSON.parse(event.value.data)).toEqual({ content: 'foo' });\n\n    event = await stream.next();\n    expect(event.done).toBeTruthy();\n  });\n\n  test('multi-byte characters across chunks', async () => {\n    async function* body(): AsyncGenerator<Buffer> {\n      yield Buffer.from('event: completion\\n');\n      yield Buffer.from('data: {\"content\": \"');\n      // bytes taken from the string 'известни' and arbitrarily split\n      // so that some multi-byte characters span multiple chunks\n      yield Buffer.from([0xd0]);\n      yield Buffer.from([0xb8, 0xd0, 0xb7, 0xd0]);\n      yield Buffer.from([0xb2, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0xd0, 0xbd, 0xd0, 0xb8]);\n      yield Buffer.from('\"}\\n');\n      yield Buffer.from('\\n');\n    }\n\n    const stream = _iterSSEMessages(new Response(ReadableStreamFrom(body())), new AbortController())[\n      Symbol.asyncIterator\n    ]();\n\n    let event = await stream.next();\n    assert(event.value);\n    expect(event.value.event).toEqual('completion');\n    expect(JSON.parse(event.value.data)).toEqual({ content: 'известни' });\n\n    event = await stream.next();\n    expect(event.done).toBeTruthy();\n  });\n});\n"
  },
  {
    "path": "tests/stringifyQuery.test.ts",
    "content": "// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { stringifyQuery } from 'openai/internal/utils/query';\n\ndescribe(stringifyQuery, () => {\n  for (const [input, expected] of [\n    [{ a: '1', b: 2, c: true }, 'a=1&b=2&c=true'],\n    [{ a: null, b: false, c: undefined }, 'a=&b=false'],\n    [{ 'a/b': 1.28341 }, `${encodeURIComponent('a/b')}=1.28341`],\n    [\n      { 'a/b': 'c/d', 'e=f': 'g&h' },\n      `${encodeURIComponent('a/b')}=${encodeURIComponent('c/d')}&${encodeURIComponent(\n        'e=f',\n      )}=${encodeURIComponent('g&h')}`,\n    ],\n  ] as const) {\n    it(`${JSON.stringify(input)} -> ${expected}`, () => {\n      expect(stringifyQuery(input)).toEqual(expected);\n    });\n  }\n});\n"
  },
  {
    "path": "tests/uploads.test.ts",
    "content": "import fs from 'fs';\nimport type { ResponseLike } from 'openai/internal/to-file';\nimport { toFile } from 'openai/core/uploads';\nimport { File } from 'node:buffer';\n\nclass MyClass {\n  name: string = 'foo';\n}\n\nfunction mockResponse({ url, content }: { url: string; content?: Blob }): ResponseLike {\n  return {\n    url,\n    blob: async () => content || new Blob([]),\n  };\n}\n\ndescribe('toFile', () => {\n  it('throws a helpful error for mismatched types', async () => {\n    await expect(\n      // @ts-expect-error intentionally mismatched type\n      toFile({ foo: 'string' }),\n    ).rejects.toThrowErrorMatchingInlineSnapshot(\n      `\"Unexpected data type: object; constructor: Object; props: [\"foo\"]\"`,\n    );\n\n    await expect(\n      // @ts-expect-error intentionally mismatched type\n      toFile(new MyClass()),\n    ).rejects.toThrowErrorMatchingInlineSnapshot(\n      `\"Unexpected data type: object; constructor: MyClass; props: [\"name\"]\"`,\n    );\n  });\n\n  it('disallows string at the type-level', async () => {\n    // @ts-expect-error we intentionally do not type support for `string`\n    // to help people avoid passing a file path\n    const file = await toFile('contents');\n    expect(file.text()).resolves.toEqual('contents');\n  });\n\n  it('extracts a file name from a Response', async () => {\n    const response = mockResponse({ url: 'https://example.com/my/audio.mp3' });\n    const file = await toFile(response);\n    expect(file.name).toEqual('audio.mp3');\n  });\n\n  it('extracts a file name from a File', async () => {\n    const input = new File(['foo'], 'input.jsonl');\n    const file = await toFile(input);\n    expect(file.name).toEqual('input.jsonl');\n  });\n\n  it('extracts a file name from a ReadStream', async () => {\n    const input = fs.createReadStream('tests/uploads.test.ts');\n    const file = await toFile(input);\n    expect(file.name).toEqual('uploads.test.ts');\n  });\n\n  it('does not copy File objects', async () => {\n    const input = new File(['foo'], 'input.jsonl', { type: 'jsonl' });\n    const file = await toFile(input);\n    expect(file).toBe(input);\n    expect(file.name).toEqual('input.jsonl');\n    expect(file.type).toBe('jsonl');\n  });\n\n  it('is assignable to File and Blob', async () => {\n    const input = new File(['foo'], 'input.jsonl', { type: 'jsonl' });\n    const result = await toFile(input);\n    const file: File = result;\n    const blob: Blob = result;\n    void file, blob;\n  });\n});\n\ndescribe('missing File error message', () => {\n  let prevGlobalFile: unknown;\n  let prevNodeFile: unknown;\n  beforeEach(() => {\n    // The file shim captures the global File object when it's first imported.\n    // Reset modules before each test so we can test the error thrown when it's undefined.\n    jest.resetModules();\n    const buffer = require('node:buffer');\n    // @ts-ignore\n    prevGlobalFile = globalThis.File;\n    prevNodeFile = buffer.File;\n    // @ts-ignore\n    globalThis.File = undefined;\n    buffer.File = undefined;\n  });\n  afterEach(() => {\n    // Clean up\n    // @ts-ignore\n    globalThis.File = prevGlobalFile;\n    require('node:buffer').File = prevNodeFile;\n    jest.resetModules();\n  });\n\n  test('is thrown', async () => {\n    const uploads = await import('openai/core/uploads');\n    await expect(\n      uploads.toFile(mockResponse({ url: 'https://example.com/my/audio.mp3' })),\n    ).rejects.toMatchInlineSnapshot(\n      `[Error: \\`File\\` is not defined as a global, which is required for file uploads.]`,\n    );\n  });\n});\n"
  },
  {
    "path": "tests/utils/mock-fetch.ts",
    "content": "import { type Fetch, type RequestInfo, type RequestInit, type Response } from 'openai/internal/builtin-types';\n\n/**\n * Creates a mock `fetch` function and a `handleRequest` function for intercepting `fetch` calls.\n *\n * You call `handleRequest` with a callback function that handles the next `fetch` call.\n * It returns a Promise that:\n * - waits for the next call to `fetch`\n * - calls the callback with the `fetch` arguments\n * - resolves `fetch` with the callback output\n */\nexport function mockFetch(): { fetch: Fetch; handleRequest: (handle: Fetch) => Promise<void> } {\n  const fetchQueue: ((handler: typeof fetch) => void)[] = [];\n  const handlerQueue: Promise<typeof fetch>[] = [];\n\n  const enqueueHandler = () => {\n    handlerQueue.push(\n      new Promise<typeof fetch>((resolve) => {\n        fetchQueue.push((handle: typeof fetch) => {\n          enqueueHandler();\n          resolve(handle);\n        });\n      }),\n    );\n  };\n  enqueueHandler();\n\n  async function fetch(req: string | RequestInfo, init?: RequestInit): Promise<Response> {\n    const handler = await handlerQueue.shift();\n    if (!handler) throw new Error('expected handler to be defined');\n    const signal = init?.signal;\n    if (!signal) return await handler(req, init);\n    return await Promise.race([\n      handler(req, init),\n      new Promise<Response>((resolve, reject) => {\n        if (signal.aborted) {\n          // @ts-ignore does exist in Node\n          reject(new DOMException('The user aborted a request.', 'AbortError'));\n          return;\n        }\n        signal.addEventListener('abort', (e) => {\n          // @ts-ignore does exist in Node\n          reject(new DOMException('The user aborted a request.', 'AbortError'));\n        });\n      }),\n    ]);\n  }\n\n  function handleRequest(handle: typeof fetch): Promise<void> {\n    return new Promise<void>((resolve, reject) => {\n      fetchQueue.shift()?.(async (req, init) => {\n        try {\n          return await handle(req, init);\n        } catch (err) {\n          reject(err);\n          return err as any;\n        } finally {\n          resolve();\n        }\n      });\n    });\n  }\n\n  return { fetch, handleRequest };\n}\n"
  },
  {
    "path": "tests/utils/mock-snapshots.ts",
    "content": "import OpenAI from 'openai/index';\nimport { RequestInfo } from 'openai/internal/builtin-types';\nimport { mockFetch } from './mock-fetch';\nimport { Readable } from 'stream';\n\nconst defaultFetch = fetch;\n\nexport async function makeSnapshotRequest<T>(\n  requestFn: (client: OpenAI) => Promise<T>,\n  snapshotIndex = 1,\n): Promise<T> {\n  if (process.env['UPDATE_API_SNAPSHOTS'] === '1') {\n    var capturedResponseContent: string | null = null;\n\n    async function fetch(url: RequestInfo, init?: RequestInit) {\n      const response = await defaultFetch(url, init);\n      capturedResponseContent = await response.text();\n      return new Response(capturedResponseContent, response);\n    }\n\n    const openai = new OpenAI({ fetch });\n\n    const result = await requestFn(openai);\n    if (!capturedResponseContent) {\n      throw new Error('did not capture a response');\n    }\n\n    const text = capturedResponseContent;\n    expect(text).toMatchSnapshot();\n    return result;\n  }\n\n  const qualifiedSnapshotName = [expect.getState().currentTestName, snapshotIndex].join(' ');\n  const snapshotState = expect.getState()['snapshotState'];\n  (snapshotState._uncheckedKeys as Set<string>).delete(qualifiedSnapshotName);\n\n  const data = snapshotState._snapshotData[qualifiedSnapshotName];\n  if (!data) {\n    throw new Error(`could not resolve snapshot with name ${qualifiedSnapshotName}`);\n  }\n  if (typeof data !== 'string') {\n    console.error(data);\n    throw new Error('Expected snapshot data to be a string');\n  }\n\n  const { fetch, handleRequest } = mockFetch();\n\n  const openai = new OpenAI({ fetch, apiKey: 'My API Key' });\n  const requestPromise = requestFn(openai);\n\n  await handleRequest(() =>\n    Promise.resolve(\n      new Response(\n        // remove leading & trailing quotes\n        data.slice(2, -2),\n        {\n          status: 200,\n          headers: { 'content-type': 'application/json' },\n        },\n      ),\n    ),\n  );\n\n  return await requestPromise;\n}\n\nexport async function makeStreamSnapshotRequest<T extends AsyncIterable<any>>(\n  requestFn: (client: OpenAI) => T,\n): Promise<T> {\n  if (process.env['UPDATE_API_SNAPSHOTS'] === '1') {\n    var capturedResponseContent: string | null = null;\n\n    async function fetch(url: RequestInfo, init?: RequestInit) {\n      const response = await defaultFetch(url, init);\n      capturedResponseContent = await response.text();\n      return new Response(Readable.from(capturedResponseContent), response);\n    }\n\n    const openai = new OpenAI({ fetch });\n\n    const iterator = requestFn(openai);\n    for await (const _ of iterator) {\n      // consume iterator\n    }\n\n    if (!capturedResponseContent) {\n      throw new Error('did not capture a response');\n    }\n\n    const text = capturedResponseContent;\n    expect(text).toMatchSnapshot();\n    return iterator;\n  }\n\n  const qualifiedSnapshotName = `${expect.getState().currentTestName} 1`;\n  const snapshotState = expect.getState()['snapshotState'];\n  (snapshotState._uncheckedKeys as Set<string>).delete(qualifiedSnapshotName);\n\n  const data = snapshotState._snapshotData[qualifiedSnapshotName];\n  if (!data) {\n    throw new Error(`could not resolve snapshot with name ${qualifiedSnapshotName}`);\n  }\n  if (typeof data !== 'string') {\n    console.error(data);\n    throw new Error('Expected snapshot data to be a string');\n  }\n\n  const { fetch, handleRequest } = mockFetch();\n\n  const openai = new OpenAI({ fetch, apiKey: 'My API Key' });\n  const requestPromise = requestFn(openai);\n\n  await handleRequest(() =>\n    Promise.resolve(\n      new Response(\n        // remove leading & trailing quotes\n        Readable.from(data.slice(2, -2)),\n        {\n          status: 200,\n          headers: { 'content-type': 'application/json' },\n        },\n      ),\n    ),\n  );\n\n  return requestPromise;\n}\n"
  },
  {
    "path": "tests/utils/typing.ts",
    "content": "type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;\n\nexport const expectType = <T>(_expression: T): void => {\n  return;\n};\n\nexport const compareType = <T1, T2>(_expression: Equal<T1, T2>): void => {\n  return;\n};\n"
  },
  {
    "path": "tsc-multi.json",
    "content": "{\n  \"targets\": [\n    {\n      \"extname\": \".js\",\n      \"module\": \"commonjs\",\n      \"shareHelpers\": \"internal/tslib.js\"\n    },\n    {\n      \"extname\": \".mjs\",\n      \"module\": \"esnext\",\n      \"shareHelpers\": \"internal/tslib.mjs\"\n    }\n  ],\n  \"projects\": [\"tsconfig.build.json\"]\n}\n"
  },
  {
    "path": "tsconfig.build.json",
    "content": "{\n  \"extends\": \"./tsconfig.json\",\n  \"include\": [\"dist/src\"],\n  \"exclude\": [],\n  \"compilerOptions\": {\n    \"rootDir\": \"./dist/src\",\n    \"paths\": {\n      \"openai/*\": [\"./dist/src/*\"],\n      \"openai\": [\"./dist/src/index.ts\"]\n    },\n    \"noEmit\": false,\n    \"declaration\": true,\n    \"declarationMap\": true,\n    \"outDir\": \"dist\",\n    \"pretty\": true,\n    \"sourceMap\": true\n  }\n}\n"
  },
  {
    "path": "tsconfig.deno.json",
    "content": "{\n  \"extends\": \"./tsconfig.json\",\n  \"include\": [\"dist-deno\"],\n  \"exclude\": [],\n  \"compilerOptions\": {\n    \"rootDir\": \"./dist-deno\",\n    \"lib\": [\"es2020\", \"DOM\"],\n    \"noEmit\": true,\n    \"declaration\": true,\n    \"declarationMap\": true,\n    \"outDir\": \"dist-deno\",\n    \"pretty\": true,\n    \"sourceMap\": true\n  }\n}\n"
  },
  {
    "path": "tsconfig.dist-src.json",
    "content": "{\n  // this config is included in the published src directory to prevent TS errors\n  // from appearing when users go to source, and VSCode opens the source .ts file\n  // via declaration maps\n  \"include\": [\"index.ts\"],\n  \"compilerOptions\": {\n    \"target\": \"ES2015\",\n    \"lib\": [\"DOM\", \"DOM.Iterable\", \"ES2018\"],\n    \"moduleResolution\": \"node\"\n  }\n}\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n  \"include\": [\"src\", \"tests\", \"examples\"],\n  \"exclude\": [],\n  \"compilerOptions\": {\n    \"target\": \"es2020\",\n    \"lib\": [\"es2020\"],\n    \"module\": \"commonjs\",\n    \"moduleResolution\": \"node\",\n    \"esModuleInterop\": true,\n    \"paths\": {\n      \"openai/*\": [\"./src/*\"],\n      \"openai\": [\"./src/index.ts\"]\n    },\n    \"noEmit\": true,\n\n    \"resolveJsonModule\": true,\n\n    \"forceConsistentCasingInFileNames\": true,\n\n    \"strict\": true,\n    \"noImplicitAny\": true,\n    \"strictNullChecks\": true,\n    \"strictFunctionTypes\": true,\n    \"strictBindCallApply\": true,\n    \"strictPropertyInitialization\": true,\n    \"noImplicitThis\": true,\n    \"noImplicitReturns\": true,\n    \"alwaysStrict\": true,\n    \"exactOptionalPropertyTypes\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"noImplicitOverride\": true,\n    \"noPropertyAccessFromIndexSignature\": true,\n    \"isolatedModules\": true,\n\n    \"skipLibCheck\": true\n  }\n}\n"
  }
]