Skip to content

Commit

Permalink
feat(client): add header OpenAI-Project (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Apr 16, 2024
1 parent 116e38a commit bb4df37
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export interface ClientOptions {
*/
organization?: string | null | undefined;

/**
* Defaults to process.env['OPENAI_PROJECT_ID'].
*/
project?: string | null | undefined;

/**
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
*
Expand Down Expand Up @@ -85,6 +90,7 @@ export interface ClientOptions {
export class OpenAI extends Core.APIClient {
apiKey: string;
organization: string | null;
project: string | null;

private _options: ClientOptions;

Expand All @@ -93,6 +99,7 @@ export class OpenAI extends Core.APIClient {
*
* @param {string | undefined} [opts.apiKey=process.env['OPENAI_API_KEY'] ?? undefined]
* @param {string | null | undefined} [opts.organization=process.env['OPENAI_ORG_ID'] ?? null]
* @param {string | null | undefined} [opts.project=process.env['OPENAI_PROJECT_ID'] ?? null]
* @param {string} [opts.baseURL=process.env['OPENAI_BASE_URL'] ?? https://api.openai.com/v1] - Override the default base URL for the API.
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
Expand All @@ -106,6 +113,7 @@ export class OpenAI extends Core.APIClient {
baseURL = Core.readEnv('OPENAI_BASE_URL'),
apiKey = Core.readEnv('OPENAI_API_KEY'),
organization = Core.readEnv('OPENAI_ORG_ID') ?? null,
project = Core.readEnv('OPENAI_PROJECT_ID') ?? null,
...opts
}: ClientOptions = {}) {
if (apiKey === undefined) {
Expand All @@ -117,6 +125,7 @@ export class OpenAI extends Core.APIClient {
const options: ClientOptions = {
apiKey,
organization,
project,
...opts,
baseURL: baseURL || `https://api.openai.com/v1`,
};
Expand All @@ -138,6 +147,7 @@ export class OpenAI extends Core.APIClient {

this.apiKey = apiKey;
this.organization = organization;
this.project = project;
}

completions: API.Completions = new API.Completions(this);
Expand All @@ -160,6 +170,7 @@ export class OpenAI extends Core.APIClient {
return {
...super.defaultHeaders(opts),
'OpenAI-Organization': this.organization,
'OpenAI-Project': this.project,
...this._options.defaultHeaders,
};
}
Expand Down

0 comments on commit bb4df37

Please sign in to comment.