Skip to content

fix(stt): append api-version for Azure OpenAI Whisper endpoint#217

Open
wwenrr wants to merge 3 commits intodaggerhashimoto:masterfrom
wwenrr:fix/issue-171-azure-whisper-api-version
Open

fix(stt): append api-version for Azure OpenAI Whisper endpoint#217
wwenrr wants to merge 3 commits intodaggerhashimoto:masterfrom
wwenrr:fix/issue-171-azure-whisper-api-version

Conversation

@wwenrr
Copy link
Copy Markdown

@wwenrr wwenrr commented Apr 1, 2026

Summary

Fixes Azure OpenAI Whisper transcription failures by appending api-version when configured.

What changed

  • Added openaiApiVersion config value from env:
    • OPENAI_API_VERSION
    • AZURE_OPENAI_API_VERSION (fallback alias)
  • Updated server/services/openai-whisper.ts to build request URL dynamically:
    • uses existing OPENAI_WHISPER_URL by default
    • appends ?api-version=<value> when version env is set
    • preserves existing api-version if already present in URL
  • Added focused tests in server/services/openai-whisper.test.ts for all three URL behaviors.

Verification

  • npx vitest run server/services/openai-whisper.test.ts server/routes/transcribe.test.ts
  • npm run build:server

Fixes #171

Summary by CodeRabbit

  • New Features

    • Server configuration now supports specifying an OpenAI API version.
    • Whisper transcription requests respect the configured API version and preserve existing URL parameters when present.
  • Tests

    • Added test coverage for API-version handling in transcription request URLs.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b5325f74-297c-4464-a2c1-ebeb6710fbd7

📥 Commits

Reviewing files that changed from the base of the PR and between d282e03 and 1d5c1b9.

📒 Files selected for processing (1)
  • server/services/openai-whisper.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/services/openai-whisper.test.ts

📝 Walkthrough

Walkthrough

Adds openaiApiVersion to server config and updates Whisper transcription URL construction to append an api-version query parameter when configured; includes tests covering URL-building behavior for empty, set, existing, and whitespace-only version values.

Changes

Cohort / File(s) Summary
Configuration
server/lib/config.ts
Exported openaiApiVersion: string on config, sourced from process.env.OPENAI_API_VERSION or process.env.AZURE_OPENAI_API_VERSION, defaulting to empty string.
OpenAI Whisper Implementation
server/services/openai-whisper.ts
Added non-exported getWhisperUrl() to conditionally inject api-version into OPENAI_WHISPER_URL (trims config.openaiApiVersion); transcribe() now calls this helper.
Tests
server/services/openai-whisper.test.ts
New Vitest suite verifying URL construction and fetch invocation across four scenarios: no version, version set, URL already contains api-version, and whitespace-only version. Stubs fetch and mocks config/constants.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through config, keen and spry,
To tuck an api-version in the sky,
URLs stitched with careful art,
No more 404s to break the heart,
Whisper sings, and I do a happy hop 🎵

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(stt): append api-version for Azure OpenAI Whisper endpoint' accurately summarizes the primary change - adding api-version parameter support for Azure OpenAI.
Description check ✅ Passed The description covers the main changes, references the linked issue, and includes verification steps. While not using the exact template format, all essential information is present and well-organized.
Linked Issues check ✅ Passed The PR fully addresses issue #171 by introducing environment variable support (OPENAI_API_VERSION/AZURE_OPENAI_API_VERSION), implementing dynamic URL building with api-version appending, and preserving existing api-version parameters.
Out of Scope Changes check ✅ Passed All changes are scoped to the linked issue requirements: config field addition, URL building logic, and comprehensive test coverage for the feature.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
server/services/openai-whisper.test.ts (1)

14-82: Good test coverage for the three URL construction scenarios.

The tests correctly verify:

  1. Base URL unchanged when no API version configured
  2. api-version query param appended when configured
  3. Existing api-version in URL is preserved (not overwritten)

Consider adding a test for whitespace-only openaiApiVersion (e.g., ' ') to verify the .trim() behavior works as expected, ensuring it falls back to the base URL.

💡 Optional: Add edge case test for whitespace-only API version
it('uses base whisper URL when API version is whitespace-only', async () => {
  vi.doMock('../lib/config.js', () => ({
    config: { openaiApiKey: 'sk-test', openaiApiVersion: '   ', language: 'en' },
  }));

  vi.doMock('../lib/constants.js', () => ({
    OPENAI_WHISPER_URL: 'https://api.openai.com/v1/audio/transcriptions',
  }));

  vi.mocked(fetch).mockResolvedValue(
    new Response(JSON.stringify({ text: 'ok' }), { status: 200 }),
  );

  const { transcribe } = await import('./openai-whisper.js');
  await transcribe(Buffer.from('abc'), 'sample.webm');

  expect(fetch).toHaveBeenCalledWith(
    'https://api.openai.com/v1/audio/transcriptions',
    expect.objectContaining({ method: 'POST' }),
  );
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/services/openai-whisper.test.ts` around lines 14 - 82, Add a test in
openai-whisper.test.ts that mocks config.config.openaiApiVersion to a
whitespace-only string (e.g., '   '), mocks OPENAI_WHISPER_URL to the base URL,
stubs fetch to return a successful Response, imports transcribe from
./openai-whisper.js, calls transcribe(Buffer.from('abc'), 'sample.webm'), and
asserts fetch was called with the base OPENAI_WHISPER_URL (no ?api-version
appended); reference the transcribe function, config.openaiApiVersion, and
OPENAI_WHISPER_URL when locating where to add the new test and reuse the
existing fetch mock setup/assertion pattern from the other tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/services/openai-whisper.test.ts`:
- Around line 14-82: Add a test in openai-whisper.test.ts that mocks
config.config.openaiApiVersion to a whitespace-only string (e.g., '   '), mocks
OPENAI_WHISPER_URL to the base URL, stubs fetch to return a successful Response,
imports transcribe from ./openai-whisper.js, calls
transcribe(Buffer.from('abc'), 'sample.webm'), and asserts fetch was called with
the base OPENAI_WHISPER_URL (no ?api-version appended); reference the transcribe
function, config.openaiApiVersion, and OPENAI_WHISPER_URL when locating where to
add the new test and reuse the existing fetch mock setup/assertion pattern from
the other tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: df4de8c7-b586-410f-984f-6712a9383a68

📥 Commits

Reviewing files that changed from the base of the PR and between fed3ab1 and d282e03.

📒 Files selected for processing (3)
  • server/lib/config.ts
  • server/services/openai-whisper.test.ts
  • server/services/openai-whisper.ts

@wwenrr
Copy link
Copy Markdown
Author

wwenrr commented Apr 1, 2026

Addressed the CodeRabbit suggestion ✅\n\nAdded a new test case for whitespace-only API version config:\n- now verifies we keep the base \n- Ensures no is appended when the configured value trims to empty\n\nPushed in commit: \n\nNote: I couldn't run the local test command in this environment because isn't installed here, but the test follows the existing test harness/mocking pattern in this file.

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.

[Bug] STT: Azure OpenAI (Whisper) transcription returns 404 due to missing api-version

1 participant