diff --git a/README.md b/README.md index 4cdebfe0a..05c3f4964 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,15 @@ Error codes are as followed: | >=500 | `InternalServerError` | | N/A | `APIConnectionError` | +### Azure OpenAI + +An example of using this library with Azure OpenAI can be found [here](https://github.com/openai/openai-node/blob/master/examples/azure.ts). + +Please note there are subtle differences in API shape & behavior between the Azure OpenAI API and the OpenAI API, +so using this library with Azure OpenAI may result in incorrect types, which can lead to bugs. + +See [`@azure/openai`](https://www.npmjs.com/package/@azure/openai) for an Azure-specific SDK provided by Microsoft. + ### Retries Certain errors will be automatically retried 2 times by default, with a short exponential backoff. diff --git a/examples/azure.ts b/examples/azure.ts index 058143885..a903cfd6e 100755 --- a/examples/azure.ts +++ b/examples/azure.ts @@ -10,6 +10,9 @@ const resource = ''; // Navigate to the Azure OpenAI Studio to deploy a model. const model = ''; +// https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning +const apiVersion = '2023-06-01-preview'; + const apiKey = process.env['AZURE_OPENAI_API_KEY']; if (!apiKey) { throw new Error('The AZURE_OPENAI_API_KEY environment variable is missing or empty.'); @@ -19,7 +22,7 @@ if (!apiKey) { const openai = new OpenAI({ apiKey, baseURL: `https://${resource}.openai.azure.com/openai/deployments/${model}`, - defaultQuery: { 'api-version': '2023-06-01-preview' }, + defaultQuery: { 'api-version': apiVersion }, defaultHeaders: { 'api-key': apiKey }, });