New AQ. API Keys Failing to upload to file search store

Using google.golang.org/genai v1.49.0 client with a new AQ. prefixed api key the call to upload a file to file search store consistently fails.

client, err := genai.NewClient(ctx, &genai.ClientConfig{

    APIKey:  os.Getenv("GEMINI_API_KEY"),

    Backend: genai.BackendGeminiAPI,

  })

store, err := client.FileSearchStores.Create(ctx,
  &genai.CreateFileSearchStoreConfig{DisplayName: "My File Search Store"})

  op, err := client.FileSearchStores.UploadToFileSearchStoreFromPath(ctx, "~/path/to/file.pdf", store.Name, nil)

With this error: response body is invalid for chunk at offset 0: Error 500, Message: Internal error encountered., Status: INTERNAL, Details: []

I’ve switched to a free tier api key on a different project and the same upload code works as expected.

You need to create or just ask Gemini at the url gemini.google.com and input that value in place of the key.
Sorry for the confusion.

Hi

We are working on address the issue with AQ. prefix keys, You can create a new key(Non AQ.prefix) via AI Studio to unblock to your workflow.

@Mustan_lokhand I can’t create ApiKeys other than AQ. prefix, in all projects I have. I’m assuming that, because my apiKeys has been leaked, Google has flagged my accounts and it will no longer generate AIza prefix keys. The biggest issue is that it can still use the AQ. apikey, but it will throw 500 when I try to upload files to FileSearch. The only workaround I have at the moment is to restore the leaked apikeys I had previously revoked.

Please advise - do you have any documentation that could come to rescue so AQ apikeys work?

Hi @FelipeDrumond

Taking a look into this

Can you share any sample code snippet with me ?

@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!

Thank you for sharing this

I was able to reproduce and we are working on fix for the same

Hey @Mustan_lokhand is there any ETA to this to be fixed?
I’m having the same issue, but in my case I lost access to my previous API key and now I’m left with only the new API key, that now is blocking any file upload operation

@fcmonje I recovered my revoked apikey - not sure you still have time to do that. However, that’s risky since it could have been compromised. Check https://console.cloud.google.com/apis/credentials/deleted?project=YOUR_PROJECT

@Mustan_lokhand what if I rotatef the key? Would that just change the secret value or update the apikey version from AIza to AQ? If it remains on AIza, that would be an alternative until this gets understood and fixed.

Unfortunatelly we cannot recover it anymore.
From what I was able to search, if key is rotated, it will generate new AQ key format.

Seems to me Gemini File Search is almost totally borked as far as ingestion goes. Spent I don’t know how many hours trying different things. It’s good to know it’s not just me.

I hope this will be fixed soon as I am effectively blocked.

2 days – what’s the status? I paid to use file search and now I’m unable to. My AQ keys simply don’t work. Can you share a blog post or something about this or send out comms to your users about how the keys are broken?

This has been a known issue since April?

I’m sorry, but what are you guys even doing? These keys are totally non-functional.

@Mustan_lokhand would be possible to give us some directions, or an estimate on when this issue would be fixed?

Hi
Wanted to share quick update

We have rolled out a fix and this should address the issue with file upload and file search

We are moving away from Traffic keys (Alza) and towards a more secure Authentication Key (AQ). AI Studio will now only generate Authentication Key (AQ) keys. More information on key usage can be found in the Using Gemini API keys documentation.

Please submit any compatibility issues with services / SDKs etc. in this form for our engineering team to review. Thanks!

The form asks for the API key in question but the bottom of the form says “Never submit passwords through Google Forms.”

I’m still facing this issue still as of 6/19/26 with the following method:

client.FileSearchStores.ImportFile(go sdk).

Everything else works just fine-- just not the import file method.

Is there any other way to get this resolved without submitting a private api key to a public google form?

Edit: It looks like it’s actually nothing to do with an authentication issue. I can upload pdf files just fine, but when I try to upload an excel file (mime type application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ), I get the following error:

Error 401, Message: The request does not have valid authentication credentials., Status: UNAUTHENTICATED, Details: []