TanStack AI version#
@tanstack/ai-gemini 1.2.0 (also 1.1.1). The last good version is 1.1.0. @tanstack/ai 1.2.0.
Framework/Library version#
Node.js 24.22.1, @google/genai 2.32.0 (what ^2.10.0 installs today). Server code, no UI framework.
Describe the bug and the steps to reproduce it#
With an apiKey, the Gemini adapters ignore httpOptions.fetch. Every request goes to the global fetch. Nothing throws, so requests silently skip a proxy, a Cloudflare binding, a data-residency egress, or a logging fetch.
@google/genai has httpOptions.fetch since 2.23.0. In 1.1.0 the adapter sends requests through it. In 1.1.1 and 1.2.0 it does not.
Steps:
- Run
npm i @tanstack/ai@1.2.0 @tanstack/ai-gemini@1.2.0 zod in an empty ES module project.
- Save the script below as
repro.mjs.
- Run
node repro.mjs (Node 24).
import { chat } from '@tanstack/ai'
import { createGeminiChat } from '@tanstack/ai-gemini'
globalThis.fetch = async (input) => {
throw new Error(`global fetch called for ${input}`)
}
let customFetchCalls = 0
const myFetch = async () => {
customFetchCalls++
const chunk = {
candidates: [
{ content: { role: 'model', parts: [{ text: 'hi' }] }, finishReason: 'STOP' },
],
}
return new Response(`data: ${JSON.stringify(chunk)}\n\n`, {
headers: { 'content-type': 'text/event-stream' },
})
}
const adapter = createGeminiChat('gemini-2.5-flash', 'fake-key', {
httpOptions: { fetch: myFetch },
})
async function main() {
let text = ''
let error
for await (const chunk of chat({
threadId: 'repro',
adapter,
messages: [{ role: 'user', content: 'Hi' }],
})) {
if (chunk.type === 'TEXT_MESSAGE_CONTENT') text += chunk.delta
if (chunk.type === 'RUN_ERROR') error = chunk.message
}
console.log(JSON.stringify({ text, customFetchCalls, error }))
}
main()
Expected (this is the 1.1.0 output):
{"text":"hi","customFetchCalls":1}
Actual on 1.1.1 and 1.2.0:
{"text":"","customFetchCalls":0,"error":"global fetch called for https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse"}
Where it comes from: #1973 (released in 1.1.1) replaced the SDK with a fetch client when the config has an apiKey. On main:
apiCall in packages/ai-gemini/src/client/api.ts calls the global fetch. It never reads httpOptions.fetch.
createInteractions in src/client/interactions.ts does not pass fetch to createHttpClient. So image generation (createGeminiImage) skips the custom fetch too.
Vertex AI and enterprise still go through the SDK and are not affected.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)#
https://stackblitz.com/github/kurochenko/tanstack-ai-gemini-fetch-repro
Run npm start. It is the script above. It needs no API key and makes no network call. To see 1.1.0 work, set @tanstack/ai-gemini to 1.1.0 in package.json and run npm install.
Do you intend to try to help solve this bug with your own PR?#
Yes, I am also opening a PR that solves the problem along side this issue
Terms & Code of Conduct#