You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I started getting this error since yesterday's afternoon. Before that it was working fine. Do I need to change model or update some setting?
[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/cachedContents: [503 Service Unavailable] The service is currently unavailable.. The service may be experiencing high load or maintenance. Please try again later
Code example
import { google } from "@ai-sdk/google";
import {
GoogleAICacheManager,
GoogleAIFileManager,
} from "@google/generative-ai/server";
import { generateObject, generateText } from "ai";
const cacheManager = new GoogleAICacheManager(
process.env.GOOGLE_GENERATIVE_AI_API_KEY
);
const fileManager = new GoogleAIFileManager(
process.env.GOOGLE_GENERATIVE_AI_API_KEY
);
const { name: cachedContent } = await cacheManager.create({
model,
contents: [
{
role: "user",
parts: [
{
fileData: {
fileUri: uploadResult.file.uri,
mimeType: uploadResult.file.mimeType,
},
},
],
},
],
ttlSeconds: 60 * 60,
});
if (!cachedContent) {
throw new Error("Failed to cache text - received empty response");
}
return cachedContent;
} catch (error: unknown) {
// Type guard for Error objects
if (!(error instanceof Error)) {
throw new Error("An unknown error occurred");
}
lastError = error;
// Check if it's a 503 error
if (error.message.includes("503 Service Unavailable")) {
console.warn(
`Attempt ${attempt + 1}/${maxRetries} failed with 503 error`
);
// If we haven't exhausted all retries, wait and try again
if (attempt < maxRetries - 1) {
const delay = baseDelay * Math.pow(2, attempt); // Exponential backoff
console.log(`Retrying in ${delay / 1000} seconds...`);
await new Promise((resolve) => setTimeout(resolve, delay));
continue;
}
} else {
// If it's not a 503 error, throw immediately
throw error;
}
}
}
// If we've exhausted all retries
throw new Error( Failed to cache text after ${maxRetries} attempts. Last error: ${lastError?.message}. + The service may be experiencing high load or maintenance. Please try again later.
);
}
AI provider
"@ai-sdk/google": "^1.1.8",
Additional context
This was working fine earlier. I used it at least 100 times. But then it started throwing this error. I checked my usage, everything was fine.
The text was updated successfully, but these errors were encountered:
Description
I started getting this error since yesterday's afternoon. Before that it was working fine. Do I need to change model or update some setting?
[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/cachedContents: [503 Service Unavailable] The service is currently unavailable.. The service may be experiencing high load or maintenance. Please try again later
Code example
import { google } from "@ai-sdk/google";
import {
GoogleAICacheManager,
GoogleAIFileManager,
} from "@google/generative-ai/server";
import { generateObject, generateText } from "ai";
const cacheManager = new GoogleAICacheManager(
process.env.GOOGLE_GENERATIVE_AI_API_KEY
);
const fileManager = new GoogleAIFileManager(
process.env.GOOGLE_GENERATIVE_AI_API_KEY
);
const model: GoogleModelCacheableId = "models/gemini-1.5-flash-001";
export async function createCacheableText(sourceUrl: string): Promise {
const maxRetries = 3;
const baseDelay = 1000; // 1 second
let lastError: Error | null = null;
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
const uploadResult = await fileManager.uploadFile(sourceUrl, {
mimeType: "application/pdf",
});
}
// If we've exhausted all retries
throw new Error(
Failed to cache text after ${maxRetries} attempts. Last error: ${lastError?.message}.
+The service may be experiencing high load or maintenance. Please try again later.
);
}
AI provider
"@ai-sdk/google": "^1.1.8",
Additional context
This was working fine earlier. I used it at least 100 times. But then it started throwing this error. I checked my usage, everything was fine.
The text was updated successfully, but these errors were encountered: