OpenAIClientOptionsWithAzureAgent interface

Extended OpenAI client options to include Azure Agent endpoint configuration.

Extends

ClientOptions

Properties

azureConfig

Azure Agent endpoint configuration.

Inherited Properties

adminAPIKey

Defaults to process.env['OPENAI_ADMIN_KEY'].

apiKey

API key used for authentication.

  • Accepts either a static string or an async function that resolves to a string.
  • Defaults to process.env['OPENAI_API_KEY'].
  • When a function is provided, it is invoked when building bearer authentication headers for each attempt, including retries and direct buildRequest() calls. Each invocation's result is used for its own request.
  • The function must return a non-empty string; otherwise an OpenAIError is thrown.
  • If the function throws, the error is wrapped in an OpenAIError with the original error available as cause.
  • Mutually exclusive with workloadIdentity.
baseURL

Override the default base URL for the API, e.g., "https://api.example.com/v2/"

Defaults to process.env['OPENAI_BASE_URL'].

credential

First-class certificate credential created with fromX509 from openai/auth/x509-transport.

dangerouslyAllowBrowser

By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers. Only set this option to true if you understand the risks and have appropriate mitigations in place.

dataResidency

Select an OpenAI regional endpoint. This overrides an inherited or environment base URL and is mutually exclusive with an explicit baseURL or provider. Availability depends on your project and model; no fallback is performed. null and undefined leave ordinary base URL resolution unchanged.

defaultHeaders

Default headers to include with every request to the API.

These can be removed in individual requests by explicitly setting the header to null in request options.

defaultQuery

Default query parameters to include with every request to the API.

These can be removed in individual requests by explicitly setting the param to undefined in request options.

fetch

Specify a custom fetch function implementation.

If not provided, we expect that fetch is defined globally.

fetchOptions

Additional RequestInit options to be passed to fetch calls. Properties will be overridden by per-request fetchOptions.

logger

Set the logger.

Defaults to globalThis.console.

logLevel

Set the log level.

Defaults to process.env['OPENAI_LOG'] or 'warn' if it isn't set.

maxRetries

The maximum number of times that the client will retry a request in case of a temporary failure, like a network error or a 5XX error from the server.

organization

Defaults to process.env['OPENAI_ORG_ID'].

project

Defaults to process.env['OPENAI_PROJECT_ID'].

provider

Configure this client to use a third-party API provider. Mutually exclusive with top-level authentication and baseURL options.

timeout

The maximum amount of time (in milliseconds) that the client should wait for a response from the server before timing out a single request.

Note that request timeouts are retried by default, so in a worst-case scenario you may wait much longer than this timeout before the promise succeeds or fails.

Node.js fetch enforces independent response-header and body-inactivity timeouts, typically defaulting to five minutes, even when this timeout is longer. To increase them, install undici and configure an Agent with the matching fetch implementation:

import { Agent, fetch } from 'undici';

const timeout = 20 * 60 * 1000;
const client = new OpenAI({
  timeout,
  fetch,
  fetchOptions: {
    dispatcher: new Agent({ headersTimeout: timeout, bodyTimeout: timeout }),
  },
});
webhookSecret

Defaults to process.env['OPENAI_WEBHOOK_SECRET'].

workloadIdentity

Workload identity configuration for OAuth2 token exchange authentication. Mutually exclusive with apiKey.

x509Transport

Approved, frozen Node.js certificate transport required only for X.509 workload identity.

Property Details

azureConfig

Azure Agent endpoint configuration.

azureConfig?: AzureAgentConfig

Property Value

Inherited Property Details

adminAPIKey

Defaults to process.env['OPENAI_ADMIN_KEY'].

adminAPIKey?: string | null

Property Value

string | null

Inherited From OpenAIClientOptions.adminAPIKey

apiKey

API key used for authentication.

  • Accepts either a static string or an async function that resolves to a string.
  • Defaults to process.env['OPENAI_API_KEY'].
  • When a function is provided, it is invoked when building bearer authentication headers for each attempt, including retries and direct buildRequest() calls. Each invocation's result is used for its own request.
  • The function must return a non-empty string; otherwise an OpenAIError is thrown.
  • If the function throws, the error is wrapped in an OpenAIError with the original error available as cause.
  • Mutually exclusive with workloadIdentity.
apiKey?: string | ApiKeySetter | null

Property Value

string | ApiKeySetter | null

Inherited From OpenAIClientOptions.apiKey

baseURL

Override the default base URL for the API, e.g., "https://api.example.com/v2/"

Defaults to process.env['OPENAI_BASE_URL'].

baseURL?: string | null

Property Value

string | null

Inherited From OpenAIClientOptions.baseURL

credential

First-class certificate credential created with fromX509 from openai/auth/x509-transport.

credential?: X509Credential

Property Value

X509Credential

Inherited From OpenAIClientOptions.credential

dangerouslyAllowBrowser

By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers. Only set this option to true if you understand the risks and have appropriate mitigations in place.

dangerouslyAllowBrowser?: boolean

Property Value

boolean

Inherited From OpenAIClientOptions.dangerouslyAllowBrowser

dataResidency

Select an OpenAI regional endpoint. This overrides an inherited or environment base URL and is mutually exclusive with an explicit baseURL or provider. Availability depends on your project and model; no fallback is performed. null and undefined leave ordinary base URL resolution unchanged.

dataResidency?: DataResidency | null

Property Value

DataResidency | null

Inherited From OpenAIClientOptions.dataResidency

defaultHeaders

Default headers to include with every request to the API.

These can be removed in individual requests by explicitly setting the header to null in request options.

defaultHeaders?: HeadersLike

Property Value

HeadersLike

Inherited From OpenAIClientOptions.defaultHeaders

defaultQuery

Default query parameters to include with every request to the API.

These can be removed in individual requests by explicitly setting the param to undefined in request options.

defaultQuery?: Record<string, string | undefined>

Property Value

Record<string, string | undefined>

Inherited From OpenAIClientOptions.defaultQuery

fetch

Specify a custom fetch function implementation.

If not provided, we expect that fetch is defined globally.

fetch?: Fetch

Property Value

Fetch

Inherited From OpenAIClientOptions.fetch

fetchOptions

Additional RequestInit options to be passed to fetch calls. Properties will be overridden by per-request fetchOptions.

fetchOptions?: MergedRequestInit

Property Value

MergedRequestInit

Inherited From OpenAIClientOptions.fetchOptions

logger

Set the logger.

Defaults to globalThis.console.

logger?: Logger

Property Value

Logger

Inherited From OpenAIClientOptions.logger

logLevel

Set the log level.

Defaults to process.env['OPENAI_LOG'] or 'warn' if it isn't set.

logLevel?: LogLevel

Property Value

LogLevel

Inherited From OpenAIClientOptions.logLevel

maxRetries

The maximum number of times that the client will retry a request in case of a temporary failure, like a network error or a 5XX error from the server.

maxRetries?: number

Property Value

number

Inherited From OpenAIClientOptions.maxRetries

organization

Defaults to process.env['OPENAI_ORG_ID'].

organization?: string | null

Property Value

string | null

Inherited From OpenAIClientOptions.organization

project

Defaults to process.env['OPENAI_PROJECT_ID'].

project?: string | null

Property Value

string | null

Inherited From OpenAIClientOptions.project

provider

Configure this client to use a third-party API provider. Mutually exclusive with top-level authentication and baseURL options.

provider?: Provider

Property Value

Provider

Inherited From OpenAIClientOptions.provider

timeout

The maximum amount of time (in milliseconds) that the client should wait for a response from the server before timing out a single request.

Note that request timeouts are retried by default, so in a worst-case scenario you may wait much longer than this timeout before the promise succeeds or fails.

Node.js fetch enforces independent response-header and body-inactivity timeouts, typically defaulting to five minutes, even when this timeout is longer. To increase them, install undici and configure an Agent with the matching fetch implementation:

import { Agent, fetch } from 'undici';

const timeout = 20 * 60 * 1000;
const client = new OpenAI({
  timeout,
  fetch,
  fetchOptions: {
    dispatcher: new Agent({ headersTimeout: timeout, bodyTimeout: timeout }),
  },
});
timeout?: number

Property Value

number

Inherited From OpenAIClientOptions.timeout

webhookSecret

Defaults to process.env['OPENAI_WEBHOOK_SECRET'].

webhookSecret?: string | null

Property Value

string | null

Inherited From OpenAIClientOptions.webhookSecret

workloadIdentity

Workload identity configuration for OAuth2 token exchange authentication. Mutually exclusive with apiKey.

workloadIdentity?: WorkloadIdentity | X509WorkloadIdentity

Property Value

WorkloadIdentity | X509WorkloadIdentity

Inherited From OpenAIClientOptions.workloadIdentity

x509Transport

Approved, frozen Node.js certificate transport required only for X.509 workload identity.

x509Transport?: X509Transport

Property Value

X509Transport

Inherited From OpenAIClientOptions.x509Transport