Skip to content

Commit 8f697ad

Browse files
0xslineclaude
andcommitted
fix(agents): prevent /v1beta duplication in Gemini PDF URL
Strip trailing /v1beta from baseUrl before appending the version segment, so callers that already include /v1beta in their base URL (e.g. subagent-registry) no longer produce /v1beta/v1beta/models/… which results in a 404 from the Gemini API. Closes #34312 Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent ef4fa43 commit 8f697ad

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/agents/tools/pdf-native-providers.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,9 @@ export async function geminiAnalyzePdf(params: {
137137
}
138138
parts.push({ text: params.prompt });
139139

140-
const baseUrl = (params.baseUrl ?? "https://generativelanguage.googleapis.com").replace(
141-
/\/+$/,
142-
"",
143-
);
140+
const baseUrl = (params.baseUrl ?? "https://generativelanguage.googleapis.com")
141+
.replace(/\/+$/, "")
142+
.replace(/\/v1beta$/, "");
144143
const url = `${baseUrl}/v1beta/models/${encodeURIComponent(params.modelId)}:generateContent?key=${encodeURIComponent(apiKey)}`;
145144

146145
const res = await fetch(url, {

src/agents/tools/pdf-tool.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,26 @@ describe("native PDF provider API calls", () => {
711711
"apiKey required",
712712
);
713713
});
714+
715+
it("geminiAnalyzePdf does not duplicate /v1beta when baseUrl already includes it", async () => {
716+
const { geminiAnalyzePdf } = await import("./pdf-native-providers.js");
717+
const fetchMock = mockFetchResponse({
718+
ok: true,
719+
json: async () => ({
720+
candidates: [{ content: { parts: [{ text: "ok" }] } }],
721+
}),
722+
});
723+
724+
await geminiAnalyzePdf(
725+
makeGeminiAnalyzeParams({
726+
baseUrl: "https://generativelanguage.googleapis.com/v1beta",
727+
}),
728+
);
729+
730+
const [url] = fetchMock.mock.calls[0];
731+
expect(url).toContain("/v1beta/models/");
732+
expect(url).not.toContain("/v1beta/v1beta");
733+
});
714734
});
715735

716736
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)