You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: OpenAI_API/APIAuthentication.cs
+45-21Lines changed: 45 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,10 @@ public class APIAuthentication
17
17
/// The API key, required to access the API endpoint.
18
18
/// </summary>
19
19
publicstringApiKey{get;set;}
20
+
/// <summary>
21
+
/// The Organization ID to count API requests against. This can be found at https://beta.openai.com/account/org-settings.
22
+
/// </summary>
23
+
publicstringOpenAIOrganization{get;set;}
20
24
21
25
/// <summary>
22
26
/// Allows implicit casting from a string, so that a simple string API key can be provided in place of an instance of <see cref="APIAuthentication"/>
@@ -36,7 +40,19 @@ public APIAuthentication(string apiKey)
36
40
this.ApiKey=apiKey;
37
41
}
38
42
39
-
privatestaticAPIAuthenticationcachedDefault=null;
43
+
44
+
/// <summary>
45
+
/// Instantiates a new Authentication object with the given <paramref name="apiKey"/>, which may be <see langword="null"/>. For users who belong to multiple organizations, you can specify which organization is used. Usage from these API requests will count against the specified organization's subscription quota.
46
+
/// </summary>
47
+
/// <param name="apiKey">The API key, required to access the API endpoint.</param>
48
+
/// <param name="openAIOrganization">The Organization ID to count API requests against. This can be found at https://beta.openai.com/account/org-settings.</param>
/// 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. <seealso cref="LoadFromEnv"/><seealso cref="LoadFromPath(string, string, bool)"/>
@@ -63,21 +79,25 @@ public static APIAuthentication Default
63
79
}
64
80
}
65
81
66
-
/// <summary>
67
-
/// Attempts to load api keys from environment variables, as "OPENAI_KEY" (or "OPENAI_SECRET_KEY", for backwards compatibility)
68
-
/// </summary>
69
-
/// <returns>Returns the loaded <see cref="APIAuthentication"/> any api keys were found, or <see langword="null"/> if there were no matching environment vars.</returns>
70
-
publicstaticAPIAuthenticationLoadFromEnv()
82
+
/// <summary>
83
+
/// Attempts to load api key from environment variables, as "OPENAI_KEY" or "OPENAI_API_KEY". Also loads org if from "OPENAI_ORGANIZATION" if present.
84
+
/// </summary>
85
+
/// <returns>Returns the loaded <see cref="APIAuthentication"/> any api keys were found, or <see langword="null"/> if there were no matching environment vars.</returns>
OpenAIAPIapi=newOpenAIAPI(APIAuthenticationLoadFromEnv()); // use env vars
53
53
// or
@@ -56,6 +56,14 @@ OpenAIAPI api = new OpenAIAPI(APIAuthentication LoadFromPath()); // use config f
56
56
OpenAIAPIapi=newOpenAIAPI(); // uses default, env, or config file
57
57
```
58
58
59
+
You may optionally include an openAIOrganization (OPENAI_ORGANIZATION in env or config file) specifying which organization is used for an API request. Usage from these API requests will count against the specified organization's subscription quota. Organization IDs can be found on your [Organization settings](https://beta.openai.com/account/org-settings) page.
0 commit comments