Interactions API JavaScript SDK 403 error when running in browser. But raw fetch request works

Comparing the following two ways to call the new interactions API in the browser environment

// This works
async function viaFetch() {
  const response = await fetch("https://generativelanguage.googleapis.com/v1beta/interactions", {
    method: "OPTIONS",
    headers: {
      "x-goog-api-key": "...",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "gemini-3.5-flash",
      input: "How does AI work?",
    }),
  });

  const data = await response.json();
  console.log(data);
}

// This results in 403 error
async function viaSDK() {
  const ai = new GoogleGenAI({ apiKey: "..." });

  const interaction = await ai.interactions.create({
    model: "gemini-3.5-flash",
    input: "How does AI work?",
  });
  console.log(interaction.output_text);
}

The fetch API returns OK 200.

The SDK returns 403 forbidden error with the message Your client does not have permission to get URL /v1beta/interactions from this server.

Here is the minimum cURL reproduction

# Equivalent to fetch
curl 'https://generativelanguage.googleapis.com/v1beta/interactions' \
  -X 'OPTIONS' \
  -H 'accept: */*' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'access-control-request-headers: content-type,x-goog-api-key' \
  -H 'access-control-request-method: OPTIONS' \
  -H 'origin: http://localhost:5173' \
  -H 'priority: u=1, i' \
  -H 'referer: http://localhost:5173/' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: cross-site' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 Edg/149.0.0.0'

# Equivalent to SDK
curl 'https://generativelanguage.googleapis.com/v1beta/interactions' \
  -X 'OPTIONS' \
  -H 'accept: */*' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'access-control-request-headers: api-revision,content-type,x-goog-api-client,x-goog-api-key' \
  -H 'access-control-request-method: OPTIONS' \
  -H 'origin: http://localhost:5173' \
  -H 'priority: u=1, i' \
  -H 'referer: http://localhost:5173/' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: cross-site' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 Edg/149.0.0.0'


The SDK added the api-revision in the access-control-request-headers. Removing this value would fix the problem.

Given that the two methods are equivalent, I would expect both to work. I’d really hope to run the interactions API via the SDK in the browser for building demos and prototypes without relying on the backend proxy. This used to work flawlessly with the current sdk when not using the interactions api. But it has been broken since day 1 with the interactions API.

Hi hacker_yesterday, could you tell me which version of the SDK you’re using?

The JS SDK, latest (v2.10.0). There was identical issues in all the older versions of the SDK I’ve used. So it was probably not a regression but a bug that was never addressed.

Thanks Jon!

Hi @hacker_yesterday thanks for flagging this issue! This is a bug on the SDK. We will plan a patch later this week to fix this

Fix confirmed. Thank you for fast response.