Class OpenAIAuthentication
- Namespace
- OpenAI
- Assembly
- OpenAI-DotNet.dll
Represents authentication to the OpenAI API endpoint
public sealed class OpenAIAuthentication- Inheritance
- 
      
      OpenAIAuthentication
- Inherited Members
Constructors
OpenAIAuthentication(string)
Instantiates a new Authentication object with the given apiKey, which may be null.
public OpenAIAuthentication(string apiKey)Parameters
- apiKeystring
- The API key, required to access the API endpoint. 
OpenAIAuthentication(string, string, string)
Instantiates a new Authentication object with the given apiKey, which may be null.
public OpenAIAuthentication(string apiKey, string organization, string projectId = null)Parameters
- apiKeystring
- The API key, required to access the API endpoint. 
- organizationstring
- For users who belong to multiple organizations, you can pass a header to specify which organization is used for an API request. Usage from these API requests will count against the specified organization's subscription quota. 
- projectIdstring
- Optional, Project id to specify. 
Properties
ApiKey
The API key, required to access the API endpoint.
public string ApiKey { get; }Property Value
Default
The default authentication to use when no other auth is specified. This can be set manually, or automatically loaded via environment variables or a config file. LoadFromEnvironment(string)LoadFromDirectory(string, string, bool)
public static OpenAIAuthentication Default { get; }Property Value
OrganizationId
For users who belong to multiple organizations, you can pass a header to specify which organization is used for an API request. Usage from these API requests will count against the specified organization's subscription quota.
public string OrganizationId { get; }Property Value
ProjectId
For users that specify specific projects.
public string ProjectId { get; }Property Value
Methods
LoadFromDirectory(string, string, bool)
Attempts to load api keys from a configuration file, by default ".openai" in the current directory, optionally traversing up the directory tree.
public static OpenAIAuthentication LoadFromDirectory(string directory = null, string filename = ".openai", bool searchUp = true)Parameters
- directorystring
- The directory to look in, or null for the current directory. 
- filenamestring
- The filename of the config file. 
- searchUpbool
- Whether to recursively traverse up the directory tree if the - filenameis not found in the- directory.
Returns
- OpenAIAuthentication
- Returns the loaded OpenAIAuthentication any api keys were found, or null if it was not successful in finding a config (or if the config file didn't contain correctly formatted API keys) 
LoadFromEnv(string)
[Obsolete("use LoadFromEnvironment")]
public static OpenAIAuthentication LoadFromEnv(string organizationId = null)Parameters
- organizationIdstring
Returns
LoadFromEnvironment(string)
Attempts to load api keys from environment variables, as "OPENAI_KEY" (or "OPENAI_SECRET_KEY", for backwards compatibility)
public static OpenAIAuthentication LoadFromEnvironment(string organizationId = null)Parameters
- organizationIdstring
- For users who belong to multiple organizations, you can pass a header to specify which organization is used for an API request. Usage from these API requests will count against the specified organization's subscription quota. 
Returns
- OpenAIAuthentication
- Returns the loaded OpenAIAuthentication any api keys were found, or null if there were no matching environment vars. 
LoadFromPath(string)
Attempts to load api keys from a specified configuration file.
public static OpenAIAuthentication LoadFromPath(string path)Parameters
- pathstring
- The specified path to the configuration file. 
Returns
- OpenAIAuthentication
- Returns the loaded OpenAIAuthentication any api keys were found, or null if it was not successful in finding a config (or if the config file didn't contain correctly formatted API keys) 
Operators
implicit operator OpenAIAuthentication(string)
Allows implicit casting from a string, so that a simple string API key can be provided in place of an instance of OpenAIAuthentication.
public static implicit operator OpenAIAuthentication(string key)Parameters
- keystring
- The API key to convert into a OpenAIAuthentication.