Skip to content

Commit f0934d4

Browse files
committed
JS - AzureClientOptions
1 parent 9df9f0f commit f0934d4

File tree

1 file changed

+65
-3
lines changed
  • articles/ai-services/openai/includes/language-overview

1 file changed

+65
-3
lines changed

articles/ai-services/openai/includes/language-overview/javascript.md

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Azure OpenAI JavaScript support
55
manager: nitinme
66
ms.service: azure-ai-openai
77
ms.topic: include
8-
ms.date: 11/18/2024
8+
ms.date: 02/06/2025
99
---
1010

1111
[Source code](https://github.com/openai/openai-node) | [Package (npm)](https://www.npmjs.com/package/openai) | [Reference](../../reference.md) |
@@ -25,6 +25,33 @@ Feature availability in Azure OpenAI is dependent on what version of the REST AP
2525
npm install openai
2626
```
2727

28+
## Configuration
29+
30+
The `AzureClientOptions` object is used to configure the API client for interfacing with the Azure OpenAI API. The configuration object extends the existing OpenAi `ClientOptions` object. Below are the Azure OpenAI specific properties, their default values, and descriptions:
31+
32+
**Properties**:
33+
34+
* azureADTokenProvider:
35+
Type: (() => Promise<string>) | undefined
36+
Default: undefined
37+
Description: A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory), which will be invoked on every request.
38+
* apiKey:
39+
Type: string | undefined
40+
Default: process.env['AZURE_OPENAI_API_KEY']
41+
Description: Your API key for authenticating requests.
42+
* apiVersion:
43+
Type: string | undefined
44+
Default: process.env['OPENAI_API_VERSION']
45+
Description: Specifies the API version to use.
46+
* deployment:
47+
Type: string | undefined
48+
Default: undefined
49+
Description: A model deployment. If given, sets the base client URL to include /deployments/{deployment}. Note: this means you won't be able to use non-deployment endpoints. Not supported with Assistants APIs.
50+
* endpoint:
51+
Type: string | undefined
52+
Default: undefined
53+
Description: Your Azure endpoint, including the resource, e.g. https://example-resource.azure.openai.com/.
54+
2855
## Authentication
2956

3057
# [Microsoft Entra ID](#tab/secure)
@@ -36,7 +63,7 @@ import { DefaultAzureCredential } from "@azure/identity";
3663
const credential = new DefaultAzureCredential();
3764
```
3865

39-
This object is then passed to the second argument of the `OpenAIClient` and `AssistantsClient` client constructors.
66+
This object is then passed as part of the [`AzureClientOptions`](#configuration) object to the `AzureOpenAI` and `AssistantsClient` client constructors.
4067

4168
In order to authenticate the `AzureOpenAI` client, however, we need to use the `getBearerTokenProvider` function from the `@azure/identity` package. This function creates a token provider that `AzureOpenAI` uses internally to obtain tokens for each request. The token provider is created as follows:
4269

@@ -49,7 +76,6 @@ const apiVersion = "2024-10-21"
4976
const scope = "https://cognitiveservices.azure.com/.default";
5077
const azureADTokenProvider = getBearerTokenProvider(credential, scope);
5178

52-
5379
const client = new AzureOpenAI({
5480
endpoint,
5581
apiVersions,
@@ -78,6 +104,42 @@ const client = new AzureOpenAI({ apiKey, endpoint, apiVersion });
78104

79105
---
80106

107+
### AzureClientOptions Properties
108+
109+
| Property Name | Default Value / Environment Variable | Purpose |
110+
|---------------------|--------------------------------------|-------------------------------------------------------------------------|
111+
| `endpoint` | `process.env.AZURE_COSMOS_DB_ENDPOINT` | The endpoint URL for the Azure Cosmos DB instance. |
112+
| `key` | `process.env.AZURE_COSMOS_DB_KEY` | The primary key for accessing the Azure Cosmos DB instance. |
113+
| `databaseName` | `process.env.AZURE_COSMOS_DB_DATABASE` | The name of the database to connect to within the Azure Cosmos DB. |
114+
| `containerName` | `process.env.AZURE_COSMOS_DB_CONTAINER`| The name of the container (collection) within the database. |
115+
| `aadCredentials` | `new DefaultAzureCredential()` | Azure Active Directory credentials for authentication. |
116+
| `consistencyLevel` | `Session` | The consistency level for read operations (e.g., Strong, BoundedStaleness, Session, Eventual). |
117+
| `connectionPolicy` | `Default` | The connection policy for the Cosmos DB client, including retry options and preferred locations. |
118+
| `timeout` | `60000` (60 seconds) | The timeout duration for requests to the Azure Cosmos DB instance. |
119+
120+
## Description
121+
122+
The `AzureClientOptions` object is used to configure the connection and behavior of the Azure Cosmos DB client. It includes properties for specifying the endpoint, authentication credentials, database and container names, consistency level, connection policy, and request timeout.
123+
124+
### Example Usage
125+
126+
```typescript
127+
import { CosmosClient, AzureClientOptions } from "@azure/cosmos";
128+
129+
const options: AzureClientOptions = {
130+
endpoint: process.env.AZURE_COSMOS_DB_ENDPOINT,
131+
key: process.env.AZURE_COSMOS_DB_KEY,
132+
databaseName: process.env.AZURE_COSMOS_DB_DATABASE,
133+
containerName: process.env.AZURE_COSMOS_DB_CONTAINER,
134+
aadCredentials: new DefaultAzureCredential(),
135+
consistencyLevel: "Session",
136+
connectionPolicy: { retryOptions: { maxRetryAttempts: 3 } },
137+
timeout: 60000,
138+
};
139+
140+
const client = new CosmosClient(options);
141+
```
142+
81143
## Audio
82144

83145
### Transcription

0 commit comments

Comments
 (0)