@Mustan_lokhand hi - during the course of my troubleshooting, I wrote this smoke test to verify whether an api key will work or not.
With my old “AIza” it can create a fileSearch store, upload files, list, etc.
With a new api key, though, I can do everything, except upload files to the fileSearch store, which will fail with:
ApiError: {“error”:{“code”:500,“message”:“Internal error encountered.”,“status”:“INTERNAL”}}
I’ve verified the new api key has an API restriction “Gemini Api”, and a bound account.
In my https://aistudio.google.com/usage I see a message “Project “[redacted]” has been downgraded Suspicious activity was detected on your project. Secure your credentials.”
It was Tier 3, now is Tier 1, but this message appeared in the last few hours, after I posted in this thread.
import dotenv from 'dotenv';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { GoogleGenAI } from '@google/genai';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = path.resolve(__dirname, '..');
dotenv.config({ path: path.join(rootDir, '.env.server.local') });
dotenv.config({ path: path.join(rootDir, '.env.local') });
dotenv.config();
const apiKey = process.env.GEMINI_API_KEY || process.env.VITE_GEMINI_API_KEY;
if (!apiKey) {
throw new Error('Missing GEMINI_API_KEY or VITE_GEMINI_API_KEY.');
}
const ai = new GoogleGenAI({ apiKey });
const csvPath = createSampleCsv();
console.log('Creating File Search Store...');
const store = await ai.fileSearchStores.create({
config: {
displayName: `smoke-test-${Date.now()}`
}
});
const storeName = normalizeStoreName(store.name);
if (!storeName) {
throw new Error('Gemini created a File Search Store without a resource name.');
}
console.log('Created File Search Store');
console.log(JSON.stringify({
storeName,
displayName: store.displayName,
csvPath,
csvSizeBytes: fs.statSync(csvPath).size
}, null, 2));
console.log('Uploading CSV to File Search Store...');
let operation: any = await ai.fileSearchStores.uploadToFileSearchStore({
fileSearchStoreName: storeName,
file: csvPath,
config: {
displayName: path.basename(csvPath),
mimeType: 'text/plain'
}
});
while (!operation.done) {
console.log(JSON.stringify({
operationName: operation.name,
done: operation.done
}, null, 2));
await new Promise((resolve) => setTimeout(resolve, 2000));
operation = await ai.operations.get({ operation });
}
const documentName = operation?.result?.documentName
|| operation?.response?.documentName
|| operation?.metadata?.documentName;
console.log('Upload operation completed');
console.log(JSON.stringify({
operationName: operation.name,
done: operation.done,
documentName,
error: operation.error
}, null, 2));
console.log('Listing File Search Store documents...');
const documents = await ai.fileSearchStores.documents.list({
parent: storeName,
config: { pageSize: 10 }
});
const listedDocuments = [];
for await (const document of documents) {
listedDocuments.push(document);
}
console.log(JSON.stringify(listedDocuments, null, 2));
function createSampleCsv(): string {
const smokeDir = path.join(rootDir, 'uploads', 'file-search-smoke-test');
const filePath = path.join(smokeDir, 'sample-file-search-upload.csv');
fs.mkdirSync(smokeDir, { recursive: true });
fs.writeFileSync(
filePath,
[
'item,category,answer',
'check_in,front_desk,Check-in starts at 3 PM.',
'breakfast,dining,Breakfast is served from 7 AM to 10 AM.',
'parking,arrival,Valet parking is available at the main entrance.'
].join('\n'),
'utf8'
);
return filePath;
}
function normalizeStoreName(value?: string): string {
const storeName = value?.trim() || '';
if (!storeName) {
return '';
}
return storeName.startsWith('fileSearchStores/')
? storeName
: `fileSearchStores/${storeName}`;
}
Packages
"dependencies": {
"@google-cloud/storage": "^7.16.0",
"@google/genai": "2.7.0",
...
}
Thanks!