ApiKeys

Wisej.AI.Helpers.ApiKeys

Namespace: Wisej.AI.Helpers

Assembly: Wisej.AI (3.5.0.0)

Provides methods to retrieve API keys from environment variables or a configuration file.

public class ApiKeys

Methods

GetApiKey(name, namePostfix, envPrefix)

Retrieves the API key associated with the specified name.

Parameter
Type
Description

name

The name of the API key to retrieve.

namePostfix

An optional postfix to remove from the name when searching for the key.

envPrefix

The prefix for environment variables. Default is "WISEJ_AI_APIKEY_".

Returns: String. The API key if found; otherwise, null.

This method first attempts to retrieve the API key from environment variables using the specified prefix. If not found, it attempts to read the key from a JSON configuration file located at the path defined by AI_PATH and APIKEYS_FILENAME.


string apiKey = ApiKeys.GetApiKey("MyService", "Postfix");
if (apiKey != null)
{
// Use the API key
}

Last updated