@@ -18,6 +18,11 @@ export interface ClientOptions {
18
18
*/
19
19
organization ?: string | null | undefined ;
20
20
21
+ /**
22
+ * Defaults to process.env['OPENAI_PROJECT_ID'].
23
+ */
24
+ project ?: string | null | undefined ;
25
+
21
26
/**
22
27
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
23
28
*
@@ -85,6 +90,7 @@ export interface ClientOptions {
85
90
export class OpenAI extends Core . APIClient {
86
91
apiKey : string ;
87
92
organization : string | null ;
93
+ project : string | null ;
88
94
89
95
private _options : ClientOptions ;
90
96
@@ -93,6 +99,7 @@ export class OpenAI extends Core.APIClient {
93
99
*
94
100
* @param {string | undefined } [opts.apiKey=process.env['OPENAI_API_KEY'] ?? undefined]
95
101
* @param {string | null | undefined } [opts.organization=process.env['OPENAI_ORG_ID'] ?? null]
102
+ * @param {string | null | undefined } [opts.project=process.env['OPENAI_PROJECT_ID'] ?? null]
96
103
* @param {string } [opts.baseURL=process.env['OPENAI_BASE_URL'] ?? https://api.openai.com/v1] - Override the default base URL for the API.
97
104
* @param {number } [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
98
105
* @param {number } [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
@@ -106,6 +113,7 @@ export class OpenAI extends Core.APIClient {
106
113
baseURL = Core . readEnv ( 'OPENAI_BASE_URL' ) ,
107
114
apiKey = Core . readEnv ( 'OPENAI_API_KEY' ) ,
108
115
organization = Core . readEnv ( 'OPENAI_ORG_ID' ) ?? null ,
116
+ project = Core . readEnv ( 'OPENAI_PROJECT_ID' ) ?? null ,
109
117
...opts
110
118
} : ClientOptions = { } ) {
111
119
if ( apiKey === undefined ) {
@@ -117,6 +125,7 @@ export class OpenAI extends Core.APIClient {
117
125
const options : ClientOptions = {
118
126
apiKey,
119
127
organization,
128
+ project,
120
129
...opts ,
121
130
baseURL : baseURL || `https://api.openai.com/v1` ,
122
131
} ;
@@ -138,6 +147,7 @@ export class OpenAI extends Core.APIClient {
138
147
139
148
this . apiKey = apiKey ;
140
149
this . organization = organization ;
150
+ this . project = project ;
141
151
}
142
152
143
153
completions : API . Completions = new API . Completions ( this ) ;
@@ -160,6 +170,7 @@ export class OpenAI extends Core.APIClient {
160
170
return {
161
171
...super . defaultHeaders ( opts ) ,
162
172
'OpenAI-Organization' : this . organization ,
173
+ 'OpenAI-Project' : this . project ,
163
174
...this . _options . defaultHeaders ,
164
175
} ;
165
176
}
0 commit comments