Skip to content

Commit 5176d98

Browse files
Merge pull request #7810 from MicrosoftDocs/main
Auto Publish – main to live - 2025-10-23 05:05 UTC
2 parents 0fb097e + 05667fd commit 5176d98

File tree

3 files changed

+60
-14
lines changed

3 files changed

+60
-14
lines changed

articles/ai-foundry/openai/azure-government.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ In some cases, models are retired in Azure Governmen ahead of dates in the comme
6666

6767
<br>
6868

69-
### Deafault Model Versions
69+
### Default Model Versions
7070
In some cases, new model versions are designated as default in Azure Governmen ahead of dates in the commercial cloud. General information on model upgrades can be found at [Working with Azure OpenAI models](/azure/ai-foundry/openai/how-to/working-with-models?tabs=powershell&branch=main#model-deployment-upgrade-configuration)
7171

7272
The following shows default model differences in Azure Government.
90 KB
Loading

articles/search/search-security-api-keys.md

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ ms.service: azure-ai-search
99
ms.custom:
1010
- ignite-2023
1111
ms.topic: how-to
12-
ms.date: 07/31/2025
12+
ms.date: 10/22/2025
1313
ms.update-cycle: 365-days
1414
#customer intent: I want to learn how to connect to Azure AI Search using API keys so that I can authenticate inbound requests to my search service.
1515
---
1616

1717
# Connect to Azure AI Search using keys
1818

19-
Azure AI Search supports both identity-based and key-based authentication for connections to your search service. An API key is a unique string composed of 52 randomly generated numbers and letters. In your source code, you can specify it in a request header, or as an [environment variable](/azure/ai-services/cognitive-services-environment-variables) or as an app setting in your project, and then reference the variable on the request.
19+
Azure AI Search supports both identity-based and key-based authentication for connections to your search service. An API key is a unique string composed of 52 randomly generated numbers and letters. In your source code, you can specify it in a request header, or as an [environment variable](/azure/ai-services/cognitive-services-environment-variables) or app setting in your project, and then reference the variable on the request.
2020

2121
> [!IMPORTANT]
2222
> When you create a search service, key-based authentication is the default, but it's not the most secure option. We recommend that you replace it with [role-based access](search-security-enable-roles.md).
@@ -45,18 +45,21 @@ Visually, there's no distinction between an admin key or query key. Both keys ar
4545
API keys are used for data plane (content) requests, such as creating or accessing an index or, any other request that's represented in the [Search REST APIs](/rest/api/searchservice/).
4646

4747
You can use either an API key or [Azure roles](search-security-rbac.md) for control plane (service) requests. When you use an API key:
48-
- Admin keys are used for creating, modifying, or deleting objects. Admin keys are also used to GET object definitions and system information.
48+
49+
- Admin keys are used for creating, modifying, or deleting objects. Admin keys are also used to GET object definitions and system information, such as [LIST Indexes](/rest/api/searchservice/indexes/list) or [GET Service Statistics](/rest/api/searchservice/get-service-statistics/get-service-statistics).
50+
4951
- Query keys are typically distributed to client applications that issue queries.
5052

5153
### [**REST API**](#tab/rest-use)
5254

53-
**How API keys are used in REST calls**:
54-
55-
Set an admin key in the request header. You can't pass admin keys on the URI or in the body of the request. Admin keys are used for create-read-update-delete operation and on requests issued to the search service itself, such as [LIST Indexes](/rest/api/searchservice/indexes/list) or [GET Service Statistics](/rest/api/searchservice/get-service-statistics/get-service-statistics).
55+
Set an admin key in the request header. You can't pass admin keys on the URI or in the body of the request.
5656

5757
Here's an example of admin API key usage on a create index request:
5858

5959
```http
60+
@baseUrl=https://my-demo-search-service.search.windows.net
61+
@adminApiKey=aaaabbbb-0000-cccc-1111-dddd2222eeee
62+
6063
### Create an index
6164
POST {{baseUrl}}/indexes?api-version=2025-09-01 HTTP/1.1
6265
Content-Type: application/json
@@ -71,7 +74,7 @@ POST {{baseUrl}}/indexes?api-version=2025-09-01 HTTP/1.1
7174
}
7275
```
7376

74-
Set a query key in a request header for POST, or on the URI for GET. Query keys are used for operations that target the `index/docs` collection: [Search Documents](/rest/api/searchservice/documents/search-get), [Autocomplete](/rest/api/searchservice/documents/autocomplete-get), [Suggest](/rest/api/searchservice/documents/suggest-get), or [GET Document](/rest/api/searchservice/documents/get).
77+
Set a query key in a request header for POST, or on the URI for GET. Query keys are used for operations that target the `index/docs` collection: [Search Documents](/rest/api/searchservice/documents/search-get), [Autocomplete](/rest/api/searchservice/documents/autocomplete-get), [Suggest](/rest/api/searchservice/documents/suggest-get), or [GET Document](/rest/api/searchservice/documents/get).
7578

7679
Here's an example of query API key usage on a Search Documents (GET) request:
7780

@@ -83,26 +86,69 @@ GET /indexes/my-new-index/docs?search=*&api-version=2025-09-01&api-key={{queryAp
8386
> [!NOTE]
8487
> It's considered a poor security practice to pass sensitive data such as an `api-key` in the request URI. For this reason, Azure AI Search only accepts a query key as an `api-key` in the query string. As a general rule, we recommend passing your `api-key` as a request header.
8588
86-
### [**PowerShell**](#tab/azure-ps-use)
89+
### [**Python**](#tab/python-use)
90+
91+
It's a best practice to set the API key as an environment variable, but for simplicity, this example shows it as a string. The example uses a query API key for a query operation.
92+
93+
```python
94+
# Import libraries
95+
from azure.core.credentials import AzureKeyCredential
96+
from azure.identity import DefaultAzureCredential, AzureAuthorityHosts
97+
98+
# Variables for endpoint, keys, index
99+
search_endpoint: str = "https://<Put your search service NAME here>.search.windows.net/"
100+
credential = AzureKeyCredential("Your search service query key")
101+
index_name: str = "hotels-quickstart-python"
102+
103+
# Set up the client
104+
search_client = SearchClient(endpoint=search_endpoint,
105+
index_name=index_name,
106+
credential=credential)
107+
108+
# Run the query
109+
results = search_client.search(query_type='simple',
110+
search_text="*" ,
111+
select='HotelName,Description,Tags',
112+
include_total_count=True)
113+
114+
print ('Total Documents Matching Query:', results.get_count())
115+
for result in results:
116+
print(result["@search.score"])
117+
print(result["HotelName"])
118+
print(result["Tags"])
119+
print(f"Description: {result['Description']}")
120+
```
87121

88-
**How API keys are used in PowerShell**:
122+
### [**PowerShell**](#tab/azure-ps-use)
89123

90124
Set API keys in the request header using the following syntax:
91125

92-
```azurepowershell
126+
```powershell
93127
$headers = @{
94128
'api-key' = '<YOUR-ADMIN-OR-QUERY-API-KEY>'
95129
'Content-Type' = 'application/json'
96130
'Accept' = 'application/json' }
97131
```
98132

99-
A script example showing API key usage for various operations can be found at [Quickstart: Create an Azure AI Search index in PowerShell using REST APIs](search-get-started-text.md).
133+
Use a variable to contain the fully qualified query:
134+
135+
```powershell
136+
$url = '<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart/docs?api-version=2025-09-01&search=attached restaurant&searchFields=Description,Tags&$select=HotelId,HotelName,Tags,Description&$count=true'
137+
```
138+
139+
Send the request to the search service:
140+
141+
```powershell
142+
Invoke-RestMethod -Uri $url -Headers $headers | ConvertTo-Json
143+
```
144+
145+
More script examples for other operations can be found at [Quickstart: Create an Azure AI Search index in PowerShell using REST APIs](search-get-started-text.md).
100146

101147
### [**Portal**](#tab/portal-use)
102148

103-
**How API keys are used in the Azure portal**:
149+
Recall that key authentication is enabled by default and supports data plane operations such as indexing and queries.
104150

105-
Key authentication applies to data plane operations such as indexing and queries. It's enabled by default. However, if you [disable API keys](search-security-enable-roles.md#disable-api-key-authentication) and set up role assignments, the Azure portal uses role assignments instead.
151+
However, if you [disable API keys](search-security-enable-roles.md#disable-api-key-authentication) and set up role assignments, the Azure portal uses role assignments instead.
106152

107153
---
108154

0 commit comments

Comments
 (0)