Skip to content

Backport: feat(provider/openai): allow configuring base URL via OPENAI_BASE_URL#9052

Merged
gr2m merged 1 commit intorelease-v5.0from
backport-pr-8990-to-release-v5.0
Sep 30, 2025
Merged

Backport: feat(provider/openai): allow configuring base URL via OPENAI_BASE_URL#9052
gr2m merged 1 commit intorelease-v5.0from
backport-pr-8990-to-release-v5.0

Conversation

@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

@vercel-ai-sdk vercel-ai-sdk bot commented Sep 30, 2025

This is an automated backport of #8990 to the release-v5.0 branch.

…#8990)

## Background

Some deployments need to target an OpenAI-compatible endpoint (e.g.
self-hosted proxy, regional gateway). The OpenAI provider currently
hardcodes the API base URL, which makes this inconvenient.

## Summary

- Add support for configuring the API base URL via the `OPENAI_BASE_URL`
environment variable and the `baseURL` option on the provider.
- Continue to default to `https://api.openai.com/v1` when not provided.
- Applies consistently across chat, completion, responses, embeddings,
image, transcription, and speech models.

## Manual Verification

- Set `OPENAI_BASE_URL` to a custom endpoint (e.g.
`https://api.openai-proxy.example/v1`).
- Initialize via `createOpenAI()` and call `openai.responses(/* modelId
*/)`; requests target the configured host.
- Unset the env var and omit `baseURL`; requests fall back to
`https://api.openai.com/v1`.
- Also verified that an explicit `baseURL` option takes precedence over
the env var.

## Related Issues

Fixes #8564

---------

Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
Comment on lines +1 to +3
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { createOpenAI } from './openai-provider';
import { afterEach } from 'node:test';
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.

Suggested change
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { createOpenAI } from './openai-provider';
import { afterEach } from 'node:test';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { createOpenAI } from './openai-provider';

The afterEach import is from 'node:test' instead of 'vitest', which is inconsistent with the rest of the test utilities and could cause test execution issues.

View Details

Analysis

Incompatible test framework imports: afterEach from node:test doesn't execute in vitest

What fails: In packages/openai/src/openai-provider.test.ts, the afterEach hook imported from 'node:test' (line 3) does not execute when running tests with vitest, causing test cleanup to be skipped

How to reproduce:

# Create test demonstrating the issue:
cat > test-demo.test.ts << 'EOF'
import { afterEach } from 'node:test';
import { describe, it, expect, beforeEach } from 'vitest';

let counter = 0;

describe('Test', () => {
  beforeEach(() => { /* setup */ });
  
  afterEach(() => { counter++; });

  it('test 1', () => { expect(counter).toBe(0); });
  it('test 2', () => { expect(counter).toBe(1); }); // FAILS - counter is still 0
});
EOF

npx vitest run test-demo.test.ts

Result: Test 2 fails with expected +0 to be 1 because the afterEach from node:test never executes. Additionally, "TAP version 13" appears in test output, indicating Node.js test runner interference.

Expected: The afterEach hook should execute after each test, incrementing the counter. Using vitest's afterEach makes all tests pass.

Root cause: Node.js's node:test module provides a test runner API that is incompatible with vitest. While the import succeeds without error, the hooks are not registered with vitest's test runner and therefore never execute. This is documented in Vitest's API reference which specifies that test lifecycle hooks must be imported from 'vitest'.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

oops will fix in follow up pr

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

also: now you are telling me?!

@gr2m gr2m merged commit 110c735 into release-v5.0 Sep 30, 2025
12 checks passed
@gr2m gr2m deleted the backport-pr-8990-to-release-v5.0 branch September 30, 2025 03:02
@gr2m gr2m added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/openai Issues related to the @ai-sdk/openai provider labels Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/openai Issues related to the @ai-sdk/openai provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants