🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: pass Google API key via x-goog-api-key header (#12506)
eronezd286c1a9ad38
diff --git a/packages/model-runtime/src/providers/google/index.test.ts b/packages/model-runtime/src/providers/google/index.test.tsindex 42d6b168f66..f0097a8317f 100644--- a/packages/model-runtime/src/providers/google/index.test.ts+++ b/packages/model-runtime/src/providers/google/index.test.ts@@ -679,3 +679,24 @@ describe('thinkingConfig includeThoughts logic', () => {expect(config.thinkingConfig?.thinkingLevel).toBe('high');});});++describe('models', () => {+ it('should pass API Key via x-goog-api-key header instead of URL parameter', async () => {+ const mockFetch = vi.fn().mockResolvedValue({+ json: () => Promise.resolve({ models: [] }),+ ok: true,+ });+ global.fetch = mockFetch;++ const apiKey = 'test-google-key';+ const localInstance = new LobeGoogleAI({ apiKey });++ await localInstance.models();+ const [url, options] = mockFetch.mock.calls[0];++ expect(url).not.toContain('key=');+ expect(options.headers).toMatchObject({+ 'x-goog-api-key': apiKey,+ });+ });+});\ No newline at end of filediff --git a/packages/model-runtime/src/providers/google/index.ts b/packages/model-runtime/src/providers/google/index.tsindex 64ec6ef3cf1..66e1ca1afda 100644--- a/packages/model-runtime/src/providers/google/index.ts+++ b/packages/model-runtime/src/providers/google/index.ts@@ -400,8 +400,11 @@ export class LobeGoogleAI implements LobeRuntimeAI {async models(options?: { signal?: AbortSignal }) {try {- const url = `${this.baseURL}/v1beta/models?key=${this.apiKey}`;+ const url = `${this.baseURL}/v1beta/models`;const response = await fetch(url, {+ headers: {+ 'x-goog-api-key': this.apiKey!,+ },method: 'GET',signal: options?.signal,});