Skip to main content

ApiKeys

Namespace: Wisej.AI.Helpers

Assembly: Wisej.AI

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.

ParameterTypeDescription
nameStringThe name of the API key to retrieve.
namePostfixStringAn optional postfix to remove from the name when searching for the key.
envPrefix StringThe 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
}