httpClientFromApiKey function

Client httpClientFromApiKey(
  1. String? apiKey,
  2. List<String> envKeys
)

A http.Client authenticated using an API key.

If apiKey is not null then that API key is used. If apiKey is null, then the first set environment variables in envKeys (e.g. ['GOOGLE_API_KEY', 'GEMINI_API_KEY']) is used.

On the web, apiKey must be provided and envKeys is ignored.

Throws ConfigurationException apiKey is null and no API key is found in the given environment variables.

Implementation

http.Client httpClientFromApiKey(String? apiKey, List<String> envKeys) {
  if (apiKey == null) {
    throw ConfigurationException('apiKey must be set to an API key');
  }
  return auth.clientViaApiKey(apiKey);
}