Backport: feat(provider/openai): allow configuring base URL via OPENAI_BASE_URL#9052
Conversation
…#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>
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { createOpenAI } from './openai-provider'; | ||
| import { afterEach } from 'node:test'; |
There was a problem hiding this comment.
| 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.tsResult: 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'.
There was a problem hiding this comment.
oops will fix in follow up pr
There was a problem hiding this comment.
also: now you are telling me?!
This is an automated backport of #8990 to the release-v5.0 branch.