Skip to content
Source
Sign inSign up
TanStack/ai

feat(ai-openai): allow passing all open ai configuration options #245

Mergedruudandriessen(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/245/headmerged by AlemTuzlak View on GitHub

🎯 Changes

Allows passing in properties into openAI configuration like dangerouslyAllowBrowser. Resolved the discussion here https://github.com/TanStack/ai/discussions/197

Note: may want to consider if we want to expose all options all at once or limit to a smaller subset

✅ Checklist

  • I have followed the steps in the Contributing guide. --> contribution guidelines are no longer part of the repo?
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features

    • OpenAI client accepts additional configuration options for more flexible initialization.
    • New exported model type names (chat, image, video, TTS, transcription) available for consumers.
  • Refactor

    • Model and client types reorganized and re-exported from a centralized module for clearer type usage across the package.
  • Chores

    • Added a changeset entry documenting the minor version bump.
✏️ Tip: You can customize this high-level summary in your review settings.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      📝 Walkthrough

      Walkthrough

      Model name unions moved into model-meta; OpenAI client config and helpers relocated to utils/client; utils/index re-exports removed; adapters updated to import model types and client utilities from new locations; index exports extended to include new model and client types. No runtime behavior changes.

      Changes

      Cohort / File(s)Summary
      Changeset entry
      \.changeset/olive-wolves-love\.md
      New changeset bump for @tanstack/ai-openai documenting expanded client configuration options.
      Client utils
      packages/typescript/ai-openai/src/utils/client.ts, packages/typescript/ai-openai/src/utils/index.ts
      OpenAIClientConfig now extends ClientOptions from openai; createOpenAIClient forwards full config to the SDK. utils/index.ts no longer re-exports client and schema-converter symbols.
      Model metadata & public exports
      packages/typescript/ai-openai/src/model-meta.ts, packages/typescript/ai-openai/src/index.ts
      Added exported union types: OpenAIChatModel, OpenAIImageModel, OpenAIVideoModel, OpenAITTSModel, OpenAITranscriptionModel. Index now exports these and OpenAIClientConfig from ./utils/client.
      Adapters — types/imports updated
      packages/typescript/ai-openai/src/adapters/*
      .../adapters/image.ts, .../adapters/summarize.ts, .../adapters/text.ts, .../adapters/transcription.ts, .../adapters/tts.ts, .../adapters/video.ts
      Removed in-file model type aliases; adapters now import model types from ../model-meta. Import paths updated to use ../utils/client for OpenAIClientConfig, createOpenAIClient, and getOpenAIApiKeyFromEnv. Generic constraints updated (e.g., adapters now use OpenAIChatModel).

      Sequence Diagram(s)

      (omitted — changes are type/import refactors without new multi-component control flow)

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~20 minutes

      • TanStack/ai#188 — modifies model-meta and public exports (model name/type defs and index exports).
      • TanStack/ai#137 — related refactor moving client utilities and model types to model-meta / utils/client.

      Suggested reviewers

      • AlemTuzlak

      Poem

      🐰 I hopped through types and tidy imports bright, Moved model names to meta, snug and right, Client options stretched to carry more, Adapters fetch types from a shared store, A small hop forward — code feels light. 🌷

      🚥 Pre-merge checks | ✅ 3
      ✅ Passed checks (3 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and specifically describes the main change: allowing all OpenAI configuration options to be passed through, which aligns with the refactoring shown across multiple adapter files.
      Description check✅ PassedThe PR description addresses the key motivation and references the related discussion, but several checklist items are incomplete or marked as not applicable, and the description lacks detail about the technical approach.
      Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      ✨ Finishing touches
      • 📝 Generate docstrings

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. Actionable comments posted: 2

      🤖 Fix all issues with AI agents
      In @.changeset/olive-wolves-love.md:
      - Line 5: Update the changeset copy that currently reads "allows additional
      configuration options when creating an openAI client" to use the correct brand
      casing "OpenAI" (i.e., change "openAI" → "OpenAI"), and scan the same .changeset
      entry for any other occurrences of "openAI" to correct them for consistency.
      
      In `@packages/typescript/ai-openai/src/utils/client.ts`:
      - Around line 2-6: OpenAIClientConfig currently forces apiKey as required which
      conflicts with openai's ClientOptions where apiKey is optional; change
      OpenAIClientConfig to make apiKey optional (apiKey?: string) so it extends
      ClientOptions' fallback behavior, or alternatively document why a required
      apiKey is intentional—update the OpenAIClientConfig interface declaration
      (symbol: OpenAIClientConfig) and ensure it aligns with ClientOptions from the
      openai SDK (symbol: ClientOptions) so callers can rely on
      process.env.OPENAI_API_KEY when not supplying a key.
      @@ -0,0 +1,5 @@
      1+---
      2+'@tanstack/ai-openai': minor
      3+---
      4+
      5+allows additional configuration options when creating an openAI client
      coderabbitai[bot](GitHub profile, opens in a new tab)commented

      ⚠️ Potential issue | 🟡 Minor

      Capitalize “OpenAI” in the changeset text. Minor copy edit for brand casing.

      ✏️ Suggested fix
      -allows additional configuration options when creating an openAI client
      +allows additional configuration options when creating an OpenAI client
      📝 Committable suggestion

      ‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

      Suggested change
      5-allows additional configuration options when creating an openAI client
      5+allows additional configuration options when creating an OpenAI client
      🤖 Prompt for AI Agents
      In @.changeset/olive-wolves-love.md at line 5, Update the changeset copy that
      currently reads "allows additional configuration options when creating an openAI
      client" to use the correct brand casing "OpenAI" (i.e., change "openAI" →
      "OpenAI"), and scan the same .changeset entry for any other occurrences of
      "openAI" to correct them for consistency.
      @@ -1,7 +1,6 @@
      11 import OpenAI_SDK from 'openai'
      2+import type { ClientOptions } from 'openai';
      23
      3-export interface OpenAIClientConfig {
      4- apiKey: string
      5- organization?: string
      6- baseURL?: string
      4+export interface OpenAIClientConfig extends ClientOptions {
      5+ apiKey: string;
      76 }
      coderabbitai[bot](GitHub profile, opens in a new tab)commented

      ⚠️ Potential issue | 🟡 Minor

      🧩 Analysis chain

      🏁 Script executed:

      find . -path "*/packages/typescript/ai-openai/package.json" -o -path "*/packages/typescript/ai-openai/**/package.json" | head -5

      Repository: TanStack/ai

      Length of output: 155


      🏁 Script executed:

      cat packages/typescript/ai-openai/package.json | grep -A 5 -B 5 "openai"

      Repository: TanStack/ai

      Length of output: 743


      🌐 Web query:

      OpenAI JavaScript SDK ClientOptions interface apiKey required github.com/openai/openai-node

      💡 Result:

      In openai/openai-node, ClientOptions.apiKey is not required in the TypeScript type—it’s declared as optional (apiKey?: string). [1]

      However, the SDK still needs an API key at runtime: if you don’t pass apiKey, it will use process.env.OPENAI_API_KEY (so you can omit apiKey only if that env var is set). [2]

      Sources: [1] [2]


      Remove apiKey requirement from OpenAIClientConfig to match SDK flexibility.

      The OpenAI SDK v6.9.1+ declares ClientOptions.apiKey as optional (apiKey?: string), allowing the SDK to fall back to process.env.OPENAI_API_KEY if the key is not explicitly passed. Making apiKey: string required in OpenAIClientConfig adds an unnecessary constraint and prevents developers from leveraging the SDK's environment variable fallback. Either make apiKey optional in the interface or document why this stricter requirement is intentional for your use case.

      🤖 Prompt for AI Agents
      In `@packages/typescript/ai-openai/src/utils/client.ts` around lines 2 - 6,
      OpenAIClientConfig currently forces apiKey as required which conflicts with
      openai's ClientOptions where apiKey is optional; change OpenAIClientConfig to
      make apiKey optional (apiKey?: string) so it extends ClientOptions' fallback
      behavior, or alternatively document why a required apiKey is intentional—update
      the OpenAIClientConfig interface declaration (symbol: OpenAIClientConfig) and
      ensure it aligns with ClientOptions from the openai SDK (symbol: ClientOptions)
      so callers can rely on process.env.OPENAI_API_KEY when not supplying a key.
    3. AlemTuzlak approved these changes

    4. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit b9d43a0e2b7796cafd393b6f230b0117040b0678

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded1m 6sView ↗
      nx run-many --targets=build --exclude=examples/**✅ Succeeded37sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-01-23 14:49:59 UTC

    5. Actionable comments posted: 1

      🤖 Fix all issues with AI agents
      In `@packages/typescript/ai-openai/src/adapters/summarize.ts`:
      - Around line 4-10: You removed the backwards-compatible type alias
      OpenAISummarizeModel by constraining generics to OpenAIChatModel; restore a
      compatibility export by reintroducing a deprecated alias such as "export type
      OpenAISummarizeModel = OpenAIChatModel" (add a JSDoc `@deprecated` note) near the
      imports or the top of summarize.ts and replicate the same alias in the other
      modules where the alias was removed so existing consumer imports keep working
      (look for places referencing OpenAIChatModel generics around the summarize
      adapter and the other spots mentioned).
    6. AlemTuzlak approved these changes

      Thank you for this!

    7. Open in StackBlitz

      @tanstack/ai

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@245

      @tanstack/ai-anthropic

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@245

      @tanstack/ai-client

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@245

      @tanstack/ai-devtools-core

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@245

      @tanstack/ai-gemini

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@245

      @tanstack/ai-grok

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@245

      @tanstack/ai-ollama

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@245

      @tanstack/ai-openai

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@245

      @tanstack/ai-openrouter

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@245

      @tanstack/ai-preact

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@245

      @tanstack/ai-react

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@245

      @tanstack/ai-react-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@245

      @tanstack/ai-solid

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@245

      @tanstack/ai-solid-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@245

      @tanstack/ai-svelte

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@245

      @tanstack/ai-vue

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@245

      @tanstack/ai-vue-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@245

      @tanstack/preact-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@245

      @tanstack/react-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@245

      @tanstack/solid-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@245

      commit: b9d43a0

    8. AlemTuzlak merged this356df1a

    9. AlemTuzlak closed this

Sign in to join this conversation.