Hello everyone,
I’m looking for help from people familiar with Google AI Studio Build, especially its Gemini API integration and server-side migration.
I’ve been using Google AI Studio Build to create a writing assistant for my novel. Over several months, I’ve developed and customized this app extensively. It contains approximately 515,000 words of conversation history and accumulated story context, including character information, plot analysis, continuity checks, writing feedback, and roleplay.
This is not just a disposable chatbot for me. I’ve invested a considerable amount of time developing its behavior and building up its context, so my biggest concern is preserving the existing app and its history rather than having to rebuild everything.
I’m going to describe two incidents separately because I’m not sure whether they share the same underlying cause.
1. Previous incident — September 2026
In September, my app suddenly became unable to send messages. Initially, I thought it might be a temporary service issue or a quota problem.
However, even after waiting for approximately three days, the app continued failing. I repeatedly encountered errors such as:
-
503 Service Unavailable -
Quota exceeded -
Messages indicating that the service was overloaded.
I also experienced problems with image and file uploads. Even an empty file could fail to upload.
At the time, someone named Harry Thành helped me troubleshoot the issue. He suggested trying a different API key and model.
I remember that I eventually selected Gemini Latest in the “Model in chat” selector and refreshed the page (F5). After doing this, I could send text messages again, even though I hadn’t entered any additional prompt or modified the app’s code.
I want to emphasize that I’m not certain whether changing the model, refreshing the page, or both caused the recovery. I also don’t know whether the model selected in “Model in chat” actually changed the model configured internally in my app.
The recovery was only partial at first:
-
Text messaging worked again.
-
Image and file uploads still failed.
-
Sometimes, deleting a broken conversation and starting a new one allowed me to interact with the app again.
-
After experimenting with prompts and the app’s handling of image/file requests, those features gradually started working again.
Eventually, the app became usable again.
I mention this incident because the current problem feels somewhat similar, particularly the repeated quota and service errors. However, I don’t know whether the two incidents are related.
2. Current incident — October 2026
Recently, Google AI Studio displayed the following warning:
This app uses a legacy Gemini API configuration that is no longer supported. Ask its owner to update it.
AI Studio suggested the following migration instruction:
Move all of this app’s Gemini API calls, including streaming and Live API, from the browser to the server so the app keeps working for everyone who opens it. Keep the app’s UI and behavior the same.
I followed this instruction.
After the migration, the app started producing several different errors:
-
429 Quota exceeded -
Stream request failed -
413 Request Entity Too Large -
414 Request-URI Too Large
The 413 and 414 errors are particularly concerning because eventually the chat interface appeared empty, and even sending a single character such as . resulted in a 414 error.
The 414 response appeared as an Nginx 1.22.1 error page.
I tried asking AI Studio Build to diagnose and repair the Gemini integration, streaming implementation, quota errors, and backend migration. I also tried reverting to the app version from before the migration, but the problem was not clearly resolved.
I created two new API keys and replaced the keys in Secrets one at a time. Neither attempt fixed the issue.
I also waited more than 24 hours.
Interestingly, other apps in my AI Studio account still work normally.
3. Current model and quota observations
The app currently appears to use Gemini 3.8 Flash in its configuration.
However, I remember that during the September incident, switching to Gemini Latest through the separate “Model in chat” selector and refreshing the page restored text messaging.
I have not yet established whether this selector affects the app’s internal model configuration or only the model used by the AI Studio chat interface.
My AI Studio Usage page also showed the following values when I checked:
-
Gemini 3.8 Flash:
-
RPM: 3 / 5
-
TPM: 132K / 250K
-
RPD: 7 / 20
-
-
Gemini 3.1 Flash Lite:
-
RPM: 2 / 15
-
TPM: 137.43K / 250K
-
RPD: 10 / 500
-
These displayed figures did not appear to have reached their respective limits, although I understand that other restrictions or limits may apply.
4. Relevant code snippets
After investigating the app’s code, I found the following frontend streaming function:
export async function* generateContentStream(params: any) {
const response = await fetch('/api/gemini/stream', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(params)
});
if (!response.ok) {
const errText = await response.text();
throw new Error(errText || 'Stream request failed');
}
const reader = response.body?.getReader();
if (!reader) throw new Error('Response body reader not available');
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split('\n');
buffer = lines.pop() || '';
for (const line of lines) {
if (line.startsWith('data: ')) {
const dataStr = line.slice(6).trim();
if (dataStr === '[DONE]') return;
try {
const parsed = JSON.parse(dataStr);
if (parsed.error) {
throw new Error(parsed.error);
}
yield parsed;
} catch (e: any) {
if (e.message && e.message !== "Unexpected end of JSON input") {
throw e;
}
}
}
}
}
}
The backend route I found looks like this:
app.post('/api/gemini/stream', async (req, res) => {
try {
const { params } = req.body;
const stream = await generateContentStream(params);
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
for await (const chunk of stream) {
res.write(`data: ${JSON.stringify(chunk)}\n\n`);
}
res.end();
} catch (error) {
console.error('Error streaming content:', error);
res.status(500).json({ error: 'Failed to stream content' });
}
});
One thing I noticed is that the frontend sends JSON.stringify(params) directly, while the backend extracts params from req.body. I don’t know whether this is intentional or a request-body mismatch.
I have not yet located the actual server-side function that performs the Gemini API call.
5. What I would like help understanding
I would really appreciate guidance on the following questions:
-
Could the previous recovery through selecting Gemini Latest in “Model in chat” and refreshing the page indicate a model-selection or session-state issue?
-
Could the current 413 and 414 errors be caused by the migration, a malformed request URL, or a proxy/server configuration problem?
-
Why would a 414 error occur even when the chat is empty and I send only a single character?
-
Could the request-body handling in the frontend and backend snippets above be incorrect?
-
Is it possible to diagnose or repair the current app without losing its existing conversation history and accumulated context?
-
Are there safe ways to back up the app’s source code, conversation history, and relevant stored data before attempting further changes?
I’m not an experienced backend developer, so I would appreciate step-by-step explanations rather than instructions that assume I already understand the server architecture.
My most important requirement is to preserve the existing app and its accumulated history. I would prefer not to reset, delete, or rebuild it unless there is absolutely no alternative.
Thank you very much for taking the time to read this. Any guidance would mean a lot to me.