@@ -18,6 +18,11 @@ export interface ClientOptions {
1818 */
1919 organization ?: string | null | undefined ;
2020
21+ /**
22+ * Defaults to process.env['OPENAI_PROJECT_ID'].
23+ */
24+ project ?: string | null | undefined ;
25+
2126 /**
2227 * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
2328 *
@@ -85,6 +90,7 @@ export interface ClientOptions {
8590export class OpenAI extends Core . APIClient {
8691 apiKey : string ;
8792 organization : string | null ;
93+ project : string | null ;
8894
8995 private _options : ClientOptions ;
9096
@@ -93,6 +99,7 @@ export class OpenAI extends Core.APIClient {
9399 *
94100 * @param {string | undefined } [opts.apiKey=process.env['OPENAI_API_KEY'] ?? undefined]
95101 * @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]
96103 * @param {string } [opts.baseURL=process.env['OPENAI_BASE_URL'] ?? https://api.openai.com/v1] - Override the default base URL for the API.
97104 * @param {number } [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
98105 * @param {number } [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
@@ -106,6 +113,7 @@ export class OpenAI extends Core.APIClient {
106113 baseURL = Core . readEnv ( 'OPENAI_BASE_URL' ) ,
107114 apiKey = Core . readEnv ( 'OPENAI_API_KEY' ) ,
108115 organization = Core . readEnv ( 'OPENAI_ORG_ID' ) ?? null ,
116+ project = Core . readEnv ( 'OPENAI_PROJECT_ID' ) ?? null ,
109117 ...opts
110118 } : ClientOptions = { } ) {
111119 if ( apiKey === undefined ) {
@@ -117,6 +125,7 @@ export class OpenAI extends Core.APIClient {
117125 const options : ClientOptions = {
118126 apiKey,
119127 organization,
128+ project,
120129 ...opts ,
121130 baseURL : baseURL || `https://api.openai.com/v1` ,
122131 } ;
@@ -138,6 +147,7 @@ export class OpenAI extends Core.APIClient {
138147
139148 this . apiKey = apiKey ;
140149 this . organization = organization ;
150+ this . project = project ;
141151 }
142152
143153 completions : API . Completions = new API . Completions ( this ) ;
@@ -160,6 +170,7 @@ export class OpenAI extends Core.APIClient {
160170 return {
161171 ...super . defaultHeaders ( opts ) ,
162172 'OpenAI-Organization' : this . organization ,
173+ 'OpenAI-Project' : this . project ,
163174 ...this . _options . defaultHeaders ,
164175 } ;
165176 }
0 commit comments