diff --git a/packages/googleai_dart/lib/src/client.dart b/packages/googleai_dart/lib/src/client.dart index 605aec83..c6abc41a 100644 --- a/packages/googleai_dart/lib/src/client.dart +++ b/packages/googleai_dart/lib/src/client.dart @@ -43,6 +43,12 @@ class GoogleAIClient extends g.GoogleAIClient { client: client ?? createDefaultHttpClient(), ); + /// Set or replace the API key. + set apiKey(final String value) => queryParams['key'] = value; + + /// Get the API key. + String get apiKey => queryParams['key']; + // ------------------------------------------ // METHOD: streamGenerateContent // ------------------------------------------ diff --git a/packages/langchain_google/lib/src/chat_models/google_ai/chat_google_generative_ai.dart b/packages/langchain_google/lib/src/chat_models/google_ai/chat_google_generative_ai.dart index 83a8d91b..ec8b5f57 100644 --- a/packages/langchain_google/lib/src/chat_models/google_ai/chat_google_generative_ai.dart +++ b/packages/langchain_google/lib/src/chat_models/google_ai/chat_google_generative_ai.dart @@ -167,6 +167,12 @@ class ChatGoogleGenerativeAI /// A UUID generator. late final Uuid _uuid = const Uuid(); + /// Set or replace the API key. + set apiKey(final String value) => _client.apiKey = value; + + /// Get the API key. + String get apiKey => _client.apiKey; + @override String get modelType => 'chat-google-generative-ai';