Azure AI Masters

Free Demo Class

Book Your Free Demo Class

Share your details and our team will call you to confirm your free Azure AI demo.

Blog › Tutorials
Hands-on tutorial · Updated October 2026

Azure OpenAI Service Tutorial

2026 guide · From resource to your first working app

This Azure OpenAI Service tutorial takes you from zero to a working app: create an Azure OpenAI resource, deploy a model, test it in the playground, call it from Python with the OpenAI SDK, write better prompts and add your own data with RAG — with security and cost tips along the way.

✍️ Azure AI Masters trainers⏱️ 10 min read📅 Updated 12 October 2026
📑 On this page

What is Azure OpenAI Service?

Azure OpenAI Service gives you OpenAI models — such as GPT models for chat and text, and embedding models for search — inside Microsoft Azure.

🔐 Enterprise security

Microsoft Entra ID, private networking and Azure role-based access.

🛡️ Content filtering

Built-in filters for harmful content on prompts and responses.

🌍 Regional deployment

Deploy models in supported Azure regions close to your users.

Step 110 minutes

Step 1: Create an Azure OpenAI resource

You need an Azure subscription. Then create the resource from the Azure portal or Azure AI Foundry.

📋 You will set

SubscriptionResource groupRegionResource namePricing tier

🛠️ Do this

  • Search for Azure OpenAI in the Azure portal and select Create.
  • Pick a resource group and a region that offers the model you need.
  • After deployment, open Keys and Endpoint and note the endpoint.
✅ Checkpoint: you have an Azure OpenAI resource with an endpoint.
Step 25 minutes

Step 2: Deploy a model

Your code never calls a model directly — it calls a deployment you create from a model.

📘 Key terms

ModelDeployment nameModel versionQuota / tokens per minute

🛠️ Do this

  • Open your resource in Azure AI Foundry and go to Deployments.
  • Deploy a chat model and give the deployment a simple name.
  • Note the deployment name — you will use it in code.
✅ Checkpoint: you have a deployment name you can call.
Step 310 minutes

Step 3: Test in the chat playground

Before writing code, try prompts in the playground to see how the model behaves.

🎛️ Settings to try

System messageTemperatureMax response tokensFew-shot examples

🛠️ Do this

  • Write a system message that sets the assistant’s role and tone.
  • Ask the same question at temperature 0.2 and 0.9 and compare.
  • Use View code to see the sample request.
✅ Checkpoint: you know which system message and settings give the answers you want.
Step 415 minutes

Step 4: Call Azure OpenAI from Python

Install the OpenAI Python SDK, keep your secrets in a .env file and call your deployment.

pip install openai python-dotenv
# .env  (never commit this file)
AZURE_OPENAI_ENDPOINT=https://<your-resource>.openai.azure.com/
AZURE_OPENAI_API_KEY=<your-key>
AZURE_OPENAI_DEPLOYMENT=<your-deployment-name>
import os
from dotenv import load_dotenv
from openai import AzureOpenAI

load_dotenv()

client = AzureOpenAI(
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
    api_version="2024-10-21",  # check Microsoft Learn for the latest GA version
)

response = client.chat.completions.create(
    model=os.environ["AZURE_OPENAI_DEPLOYMENT"],  # your deployment name
    messages=[
        {"role": "system", "content": "You are a helpful Azure tutor. Answer in 3 short bullet points."},
        {"role": "user", "content": "What is Azure AI Search used for?"},
    ],
    temperature=0.3,
    max_tokens=300,
)

print(response.choices[0].message.content)
✅ Checkpoint: running the script prints an answer from your deployed model.
Note: the model parameter takes your deployment name, not the model family name. API versions change over time — check Microsoft Learn for the current one.

Stuck on keys or deployments? Build this live with our trainers in a free demo class.

Book a free demo
Step 5

Step 5: Write better prompts

  • Set the role in the system message — who the assistant is and what it must not do.
  • Be specific about format: bullet points, JSON, word limits.
  • Give examples (few-shot) when you need a consistent style.
  • Ask for grounded answers — “answer only from the context provided”.
  • Lower temperature for factual tasks; raise it for creative ones.
Step 6

Step 6: Answer from your own documents with RAG

Retrieval-augmented generation lets the model answer using your files instead of guessing.

1

Prepare documents

Upload PDFs or pages to Azure Blob Storage.

2

Index with Azure AI Search

Chunk the text and create vector embeddings.

3

Retrieve

For each question, fetch the most relevant chunks.

4

Generate

Send the chunks with a grounded prompt to your deployment.

Security and cost tips

🔑 Protect keys

Store keys in Azure Key Vault or use Microsoft Entra ID instead of keys.

🌐 Limit access

Use private endpoints and network rules for production apps.

🧮 Watch tokens

Shorter prompts and capped responses reduce cost.

📊 Set budgets

Add Azure budgets and alerts on your subscription.

🛡️ Keep filters on

Use content filtering and Azure AI Content Safety.

🧹 Clean up

Delete test deployments and resources you no longer need.

Go deeper with our Azure OpenAI course in Hyderabad or see where it fits in the Azure AI Engineer roadmap.

Frequently asked questions

What is Azure OpenAI Service?

It is a Microsoft Azure service that provides OpenAI models, such as GPT and embedding models, with Azure security, networking, regional deployment and content filtering.

How do I start with Azure OpenAI?

Create an Azure OpenAI resource, deploy a model, test prompts in the playground and then call your deployment from code using the endpoint, a key or Entra ID, and the deployment name.

What is the difference between a model and a deployment?

The model is the LLM itself. A deployment is your named instance of it inside your Azure OpenAI resource, and your code calls the deployment name.

Can I use Azure OpenAI with my own data?

Yes. Use retrieval-augmented generation (RAG) — index your documents in Azure AI Search and pass the most relevant content to the model with each question.

Which programming language is best for Azure OpenAI?

Python is the most common choice for learning and prototyping, but SDKs and REST APIs are also available for C#, JavaScript, Java and other languages.

How do I control Azure OpenAI costs?

Keep prompts short, cap response tokens, choose suitable models, set Azure budgets and alerts, and delete unused deployments.

Learn Azure AI with a trainer by your side

Join Azure AI Masters in Hyderabad (near JNTU Metro Station) or live online — 3-month training with real-time projects, AI-102 & AZ-900 aligned preparation, internship support and placement assistance.