
Azure Samples OpenAI is a collection of code samples that demonstrate how to use the OpenAI API with Azure.
OpenAI is a platform that provides access to AI models for tasks like text generation, translation, and more.
To get started with Azure Samples OpenAI, you'll need to create an Azure account and install the OpenAI SDK.
With the OpenAI SDK, you can interact with the OpenAI API and run code samples from the Azure Samples OpenAI collection.
Here's an interesting read: Azure Sdk
Access Control
Access Control is a crucial aspect of Azure OpenAI, and there are two primary methods for authentication: API Keys and Microsoft Entra ID.
API Key authentication requires including the API Key in the api-key HTTP header, as outlined in the Quickstart guide.
You can also use Microsoft Entra ID authentication, which involves including a token in the Authorization header, preceded by Bearer.
Azure OpenAI On Your Data supports system-assigned and user-assigned managed identities for authentication, with specific options for each.
Here are the authentication options for Azure OpenAI On Your Data when using a user-assigned managed identity:
Managed Identity Options

Managed Identity Options are a secure way to authenticate Azure OpenAI On Your Data. This method uses a system-assigned managed identity or a user-assigned managed identity for authentication.
There are two types of managed identities you can use: system-assigned and user-assigned. System-assigned managed identities are automatically created and managed by Azure, while user-assigned managed identities are created and managed by you.
To use a user-assigned managed identity, you need to specify the resource ID of the identity in the authentication options. This is not required, but it's necessary if you want to use a user-assigned identity.
Here are the details you need to provide when using a user-assigned managed identity:
Retrieve API Credentials
To retrieve your API credentials, you'll need to navigate to the Azure portal and find your resource. The endpoint value is located under Keys and Endpoint for your resource in the Azure portal, and you can also find it via the Deployments page in Azure AI Foundry portal. An example endpoint is: https://docs-test-001.openai.azure.com/.
See what others are reading: Azure Openai Endpoint

The key value is also located under Keys and Endpoint for your resource in the Azure portal, and Azure generates two keys for your resource. You can use either value, so it's a good idea to copy both the Endpoint value and an access key value. If you use an API key, store it securely somewhere else, such as in Azure Key Vault.
To obtain your API credentials, follow these steps:
Always keep in mind that having two keys allows you to securely rotate and regenerate keys without causing a service disruption.
Text Generation
Text generation is a powerful feature of Azure OpenAI, allowing you to create unique and engaging content with ease.
You can use the `createCompletionResponse` API to generate text completions, which includes a unique identifier for the completion, a list of completion choices, and a Unix timestamp for when the completion was created.
The model used for completion is also included, giving you insight into how the text was generated. This can be useful for understanding the context and parameters of the completion.
Recommended read: Azure Openai Chat Completion Python

Here's a breakdown of the key components of a text completion response:
By leveraging these features, you can unlock the full potential of text generation and create engaging content that resonates with your audience.
Completions
Completions are a crucial part of text generation, allowing you to generate text based on a given prompt.
You can control the sampling temperature for completions, with values between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
A unique identifier, called the system fingerprint, is generated for each completion, representing the backend configuration that the model runs with. This can be used to understand when backend changes have been made that might impact determinism.
You can also specify an upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens, using the max_completion_tokens parameter.
For your interest: Azure Openai Completions Playground

The model used for completion is also included in the response, which can be useful for understanding the specific model that generated the completion.
In some cases, a list of completion choices may be returned, which can be useful for generating multiple possible completions.
Here are some key parameters you can use to control completions:
These parameters can be used to fine-tune the completion process and generate more accurate and relevant text.
Embeddings
To get a vector representation of your input, you can use embeddings. Embeddings can be easily consumed by machine learning models and algorithms.
You'll need to specify an endpoint, which is the URL of your Azure OpenAI resource, such as https://aoairesource.openai.azure.com. Replace "aoairesource" with your actual Azure OpenAI resource name.
The endpoint URL should be in the format https://{your-resource-name}.openai.azure.com.
You'll also need to include a deployment-id, which is a required parameter.
The API version is also required and can be specified in the query string.
Explore further: Langchain Azure Openai Embeddings

To embed your input text, you can pass a string or an array of tokens. If you want to embed multiple inputs in a single request, you can pass an array of strings or an array of token arrays.
However, be aware that the input must not exceed the maximum input tokens for the model, which is 8,192 tokens for the text-embedding-ada-002 model.
Translations
Translations are a crucial part of text generation, and this feature is designed to transcribe and translate input audio into English text.
The audio file to translate is a required parameter, and you'll need to provide a string value for this.
You can also provide an optional text prompt to guide the model's style or continue a previous audio segment, but keep in mind that the prompt should be in English.
The response format is defined by the `response_format` parameter, which can be one of the audioResponseFormat values.
For another approach, see: Azure Openai Prompt vs Completion
The sampling temperature is another adjustable parameter, with a range of 0 to 1. A higher temperature like 0.8 will make the output more random, while a lower temperature like 0.2 will make it more focused and deterministic.
If you set the temperature to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.
Here's a breakdown of the parameters:
Audio and Image
Azure OpenAI offers a range of APIs for generating images and audio, including the DALL-E model. You can use these APIs to create images from text captions, with options for customizing the image size, quality, and style.
The DALL-E model can generate images in various sizes, including 1024x1024 pixels, which is the default size. You can also specify the number of images to generate, with a default value of 1.
Here is a list of the available image response formats:
- url: provides temporary access to download the generated images
- b64_json: returns the generated images as base64 encoded strings
Azure OpenAI provides a PowerShell script example for generating images using the DALL-E model. The script uses the Invoke-RestMethod cmdlet to send a POST request to the Azure OpenAI API, and then waits for the image to be generated before downloading it to a file.
Audio Verbose Response
The audio verbose response is a format of output that provides detailed information about the transcription or audio task. It's defined by the "audioVerboseResponse" section in the API documentation.
This format includes several key fields, such as "text", "task", "language", "duration", and "segments". The "text" field contains the translated or transcribed text, while "task" specifies the type of audio task. The "language" field indicates the language of the transcription, and "duration" provides the length of the audio file.
The "segments" field is an array that contains additional metadata about the transcription. Here's a breakdown of the fields in the audio verbose response:
Overall, the audio verbose response provides a detailed and structured format for outputting transcription or audio task results.
Image Generation
Image generation with Azure OpenAI is a powerful tool that can create stunning images from text captions. You can generate a batch of images from a text caption on a given DALL-E model deployment. To do this, you'll need to specify the endpoint, deployment ID, and API version.
Discover more: Azure Openai Deployment Name
The endpoint is the URL of your Azure OpenAI resource, such as https://YOUR_RESOURCE_NAME.openai.azure.com. The deployment ID is the ID of the DALL-E model that was deployed. The API version is the version of the API you're using, which is currently set to 2023-06-01-preview.
To generate images, you'll also need to specify the prompt, which is the text description of the desired image(s). The maximum length of the prompt is 4,000 characters. You can also specify the number of images to generate, the size of the generated images, and the response format.
The response format can be either a URL that provides temporary access to download the generated images or a base64 encoded string of the generated images. The size of the generated images can be specified in pixels, such as 1024x1024.
Here's a summary of the parameters you can specify when generating images:
You can also specify additional parameters, such as the user identifier, image quality, and style. However, these parameters are optional and have default values.
Completion Stream Response
A completion stream response is a way for the model to provide a chat completion response in a streamed format, rather than all at once. This can be useful for larger or more complex responses.
The model used for the chat completion is always specified in the response, and it's a string that identifies the specific model used.
A unique identifier is assigned to each chunk of the streamed response, and it's a string that can be used to track the response. The timestamp for when the response was created is also included in each chunk.
The object type of a streamed chat completion response is always "chat.completion.chunk", which is an enum value that indicates the type of response.
A unique perspective: What Is Azure Used for
Sources
- https://learn.microsoft.com/en-us/azure/ai-services/openai/reference
- https://learn.microsoft.com/en-us/samples/azure-samples/azure-functions-openai-demo/azure-functions-openai-demo/
- https://learn.microsoft.com/en-us/azure/ai-services/openai/dall-e-quickstart
- https://www.linkedin.com/posts/pamela-s-fox_github-azure-samplesazure-openai-entity-extraction-activity-7259711298362343424-WaKG
- https://learn.microsoft.com/en-us/samples/azure-samples/openai-chat-vision-quickstart/openai-chat-vision-quickstart/
Featured Images: pexels.com