@azure/openai package

Classes

AzureKeyCredential

A static-key-based credential that supports updating the underlying key value.

OpenAIClient

A client for interacting with Azure OpenAI.

The client needs the endpoint of an OpenAI resource and an authentication method such as an API key or token. The API key and endpoint can be found in the OpenAI resource page. They will be located in the resource's Keys and Endpoint page.

Examples for authentication:

API Key

import { OpenAIClient } from "@azure/openai";
import { AzureKeyCredential } from "@azure/core-auth";

const endpoint = "<azure endpoint>";
const credential = new AzureKeyCredential("<api key>");

const client = new OpenAIClient(endpoint, credential);

Azure Active Directory

import { OpenAIClient } from "@azure/openai";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "<azure endpoint>";
const credential = new DefaultAzureCredential();

const client = new OpenAIClient(endpoint, credential);
OpenAIKeyCredential

The OpenAIKeyCredential class represents an OpenAI API key and is used to authenticate into an OpenAI client for an OpenAI endpoint.

Interfaces

AudioResultSimpleJson

Simple transcription response

AudioResultVerboseJson

Transcription response.

AudioSegment

Transcription segment.

AzureChatEnhancementConfiguration

A representation of the available Azure OpenAI enhancement configurations.

AzureChatEnhancements

Represents the output results of Azure enhancements to chat completions, as configured via the matching input provided in the request.

AzureChatExtensionConfiguration

A representation of configuration data for a single Azure OpenAI chat extension. This will be used by a chat completions request that should use Azure OpenAI chat extensions to augment the response behavior. The use of this configuration is compatible only with Azure OpenAI.

AzureChatExtensionDataSourceResponseCitation

A single instance of additional context information available when Azure OpenAI chat extensions are involved in the generation of a corresponding chat completions response. This context information is only populated when using an Azure OpenAI request configured to use a matching extension.

AzureChatExtensionsMessageContext

A representation of the additional context information available when Azure OpenAI chat extensions are involved in the generation of a corresponding chat completions response. This context information is only populated when using an Azure OpenAI request configured to use a matching extension.

AzureChatGroundingEnhancementConfiguration

A representation of the available options for the Azure OpenAI grounding enhancement.

AzureChatOCREnhancementConfiguration

A representation of the available options for the Azure OpenAI optical character recognition (OCR) enhancement.

AzureCosmosDBChatExtensionConfiguration

A specific representation of configurable options for Azure Cosmos DB when using it as an Azure OpenAI chat extension.

AzureCosmosDBFieldMappingOptions

Optional settings to control how fields are processed when using a configured Azure Cosmos DB resource.

AzureExtensionsOptions

Options for Azure OpenAI chat extensions.

AzureGroundingEnhancement

The grounding enhancement that returns the bounding box of the objects detected in the image.

AzureGroundingEnhancementCoordinatePoint

A representation of a single polygon point as used by the Azure grounding enhancement.

AzureGroundingEnhancementLine

A content line object consisting of an adjacent sequence of content elements, such as words and selection marks.

AzureGroundingEnhancementLineSpan

A span object that represents a detected object and its bounding box information.

AzureMachineLearningIndexChatExtensionConfiguration

A specific representation of configurable options for Azure Machine Learning vector index when using it as an Azure OpenAI chat extension.

AzureSearchChatExtensionConfiguration

A specific representation of configurable options for Azure Search when using it as an Azure OpenAI chat extension.

AzureSearchIndexFieldMappingOptions

Optional settings to control how fields are processed when using a configured Azure Search resource.

ChatChoice

The representation of a single prompt completion as part of an overall chat completions request. Generally, n choices are generated per provided prompt with a default value of 1. Token limits and other settings may limit the number of choices generated.

ChatChoiceLogProbabilityInfo

Log probability information for a choice, as requested via 'logprobs' and 'top_logprobs'.

ChatCompletions

Representation of the response data from a chat completions request. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.

ChatCompletionsFunctionToolCall

A tool call to a function tool, issued by the model in evaluation of a configured function tool, that represents a function invocation needed for a subsequent chat completions request to resolve.

ChatCompletionsFunctionToolDefinition

The definition information for a chat completions function tool that can call a function in response to a tool call.

ChatCompletionsFunctionToolSelection

A tool selection of a specific, named function tool that will limit chat completions to using the named function.

ChatCompletionsJsonResponseFormat

A response format for Chat Completions that restricts responses to emitting valid JSON objects.

ChatCompletionsNamedFunctionToolSelection

A tool selection of a specific, named function tool that will limit chat completions to using the named function.

ChatCompletionsNamedToolSelection

An abstract representation of an explicit, named tool selection to use for a chat completions request.

ChatCompletionsResponseFormat

An abstract representation of a response format configuration usable by Chat Completions. Can be used to enable JSON mode.

ChatCompletionsTextResponseFormat

The standard Chat Completions response format that can freely generate text and is not guaranteed to produce response content that adheres to a specific schema.

ChatCompletionsToolCall

An abstract representation of a tool call that must be resolved in a subsequent request to perform the requested chat completion.

ChatCompletionsToolDefinition

An abstract representation of a tool that can be used by the model to improve a chat completions response.

ChatFinishDetails

An abstract representation of structured information about why a chat completions response terminated.

ChatMessageContentItem

An abstract representation of a structured content item within a chat message.

ChatMessageImageContentItem

A structured chat content item containing an image reference.

ChatMessageImageUrl

An internet location from which the model may retrieve an image.

ChatMessageTextContentItem

A structured chat content item containing plain text.

ChatRequestAssistantMessage

A request chat message representing response or action from the assistant.

ChatRequestFunctionMessage

A request chat message representing requested output from a configured function.

ChatRequestMessage

An abstract representation of a chat message as provided in a request.

ChatRequestSystemMessage

A request chat message containing system instructions that influence how the model will generate a chat completions response.

ChatRequestToolMessage

A request chat message representing requested output from a configured tool.

ChatRequestUserMessage

A request chat message representing user input to the assistant.

ChatResponseMessage

A representation of a chat message as received in a response.

ChatTokenLogProbabilityInfo

A representation of the log probability information for a single message content token.

ChatTokenLogProbabilityResult

A representation of the log probability information for a single content token, including a list of most likely tokens if 'top_logprobs' were requested.

Choice

The representation of a single prompt completion as part of an overall completions request. Generally, n choices are generated per provided prompt with a default value of 1. Token limits and other settings may limit the number of choices generated.

Completions

Representation of the response data from a completions request. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.

CompletionsLogProbabilityModel

Representation of a log probabilities model for a completions generation.

CompletionsUsage

Representation of the token counts processed for a completions request. Counts consider all tokens across prompts, choices, choice alternates, best_of generations, and other consumers.

ContentFilterBlocklistIdResult

Represents the outcome of an evaluation against a custom blocklist as performed by content filtering.

ContentFilterCitedDetectionResult

Represents the outcome of a detection operation against protected resources as performed by content filtering.

ContentFilterDetectionResult

Represents the outcome of a detection operation performed by content filtering.

ContentFilterErrorResults

Information about the content filtering error result.

ContentFilterResult

Information about filtered content severity level and if it has been filtered or not.

ContentFilterResultsForPrompt

Content filtering results for a single prompt in the request.

ContentFilterSuccessResultDetailsForPrompt

Information about the content filtering success result.

ContentFilterSuccessResultsForChoice

Information about content filtering evaluated against generated model output.

ElasticsearchChatExtensionConfiguration

A specific representation of configurable options for Elasticsearch when using it as an Azure OpenAI chat extension.

ElasticsearchIndexFieldMappingOptions

Optional settings to control how fields are processed when using a configured Elasticsearch® resource.

EmbeddingItem

Representation of a single embeddings relatedness comparison.

Embeddings

Representation of the response data from an embeddings request. Embeddings measure the relatedness of text strings and are commonly used for search, clustering, recommendations, and other similar scenarios.

EmbeddingsUsage

Measurement of the amount of tokens used in this request and response.

EventStream

A readable stream that is iterable and disposable.

FunctionCall

The name and arguments of a function that should be called, as generated by the model.

FunctionDefinition

The definition of a caller-specified function that chat completions may invoke in response to matching user input.

FunctionName

A structure that specifies the exact name of a specific, request-provided function to use when processing a chat completions operation.

GetAudioTranscriptionOptions

The options for an audio transcription request

GetAudioTranslationOptions

The options for an audio translation request

GetChatCompletionsOptions

This module contains models that we want to live side-by-side with the corresponding generated models. This is useful for providing customer-facing models that have different names/types than the generated models.

GetCompletionsOptions

The configuration information for a completions request. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.

GetEmbeddingsOptions

Options for to custom embeddings request

GetImagesOptions

Represents the request data used to generate images.

ImageGenerationContentFilterResults

Describes the content filtering result for the image generation request.

ImageGenerationData

A representation of a single generated image, provided as either base64-encoded data or as a URL from which the image may be retrieved.

ImageGenerationPromptFilterResults

Describes the content filtering results for the prompt of a image generation request.

ImageGenerations

The result of a successful image generation operation.

MaxTokensFinishDetails

A structured representation of a stop reason that signifies a token limit was reached before the model could naturally complete.

OnYourDataAccessTokenAuthenticationOptions

The authentication options for Azure OpenAI On Your Data when using access token.

OnYourDataApiKeyAuthenticationOptions

The authentication options for Azure OpenAI On Your Data when using an API key.

OnYourDataAuthenticationOptions

The authentication options for Azure OpenAI On Your Data.

OnYourDataConnectionStringAuthenticationOptions

The authentication options for Azure OpenAI On Your Data when using a connection string.

OnYourDataDeploymentNameVectorizationSource

The details of a a vectorization source, used by Azure OpenAI On Your Data when applying vector search, that is based on an internal embeddings model deployment name in the same Azure OpenAI resource.

OnYourDataEncodedApiKeyAuthenticationOptions

The authentication options for Azure OpenAI On Your Data when using an Elasticsearch encoded API key.

OnYourDataEndpointVectorizationSource

The details of a a vectorization source, used by Azure OpenAI On Your Data when applying vector search, that is based on a public Azure OpenAI endpoint call for embeddings.

OnYourDataKeyAndKeyIdAuthenticationOptions

The authentication options for Azure OpenAI On Your Data when using an Elasticsearch key and key ID pair.

OnYourDataModelIdVectorizationSource

The details of a a vectorization source, used by Azure OpenAI On Your Data when applying vector search, that is based on a search service model ID. Currently only supported by Elasticsearch®.

OnYourDataSystemAssignedManagedIdentityAuthenticationOptions

The authentication options for Azure OpenAI On Your Data when using a system-assigned managed identity.

OnYourDataUserAssignedManagedIdentityAuthenticationOptions

The authentication options for Azure OpenAI On Your Data when using a user-assigned managed identity.

OnYourDataVectorizationSource

An abstract representation of a vectorization source for Azure OpenAI On Your Data with vector search.

OpenAIClientOptions
PineconeChatExtensionConfiguration

A specific representation of configurable options for Pinecone when using it as an Azure OpenAI chat extension.

PineconeFieldMappingOptions

Optional settings to control how fields are processed when using a configured Pinecone resource.

StopFinishDetails

A structured representation of a stop reason that signifies natural termination by the model.

Type Aliases

AudioResult

The type of the result of the transcription based on the requested response format

AudioResultFormat

The result format of an audio task

AudioTranscriptionTask

"transcribe", "translate"

AzureChatExtensionConfigurationUnion

Alias for AzureChatExtensionConfigurationUnion

AzureChatExtensionType

"azure_search", "azure_ml_index", "azure_cosmos_db", "elasticsearch", "pinecone"

AzureSearchQueryType

"simple", "semantic", "vector", "vector_simple_hybrid", "vector_semantic_hybrid"

ChatCompletionsNamedToolSelectionUnion

Alias for ChatCompletionsNamedToolSelectionUnion

ChatCompletionsResponseFormatUnion

Alias for ChatCompletionsResponseFormatUnion

ChatCompletionsToolCallUnion

Alias for ChatCompletionsToolCallUnion

ChatCompletionsToolDefinitionUnion

Alias for ChatCompletionsToolDefinitionUnion

ChatCompletionsToolSelectionPreset

"auto", "none"

ChatFinishDetailsUnion

Alias for ChatFinishDetailsUnion

ChatMessageContentItemUnion

Alias for ChatMessageContentItemUnion

ChatMessageImageDetailLevel

"auto", "low", "high"

ChatRequestMessageUnion

Alias for ChatRequestMessageUnion

ChatRole

"system", "assistant", "user", "function", "tool"

CompletionsFinishReason

"stop", "length", "content_filter", "function_call", "tool_calls"

ContentFilterResultDetailsForPrompt

Information about the content filtering category, if it has been detected.

ContentFilterResultsForChoice

Information about the content filtering results, if it has been detected.

ContentFilterSeverity

"safe", "low", "medium", "high"

ElasticsearchQueryType

"simple", "vector"

FunctionCallPreset

"auto", "none"

ImageGenerationQuality

"standard", "hd"

ImageGenerationResponseFormat

"url", "b64_json"

ImageGenerationStyle

"natural", "vivid"

ImageSize

"256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"

OnYourDataAuthenticationOptionsUnion

Alias for OnYourDataAuthenticationOptionsUnion

OnYourDataAuthenticationType

"api_key", "connection_string", "key_and_key_id", "encoded_api_key", "access_token", "system_assigned_managed_identity", "user_assigned_managed_identity"

OnYourDataVectorizationSourceType

"endpoint", "deployment_name", "model_id"

OnYourDataVectorizationSourceUnion

Alias for OnYourDataVectorizationSourceUnion