Skip to content

fix(realtime): dial Azure's GA realtime upstream for GA clients - #40769

Merged
mateo-berri merged 4 commits into
litellm_internal_stagingfrom
litellm_azure_realtime_ga_default
Sep 12, 2026
Merged

mateo-berri merged 4 commits into
litellm_internal_stagingfrom
litellm_azure_realtime_ga_default

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • GA realtime clients on Azure gpt-realtime get Unknown parameter: 'session.type'
  • Azure always dialed the beta upstream when realtime_protocol was unset
  • The client's GA session.update was forwarded to that beta upstream unchanged
  • The Azure realtime health probe dialed that same beta upstream, so /health vouched for an upstream GA clients never reach

How it solves it:

  • An unset realtime_protocol now follows the client, like the OpenAI handler
  • OpenAI-Beta: realtime=v1 on the client socket keeps the beta upstream
  • Any other client gets Azure's /openai/v1/realtime GA upstream
  • The health probe defaults to that same GA upstream, so /health and the Admin UI Test Connect check what headerless clients get
  • Explicit realtime_protocol and LITELLM_AZURE_REALTIME_PROTOCOL still win, for clients and for the probe

User Flow

Before: a voice-agent developer pointing the OpenAI SDK's GA realtime client at the proxy's Azure gpt-realtime deployment gets the first session.update rejected, so the agent never gets its own instructions

  1. The proxy admin adds gpt-realtime as azure/gpt-realtime with the Azure resource's api_base and api_key, and no realtime_protocol
  2. The developer's app opens wss://litellm-domain/v1/realtime?model=gpt-realtime with client.realtime.connect(model="gpt-realtime") from the OpenAI SDK, which sends no OpenAI-Beta header
  3. The socket opens and a session.created event comes back, so the app shows "Speak now"
  4. The app sends its first session.update with {"session": {"type": "realtime", "output_modalities": ["audio"], "instructions": "...", "audio": {...}}}
  5. The next event is {"type": "error", "error": {"message": "Unknown parameter: 'session.type'.", "code": "unknown_parameter", "param": "session.type"}}, and gpt-realtime-1.5 fails the same way
  6. The admin's GET /health lists the deployment as healthy anyway, because the probe dialed the beta upstream the app never touched

After: the same GA client gets session.updated back, so the voice agent runs with its own instructions

  1. The proxy admin adds gpt-realtime as azure/gpt-realtime with the Azure resource's api_base and api_key, and no realtime_protocol
  2. The developer's app opens wss://litellm-domain/v1/realtime?model=gpt-realtime with client.realtime.connect(model="gpt-realtime") from the OpenAI SDK, which sends no OpenAI-Beta header
  3. The socket opens and a session.created event comes back, so the app shows "Speak now"
  4. The app sends its first session.update with {"session": {"type": "realtime", "output_modalities": ["audio"], "instructions": "...", "audio": {...}}}
  5. The next event is session.updated carrying "type": "realtime", "output_modalities": ["audio"], and the app's instructions, and gpt-realtime-1.5 behaves the same
  6. An app still on client.beta.realtime.connect (which sends OpenAI-Beta: realtime=v1) keeps getting beta-shaped session.updated events exactly as before
  7. The admin's GET /health and the Admin UI's Test Connect on that deployment probe the same GA upstream the app reaches, and a deployment pinned with realtime_protocol: beta keeps probing beta

Relevant issues

Relates to #24212 (the same error, fixed for OpenAI by #27110; this covers the Azure path)

Reopened from #40615 with the same commits so the approval can come from someone other than the author

Linear ticket

Resolves LIT-7451

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Shared setup: one proxy per leg booted from the named commit with python litellm/proxy/proxy_cli.py --config config.yaml --port <port> --num_workers 2 (two uvicorn workers on both legs, one proxy at a time on a random free port). Real Azure OpenAI resource in eastus2 with gpt-realtime and gpt-realtime-1.5 deployed (resource name redacted below), openai SDK 2.33.0. The two probe-url-echo-* entries point at a plain http:// base on purpose: the health probe rejects that scheme and names the exact URL it tried to dial in the /health error, which is how the A/B shows which upstream the probe picks. The long session.created lines are cut short

model_list:
  - model_name: gpt-realtime
    litellm_params:
      model: azure/gpt-realtime
      api_base: https://<resource>.cognitiveservices.azure.com
      api_key: os.environ/AZURE_API_KEY
    model_info:
      mode: realtime
  - model_name: gpt-realtime-1.5
    litellm_params:
      model: azure/gpt-realtime-1.5
      api_base: https://<resource>.cognitiveservices.azure.com
      api_key: os.environ/AZURE_API_KEY
    model_info:
      mode: realtime
  - model_name: probe-url-echo-unpinned
    litellm_params:
      model: azure/gpt-realtime
      api_base: http://127.0.0.1:39098
      api_key: recorder-key
    model_info:
      mode: realtime
  - model_name: probe-url-echo-pinned-beta
    litellm_params:
      model: azure/gpt-realtime
      api_base: http://127.0.0.1:39098
      api_key: recorder-key
      realtime_protocol: beta
    model_info:
      mode: realtime
general_settings:
  master_key: sk-1234

ga_client.py, the customer's kind of client (GA realtime client, no OpenAI-Beta header), sends the GA-shaped session.update and prints each event's type plus a few session fields:

import asyncio, json, sys
from openai import AsyncOpenAI

async def main() -> None:
    base_url, model, api_key = sys.argv[1], sys.argv[2], sys.argv[3]
    client = AsyncOpenAI(base_url=base_url, api_key=api_key, websocket_base_url=base_url.replace("http://", "ws://"))
    async with client.realtime.connect(model=model) as conn:
        await conn.session.update(session={
            "type": "realtime", "output_modalities": ["audio"], "instructions": "You are a voice agent. Keep answers short.",
            "audio": {"input": {"turn_detection": {"type": "server_vad"}}, "output": {"voice": "alloy"}},
        })
        async for event in conn:
            print(json.dumps({"type": event.type, **({"error": event.error.model_dump(exclude_none=True)} if event.type == "error" else {"session": {k: v for k, v in event.session.model_dump(exclude_none=True).items() if k in ("type", "model", "modalities", "output_modalities", "instructions")}})}))
            if event.type in ("session.updated", "error"):
                break

asyncio.run(main())

beta_client.py is the same script with client.beta.realtime.connect(model=model) (sends OpenAI-Beta: realtime=v1) and session={"modalities": ["text"], "instructions": "You are a voice agent. Keep answers short."}

Before (692a311)

GA client, gpt-realtime

  1. python ga_client.py http://127.0.0.1:55673 gpt-realtime sk-1234
  2. Output:
{"type": "session.created", "session": {"instructions": "Your knowledge cutoff is 2023-10. You are a helpful, witty, and friendly AI. Act like a human, but remember that you aren't a human and that you can't do human things in the real world. Your voice and personality should be warm and engaging, with a lively and playful tone.
{"type": "error", "error": {"message": "Unknown parameter: 'session.type'.", "type": "invalid_request_error", "code": "unknown_parameter", "param": "session.type"}}

Beta-header client, gpt-realtime

  1. python beta_client.py http://127.0.0.1:55673 gpt-realtime sk-1234
  2. Output:
{"type": "session.created", "session": {"instructions": "Your knowledge cutoff is 2023-10. You are a helpful, witty, and friendly AI. Act like a human, but remember that you aren't a human and that you can't do human things in the real world. Your voice and personality should be warm and engaging, with a lively and playful tone.
{"type": "session.updated", "session": {"instructions": "You are a voice agent. Keep answers short.", "modalities": ["text"], "model": "gpt-realtime"}}

GA client, gpt-realtime-1.5

  1. python ga_client.py http://127.0.0.1:55673 gpt-realtime-1.5 sk-1234
  2. Output:
{"type": "session.created", "session": {"instructions": "Your knowledge cutoff is 2023-10. You are a helpful, witty, and friendly AI. Act like a human, but remember that you aren't a human and that you can't do human things in the real world. Your voice and personality should be warm and engaging, with a lively and playful tone.
{"type": "error", "error": {"message": "Unknown parameter: 'session.type'.", "type": "invalid_request_error", "code": "unknown_parameter", "param": "session.type"}}

Beta-header client, gpt-realtime-1.5

  1. python beta_client.py http://127.0.0.1:55673 gpt-realtime-1.5 sk-1234
  2. Output:
{"type": "session.created", "session": {"instructions": "Your knowledge cutoff is 2023-10. You are a helpful, witty, and friendly AI. Act like a human, but remember that you aren't a human and that you can't do human things in the real world. Your voice and personality should be warm and engaging, with a lively and playful tone.
{"type": "session.updated", "session": {"instructions": "You are a voice agent. Keep answers short.", "modalities": ["text"], "model": "gpt-realtime-1.5"}}

Health probe (GET /health, every deployment in mode: realtime)

  1. curl -s http://127.0.0.1:55673/health -H 'Authorization: Bearer sk-1234' | jq '{healthy_endpoints: [.healthy_endpoints[]? | {model, api_base}], unhealthy_endpoints: [.unhealthy_endpoints[]? | {model, api_base, error: (.error // "" | split("\n")[0])}]}'
  2. Output (both echo entries dial the beta upstream, the pinned and the unpinned one alike):
{
  "healthy_endpoints": [
    {
      "model": "azure/gpt-realtime",
      "api_base": "https://<resource>.cognitiveservices.azure.com"
    },
    {
      "model": "azure/gpt-realtime-1.5",
      "api_base": "https://<resource>.cognitiveservices.azure.com"
    }
  ],
  "unhealthy_endpoints": [
    {
      "model": "azure/gpt-realtime",
      "api_base": "http://127.0.0.1:39098",
      "error": "http://127.0.0.1:39098/openai/realtime?api-version=2024-10-01-preview&deployment=gpt-realtime isn't a valid URI: scheme isn't ws or wss"
    },
    {
      "model": "azure/gpt-realtime",
      "api_base": "http://127.0.0.1:39098",
      "error": "http://127.0.0.1:39098/openai/realtime?api-version=2024-10-01-preview&deployment=gpt-realtime isn't a valid URI: scheme isn't ws or wss"
    }
  ]
}

After (105dc77)

GA client, gpt-realtime

  1. python ga_client.py http://127.0.0.1:52670 gpt-realtime sk-1234
  2. Output:
{"type": "session.created", "session": {"type": "realtime", "instructions": "Your knowledge cutoff is 2023-10. You are a helpful, witty, and friendly AI. Act like a human, but remember that you aren't a human and that you can't do human things in the real world. Your voice and personality should be warm and engaging, with a live
{"type": "session.updated", "session": {"type": "realtime", "instructions": "You are a voice agent. Keep answers short.", "model": "gpt-realtime", "output_modalities": ["audio"]}}

Beta-header client, gpt-realtime

  1. python beta_client.py http://127.0.0.1:52670 gpt-realtime sk-1234
  2. Output:
{"type": "session.created", "session": {"instructions": "Your knowledge cutoff is 2023-10. You are a helpful, witty, and friendly AI. Act like a human, but remember that you aren't a human and that you can't do human things in the real world. Your voice and personality should be warm and engaging, with a lively and playful tone.
{"type": "session.updated", "session": {"instructions": "You are a voice agent. Keep answers short.", "modalities": ["text"], "model": "gpt-realtime"}}

GA client, gpt-realtime-1.5

  1. python ga_client.py http://127.0.0.1:52670 gpt-realtime-1.5 sk-1234
  2. Output:
{"type": "session.created", "session": {"type": "realtime", "instructions": "Your knowledge cutoff is 2023-10. You are a helpful, witty, and friendly AI. Act like a human, but remember that you aren't a human and that you can't do human things in the real world. Your voice and personality should be warm and engaging, with a live
{"type": "session.updated", "session": {"type": "realtime", "instructions": "You are a voice agent. Keep answers short.", "model": "gpt-realtime-1.5", "output_modalities": ["audio"]}}

Beta-header client, gpt-realtime-1.5

  1. python beta_client.py http://127.0.0.1:52670 gpt-realtime-1.5 sk-1234
  2. Output:
{"type": "session.created", "session": {"instructions": "Your knowledge cutoff is 2023-10. You are a helpful, witty, and friendly AI. Act like a human, but remember that you aren't a human and that you can't do human things in the real world. Your voice and personality should be warm and engaging, with a lively and playful tone.
{"type": "session.updated", "session": {"instructions": "You are a voice agent. Keep answers short.", "modalities": ["text"], "model": "gpt-realtime-1.5"}}

Health probe (GET /health, every deployment in mode: realtime)

  1. curl -s http://127.0.0.1:52670/health -H 'Authorization: Bearer sk-1234' | jq '{healthy_endpoints: [.healthy_endpoints[]? | {model, api_base}], unhealthy_endpoints: [.unhealthy_endpoints[]? | {model, api_base, error: (.error // "" | split("\n")[0])}]}'
  2. Output (the unpinned echo entry now dials the GA upstream, the realtime_protocol: beta one keeps the beta upstream, and the real deployments stay healthy):
{
  "healthy_endpoints": [
    {
      "model": "azure/gpt-realtime",
      "api_base": "https://<resource>.cognitiveservices.azure.com"
    },
    {
      "model": "azure/gpt-realtime-1.5",
      "api_base": "https://<resource>.cognitiveservices.azure.com"
    }
  ],
  "unhealthy_endpoints": [
    {
      "model": "azure/gpt-realtime",
      "api_base": "http://127.0.0.1:39098",
      "error": "http://127.0.0.1:39098/openai/v1/realtime?model=gpt-realtime isn't a valid URI: scheme isn't ws or wss"
    },
    {
      "model": "azure/gpt-realtime",
      "api_base": "http://127.0.0.1:39098",
      "error": "http://127.0.0.1:39098/openai/realtime?api-version=2024-10-01-preview&deployment=gpt-realtime isn't a valid URI: scheme isn't ws or wss"
    }
  ]
}

QA observations:

  • Azure's beta endpoint accepts deployment=gpt-realtime, so beta clients worked before and after
  • /health/test_connection in realtime mode picks the same upstream as /health
  • Both real deployments answered the GA and the beta probe handshake
  • Beta-era gpt-4o-realtime-preview deployments are deprecated on Azure, not exercised live

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • Azure clients that send a beta-shaped session.update without the OpenAI-Beta header now get the GA upstream
    • the proxy remaps the session fields to GA and returns GA event names, which such a client may not expect
    • opt back in with realtime_protocol: beta in litellm_params or LITELLM_AZURE_REALTIME_PROTOCOL=beta

Low

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
  • 4a3950c passes /live-pr-risk
  • 105dc77 passes /live-pr-risk

Azure realtime defaulted to the beta upstream whenever realtime_protocol
was not configured, so a GA client's session.update (session.type,
output_modalities, nested audio) was forwarded unchanged to
/openai/realtime and Azure rejected it with "Unknown parameter:
'session.type'" on gpt-realtime and gpt-realtime-1.5. The unset default
now follows the client the way the OpenAI handler already does: a client
that sends OpenAI-Beta: realtime=v1 keeps the beta upstream, any other
client gets /openai/v1/realtime. An explicit realtime_protocol in
litellm_params or LITELLM_AZURE_REALTIME_PROTOCOL still wins.
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@codspeed

codspeed Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_azure_realtime_ga_default (105dc77) with litellm_internal_staging (e72d1cf)

Open in CodSpeed

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@greptile-apps

greptile-apps Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates Azure realtime routing so unconfigured connections follow the client protocol while preserving explicit configuration precedence.

  • Headerless and transcription clients use Azure’s GA realtime upstream.
  • Clients sending OpenAI-Beta: realtime=v1 continue using the beta upstream.
  • Explicit deployment, request, and environment protocol settings still take precedence.
  • Azure health checks now default to the GA upstream, addressing the previously reported mismatch.
  • Tests cover GA and beta routing plus deployment and environment overrides.

Confidence Score: 5/5

The PR appears safe to merge, with no outstanding correctness or repository-rule findings.

The client-aware routing preserves explicit protocol overrides and beta-header compatibility while sending headerless clients and unconfigured health checks to Azure’s GA upstream. The previous health-check mismatch thread was manually resolved without explanation, and the current code also addresses its reported behavior.

Important Files Changed

Filename Overview
litellm/litellm_core_utils/realtime_streaming.py Exposes the scoped WebSocket protocol and existing beta-header detector for reuse by Azure routing.
litellm/llms/azure/realtime/handler.py Centralizes Azure realtime protocol selection based on explicit configuration, transcription intent, and the client compatibility header.
litellm/realtime_api/main.py Uses client-aware protocol selection for live connections and defaults unconfigured health checks to the matching GA upstream.
tests/test_litellm/realtime_api/test_main.py Verifies GA and beta client routing, explicit and environment overrides, health-check behavior, and Azure Foundry host handling.

Reviews (2): Last reviewed commit: "fix(realtime): probe Azure's GA realtime..." | Re-trigger Greptile

Comment thread litellm/realtime_api/main.py Resolved
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 105dc77. Configure here.

@mateo-berri
mateo-berri merged commit 44ce8bb into litellm_internal_staging Sep 12, 2026
85 of 86 checks passed
@mateo-berri
mateo-berri deleted the litellm_azure_realtime_ga_default branch September 12, 2026 01:34
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.

1 participant