Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/adapters/openai-responses-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const TRAILING_V1 = /\/v1\/?$/;
* Custom `responsesPath` stays on the adapter; this helper is only the legacy /v1/responses branch.
*/
export function openaiResponsesUrl(baseUrl: string): string {
const trimmed = baseUrl.trim().replace(TRAILING_SLASHES, "");
const withoutEndpoint = trimmed.replace(TRAILING_RESPONSES, "");
const url = new URL(baseUrl.trim());
const trimmedPath = url.pathname.replace(TRAILING_SLASHES, "");
const withoutEndpoint = trimmedPath.replace(TRAILING_RESPONSES, "");
const withoutV1 = withoutEndpoint.replace(TRAILING_V1, "");
return `${withoutV1}/v1/responses`;
url.pathname = `${withoutV1}/v1/responses`;
return url.toString();
}
1 change: 1 addition & 0 deletions tests/openai-responses-passthrough.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ describe("OpenAI Responses key-auth URL construction", () => {
["https://api.openai.example/v1/", "https://api.openai.example/v1/responses"],
["https://api.openai.example/v1/responses", "https://api.openai.example/v1/responses"],
["https://api.openai.example/v1/responses/", "https://api.openai.example/v1/responses"],
["https://responses", "https://responses/v1/responses"],
] as const) {
expect(buildKeyAuthUrl(baseUrl)).toBe(expectedUrl);
}
Expand Down
Loading