Skip to content

fix(ai-openai): migrate WebRTC realtime adapter to OpenAI GA API#699

Open
amitsaroj wants to merge 1 commit into
TanStack:mainfrom
amitsaroj:fix/openai-realtime-ga-migration
Open

fix(ai-openai): migrate WebRTC realtime adapter to OpenAI GA API#699
amitsaroj wants to merge 1 commit into
TanStack:mainfrom
amitsaroj:fix/openai-realtime-ga-migration

Conversation

@amitsaroj
Copy link
Copy Markdown

@amitsaroj amitsaroj commented Jun 3, 2026

🎯 Changes

Fixes #586

Migrates the @tanstack/ai-openai WebRTC realtime adapter from the deprecated OpenAI Beta realtime API to the GA (generally available) API. OpenAI deprecated the Beta realtime endpoint on 2026-05-12, causing all openaiRealtime() connections to fail with beta_api_shape_disabled.

Root Cause

Two GA-shape mismatches in packages/ai-openai/src/realtime/adapter.ts:

1. Wrong SDP-exchange endpoint (connection fails immediately)

The Beta API used /v1/realtime?model=<model> for WebRTC SDP negotiation. OpenAI's GA API uses /v1/realtime/calls.

// Before (Beta — returns HTTP 400 beta_api_shape_disabled)
const sdpResponse = await fetch(`${OPENAI_REALTIME_URL}?model=${model}`, { ... })

// After (GA)
const sdpResponse = await fetch(`${OPENAI_REALTIME_URL}/calls`, { ... })

2. Missing session.type in updateSession (session config silently rejected)

The GA API requires session.type on every session.update event. Without it, the server rejects the update with missing_required_parameter: session.type, which means instructions, tools, and voice settings are never applied.

// Before (Beta — session.type not required)
const sessionUpdate: Record<string, unknown> = {}

// After (GA — "realtime" is the session type for openaiRealtime())
const sessionUpdate: Record<string, unknown> = { type: 'realtime' }

Fix

Minimal two-line change, consistent with the issue reporter's verified local fix.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • - [ ] I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.

🧪 Test Plan

  1. Call new RealtimeClient({ adapter: openaiRealtime(), ... }).connect() against OpenAI's live API.
    1. Verify no beta_api_shape_disabled 400 error.
    1. Verify session.update is accepted (instructions, tools, and voice apply correctly).
    1. Existing unit tests in packages/ai-openai/tests/openai-adapter.test.ts cover the session update shape.

Summary by CodeRabbit

  • Bug Fixes
    • Updated WebRTC endpoint configuration for realtime API SDP exchange.
    • Improved session update payload handling to ensure proper session event delivery.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 62bd639f-8888-45b9-bc78-4df549e5bb50

📥 Commits

Reviewing files that changed from the base of the PR and between 769a6c7 and b6841a8.

📒 Files selected for processing (1)
  • packages/ai-openai/src/realtime/adapter.ts

📝 Walkthrough

Walkthrough

The adapter updates address OpenAI's deprecated Beta realtime API and session event initialization. The SDP exchange endpoint migrates from the Beta shape using a model query parameter to the GA /calls endpoint, and updateSession now initializes with type: 'realtime' to ensure session update events emit when no other config fields are provided.

Changes

OpenAI Realtime Adapter Fixes

Layer / File(s) Summary
WebRTC endpoint and session initialization
packages/ai-openai/src/realtime/adapter.ts
SDP exchange URL migrated from deprecated Beta endpoint (?model=...) to GA endpoint (/calls). Session update initialization changed from empty object to { type: 'realtime' } to ensure events emit when no other config is set.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 The Beta's gone, the GA's here,
/calls replaces query cheer,
Session types now always flow,
Real-time whispers, all aglow! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: migrating the WebRTC realtime adapter to OpenAI's GA API, which is the central focus of the PR.
Description check ✅ Passed The description comprehensively covers the changes, provides clear root cause analysis with before/after code examples, and includes release impact and test plan information.
Linked Issues check ✅ Passed The PR successfully addresses both objectives from issue #586: updating the SDP endpoint from Beta /v1/realtime?model=... to GA /v1/realtime/calls and adding required session.type: 'realtime' field.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the immediate GA API migration issues identified in #586; follow-up concerns about event type renames are explicitly noted as out-of-scope future work.
Docstring Coverage ✅ Passed Docstring 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 unit tests (beta)
  • Create PR with unit tests

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ai-openai] Realtime WebRTC SDP exchange uses deprecated Beta endpoint — fails with beta_api_shape_disabled

1 participant