Skip to content

Commit 7405bc8

Browse files
Merge pull request #2795 from diberry/diberry/0602-AzureClientOptions
JS - AzureClientOptions
2 parents c723189 + f1156ab commit 7405bc8

File tree

1 file changed

+38
-12
lines changed
  • articles/ai-services/openai/includes/language-overview

1 file changed

+38
-12
lines changed

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

Lines changed: 38 additions & 12 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/13/2025
99
---
1010

1111
[Source code](https://github.com/openai/openai-node) | [Package (npm)](https://www.npmjs.com/package/openai) | [Reference](../../reference.md) |
@@ -36,7 +36,7 @@ import { DefaultAzureCredential } from "@azure/identity";
3636
const credential = new DefaultAzureCredential();
3737
```
3838

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

4141
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:
4242

@@ -48,38 +48,64 @@ const endpoint = "https://your-azure-openai-resource.com";
4848
const apiVersion = "2024-10-21"
4949
const scope = "https://cognitiveservices.azure.com/.default";
5050
const azureADTokenProvider = getBearerTokenProvider(credential, scope);
51-
51+
const deployment = "gpt-35-turbo";
5252

5353
const client = new AzureOpenAI({
5454
endpoint,
55-
apiVersions,
55+
apiVersion,
56+
deployment,
5657
azureADTokenProvider
57-
});
58+
});
5859
```
5960

6061
For more information about Azure OpenAI keyless authentication, see the "[Get started with the Azure OpenAI security building block](/azure/developer/ai/get-started-securing-your-ai-app?tabs=github-codespaces&pivots=typescript)" QuickStart article.
6162

62-
# [API Key](#tab/api-key)
6363

64-
API Key
64+
### Configuration
65+
66+
The `AzureClientOptions` object extends the OpenAI `ClientOptions` object. This Azure-specific client object is used to configure the connection and behavior of the Azure OpenAI client. It includes properties for specifying the properties unique to Azure.
6567

66-
API keys are not recommended for production use because they are less secure than other authentication methods.
68+
| Property | Details |
69+
|--|--|
70+
| apiVersion: `string` | Specifies the API version to use. |
71+
| azureADTokenProvider: `(() => Promise<string>)` | A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory), invoked on every request.|
72+
| deployment: `string` | A model deployment. If provided, sets the base client URL to include `/deployments/{deployment}`. Non-deployment endpoints can't be used (not supported with Assistants APIs).|
73+
| endpoint: `string` | Your Azure OpenAI endpoint with the following format: `https://RESOURCE-NAME.azure.openai.com/`.|
74+
75+
# [API Key](#tab/api-key)
76+
77+
API keys aren't recommended for production use because they're less secure than other authentication methods.
6778

6879
```typescript
6980
import { AzureKeyCredential } from "@azure/openai";
7081
const apiKey = new AzureKeyCredential("your API key");
71-
const endpoint = "https://your-azure-openai-resource.com";0
82+
const endpoint = "https://your-azure-openai-resource.com";
7283
const apiVersion = "2024-10-21"
84+
const deployment = "gpt-35-turbo";
7385

74-
const client = new AzureOpenAI({ apiKey, endpoint, apiVersion });
86+
const client = new AzureOpenAI({
87+
apiKey,
88+
endpoint,
89+
apiVersion,
90+
deployment
91+
});
7592
```
7693

77-
`AzureOpenAI` can be authenticated with an API key by setting the `AZURE_OPENAI_API_KEY` environment variable or by setting the `apiKey` string property in the options object when creating the `AzureOpenAI` client.
94+
### Configuration
7895

79-
[!INCLUDE [Azure key vault](~/reusable-content/ce-skilling/azure/includes/ai-services/security/azure-key-vault.md)]
96+
The `AzureClientOptions` object extends the OpenAI `ClientOptions` object. This Azure-specific client object is used to configure the connection and behavior of the Azure OpenAI client. It includes properties for specifying the properties unique to Azure.
8097

98+
| Property | Details |
99+
|--|--|
100+
| apiKey: `string` | Your API key for authenticating requests. |
101+
| apiVersion: `string` | Specifies the API version to use. |
102+
| deployment: `string` | A model deployment. If provided, sets the base client URL to include `/deployments/{deployment}`. Non-deployment endpoints can't be used (not supported with Assistants APIs).|
103+
| endpoint: `string` | Your Azure OpenAI endpoint with the following format: `https://RESOURCE-NAME.azure.openai.com/`.|
104+
105+
[!INCLUDE [Azure key vault](~/reusable-content/ce-skilling/azure/includes/ai-services/security/azure-key-vault.md)]
81106
---
82107

108+
83109
## Audio
84110

85111
### Transcription

0 commit comments

Comments
 (0)