# 400 Error "Request contains an invalid argument" when calling v1beta/openai/chat/completions from AI Studio Build Environment

**URL:** <https://discuss.ai.google.dev/t/400-error-request-contains-an-invalid-argument-when-calling-v1beta-openai-chat-completions-from-ai-studio-build-environment/95759>\
**Category:** Google AI Studio\
**Tags:** issues, build-with-ai, openai\_compatibility, ai-studio, bug\
**Created:** [July 27, 2025, 5:34pm UTC](https://discuss.ai.google.dev/t/400-error-request-contains-an-invalid-argument-when-calling-v1beta-openai-chat-completions-from-ai-studio-build-environment/95759 "2025-07-27T17:34:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ystone](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ystone/32/57363_2.png) [@Ystone](https://discuss.ai.google.dev/u/Ystone)\
**Post date:** [July 27, 2025, 5:34pm UTC](https://discuss.ai.google.dev/t/400-error-request-contains-an-invalid-argument-when-calling-v1beta-openai-chat-completions-from-ai-studio-build-environment/95759/1 "2025-07-27T17:34:23Z")

</div>

Hello everyone,

I’m encountering an issue when trying to use the OpenAI-compatible Chat Completions endpoint from within the AI Studio Build environment.

**Objective:**  
My goal is to call the v1beta/openai/chat/completions endpoint using the OpenAI SDK from a client-side application running in the AI Studio’s “Build with Gemini” environment.

**Steps to Reproduce:**  
I am using the openai npm package, configured to point to the Google Generative Language API base URL. Here is the code snippet I am running (Actually it is the example code):

```auto
import {marked} from 'marked';
import OpenAI from 'openai';

const GEMINI_API_KEY = process.env.GEMINI_API_KEY;

async function debug(...args: string[]) {
  const turn = document.createElement('div');
  const promises = args.map(async (arg) => await marked.parse(arg ?? ''));
  const strings = await Promise.all(promises);
  turn.innerHTML = strings.join('');
  document.body.append(turn);
}

const openai = new OpenAI({
  apiKey: GEMINI_API_KEY,
  baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
  dangerouslyAllowBrowser: true,
});

const response = await openai.chat.completions.create({
  model: 'models/gemini-2.5-flash',
  messages: [
    {role: 'system', content: 'You are a helpful assistant.'},
    {
      role: 'user',
      content: 'Explain to me how AI works',
    },
  ],
});

debug(response.choices[0].message.content);

```

**Expected Result:**  
The request should succeed with an HTTP 200 status code, returning a valid JSON response containing the AI-generated chat message.

**Actual Result:**  
The request fails with an **HTTP 400 (Bad Request)** error.

When inspecting the network request in the browser’s developer console (F12), the raw response body is:

```auto
[,[3,"Request contains an invalid argument."]]

```

**Additional Context:**

1. This issue appears to be specific to the **AI Studio Build environment**.

2. 
  1. It also appears that the failing request is routed through a different endpoint than successful ones. The failing request goes to `https://alkalimakersuite-pa.clients6.google.com/$rpc/google.internal.alkali.applications.makersuite.v1.MakerSuiteService/ProxyStreamedCall`, whereas successful requests go to `https://alkalimakersuite-pa.clients6.google.com/$rpc/google.internal.alkali.applications.makersuite.v1.MakerSuiteService/ProxyUnaryCall`.

3. This leads me to believe the issue might be related to how requests from this specific endpoint are processed or proxied within the AI Studio environment.

Has anyone else in the community experienced this? Is this a known issue, or does anyone have suggestions for a potential workaround?

Any help or insight would be greatly appreciated.

Thank you

---

<div class="post-metadata">

**Author:** ![Ystone](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ystone/32/57363_2.png) [@Ystone](https://discuss.ai.google.dev/u/Ystone)\
**Post date:** [July 27, 2025, 5:53pm UTC](https://discuss.ai.google.dev/t/400-error-request-contains-an-invalid-argument-when-calling-v1beta-openai-chat-completions-from-ai-studio-build-environment/95759/2 "2025-07-27T17:53:09Z")

</div>

@Lalit_Kumar @Mrinal_Ghosh @Govind_Keshari @GUNAND_MAYANGLAMBAM  
Sorry for tagging directly here, but I’ve been stuck on this issue for over a week. Do you have any insights?

---

<div class="post-metadata">

**Author:** ![Ystone](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ystone/32/57363_2.png) [@Ystone](https://discuss.ai.google.dev/u/Ystone)\
**Post date:** [July 29, 2025, 6:19am UTC](https://discuss.ai.google.dev/t/400-error-request-contains-an-invalid-argument-when-calling-v1beta-openai-chat-completions-from-ai-studio-build-environment/95759/4 "2025-07-29T06:19:33Z")

</div>

@Lalit_Kumar @Krish_Varnakavi1 @Mrinal_Ghosh Do you have any insights on this? It’s really strange.

---

<div class="post-metadata">

**Author:** ![Mrinal\_Ghosh](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mrinal_ghosh/32/32599_2.png) [@Mrinal\_Ghosh](https://discuss.ai.google.dev/u/Mrinal_Ghosh)\
**Post date:** [July 29, 2025, 6:24am UTC](https://discuss.ai.google.dev/t/400-error-request-contains-an-invalid-argument-when-calling-v1beta-openai-chat-completions-from-ai-studio-build-environment/95759/5 "2025-07-29T06:24:31Z")

</div>

Hi @Ystone ,

Our internal team is reviewing your issue, we will update you soon.

Thank you!

---

<div class="post-metadata">

**Author:** ![Ystone](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ystone/32/57363_2.png) [@Ystone](https://discuss.ai.google.dev/u/Ystone)\
**Post date:** [July 29, 2025, 6:29am UTC](https://discuss.ai.google.dev/t/400-error-request-contains-an-invalid-argument-when-calling-v1beta-openai-chat-completions-from-ai-studio-build-environment/95759/6 "2025-07-29T06:29:06Z")

</div>

Thanks man. This bug is consistently reproducible – really appreciate everything your team’s done.

---

<div class="post-metadata">

**Author:** ![Sivasankaran\_R](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sivasankaran_r/32/56643_2.png) [@Sivasankaran\_R](https://discuss.ai.google.dev/u/Sivasankaran_R)\
**Post date:** [July 29, 2025, 7:05pm UTC](https://discuss.ai.google.dev/t/400-error-request-contains-an-invalid-argument-when-calling-v1beta-openai-chat-completions-from-ai-studio-build-environment/95759/7 "2025-07-29T19:05:42Z")

</div>

Hi @Ystone I have tested the code on my side and it’s working fine. I have shared the code—please check on your side

```auto
import OpenAI from "openai";
import "dotenv/config";

const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
if (!GEMINI_API_KEY) throw new Error("Missing GEMINI_API_KEY");

const openai = new OpenAI({
    apiKey: GEMINI_API_KEY,
    baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/"
});

const response = await openai.chat.completions.create({
    model: "gemini-2.5-flash",
    messages: [
        { role: "system", content: "You are a helpful assistant." },
        {
            role: "user",
            content: "Explain to me how AI works",
        },
    ],
});

console.log(response.choices[0].message.content);

```

 ![image](https://d3qe71uytubmmx.cloudfront.net/original/3X/f/8/f8aa67c1ac125be8cb70878410a162ad4f98e3f3.png)

---

<div class="post-metadata">

**Author:** ![Ystone](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ystone/32/57363_2.png) [@Ystone](https://discuss.ai.google.dev/u/Ystone)\
**Post date:** [July 29, 2025, 7:36pm UTC](https://discuss.ai.google.dev/t/400-error-request-contains-an-invalid-argument-when-calling-v1beta-openai-chat-completions-from-ai-studio-build-environment/95759/8 "2025-07-29T19:36:08Z")

</div>

Where are you running this code? Is it in AI Studio Build? I tried executing your code snippet but still encountered the same error

 ![image](https://d3qe71uytubmmx.cloudfront.net/original/3X/4/9/491148ec0c630e7a14161c82d4817296bbc681ed.jpeg)

 ![image](https://d3qe71uytubmmx.cloudfront.net/original/3X/0/4/04fceddbd451ac8be6b642d747db22a31222bf56.png)

 ![image](https://d3qe71uytubmmx.cloudfront.net/original/3X/0/b/0b7c64829e81bfadbd8ad03bdebf8d98c3b3202e.png)

 ![image](https://d3qe71uytubmmx.cloudfront.net/original/3X/d/1/d1b900ec14e7e2f2b22c14531ad5f50b3ca6e9df.png)

@Sivasankaran_R

---

<div class="post-metadata">

**Author:** ![Ystone](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ystone/32/57363_2.png) [@Ystone](https://discuss.ai.google.dev/u/Ystone)\
**Post date:** [July 29, 2025, 7:39pm UTC](https://discuss.ai.google.dev/t/400-error-request-contains-an-invalid-argument-when-calling-v1beta-openai-chat-completions-from-ai-studio-build-environment/95759/9 "2025-07-29T19:39:01Z")

</div>

As mentioned in my post, this bug only occurs in the AI Studio Build environment. Maybe try running the code in AI Studio Build - you should be able to reproduce the error quickly. By the way, based on my observation, it seems the issue lies with "  
[https://alkalimakersuite-pa.clients6.google.com/$rpc/google.internal.alkali.applications.makersuite.v1.MakerSuiteService/ProxyStreamedCall](https://alkalimakersuite-pa.clients6.google.com/$rpc/google.internal.alkali.applications.makersuite.v1.MakerSuiteService/ProxyStreamedCall)" endpoint @Sivasankaran_R
