@@ -34,6 +34,7 @@ import {
3434 ProviderEmbeddingResponse ,
3535} from '../IProvider' ;
3636import { GeminiProviderError } from '../errors/GeminiProviderError' ;
37+ import { ApiKeyPool } from '../../../providers/ApiKeyPool.js' ;
3738
3839// ---------------------------------------------------------------------------
3940// Configuration
@@ -259,6 +260,7 @@ export class GeminiProvider implements IProvider {
259260 public defaultModelId ?: string ;
260261
261262 private config ! : GeminiProviderConfig ;
263+ private keyPool : ApiKeyPool | null = null ;
262264
263265 constructor ( ) { }
264266
@@ -292,6 +294,7 @@ export class GeminiProvider implements IProvider {
292294 defaultModelId : 'gemini-2.5-flash' ,
293295 ...config ,
294296 } ;
297+ this . keyPool = new ApiKeyPool ( config . apiKey ) ;
295298 this . defaultModelId = this . config . defaultModelId ;
296299 this . isInitialized = true ;
297300
@@ -1082,7 +1085,7 @@ export class GeminiProvider implements IProvider {
10821085 body : Record < string , unknown > ,
10831086 ) : Promise < T > {
10841087 // API key is passed as query parameter — Gemini's auth convention
1085- const url = `${ this . config . baseURL } ${ endpoint } ?key=${ this . config . apiKey } ` ;
1088+ const url = `${ this . config . baseURL } ${ endpoint } ?key=${ this . keyPool ?. hasKeys ? this . keyPool . next ( ) : this . config . apiKey } ` ;
10861089 const headers : Record < string , string > = {
10871090 'Content-Type' : 'application/json' ,
10881091 'User-Agent' : 'AgentOS/1.0 (GeminiProvider)' ,
@@ -1203,7 +1206,7 @@ export class GeminiProvider implements IProvider {
12031206 body : Record < string , unknown > ,
12041207 ) : Promise < ReadableStream < Uint8Array > > {
12051208 // Both alt=sse and key= are query params
1206- const url = `${ this . config . baseURL } ${ endpoint } ?alt=sse&key=${ this . config . apiKey } ` ;
1209+ const url = `${ this . config . baseURL } ${ endpoint } ?alt=sse&key=${ this . keyPool ?. hasKeys ? this . keyPool . next ( ) : this . config . apiKey } ` ;
12071210 const headers : Record < string , string > = {
12081211 'Content-Type' : 'application/json' ,
12091212 'User-Agent' : 'AgentOS/1.0 (GeminiProvider)' ,
0 commit comments