PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroupName/providers/Microsoft.CognitiveServices/accounts/accountName/raiBlocklists/raiBlocklistName/raiBlocklistItems/raiBlocklistItemName?api-version=2025-06-01
{
"properties": {
"pattern": "Pattern To Block",
"isRegex": false
}
}
import com.azure.resourcemanager.cognitiveservices.models.RaiBlocklistItemProperties;
/**
* Samples for RaiBlocklistItems CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/cognitiveservices/resource-manager/Microsoft.CognitiveServices/stable/2025-06-01/examples/
* PutRaiBlocklistItem.json
*/
/**
* Sample code: PutRaiBlocklistItem.
*
* @param manager Entry point to CognitiveServicesManager.
*/
public static void
putRaiBlocklistItem(com.azure.resourcemanager.cognitiveservices.CognitiveServicesManager manager) {
manager.raiBlocklistItems().define("raiBlocklistItemName")
.withExistingRaiBlocklist("resourceGroupName", "accountName", "raiBlocklistName")
.withProperties(new RaiBlocklistItemProperties().withPattern("Pattern To Block").withIsRegex(false))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-cognitiveservices
# USAGE
python put_rai_blocklist_item.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = CognitiveServicesManagementClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.rai_blocklist_items.create_or_update(
resource_group_name="resourceGroupName",
account_name="accountName",
rai_blocklist_name="raiBlocklistName",
rai_blocklist_item_name="raiBlocklistItemName",
rai_blocklist_item={"properties": {"isRegex": False, "pattern": "Pattern To Block"}},
)
print(response)
# x-ms-original-file: specification/cognitiveservices/resource-manager/Microsoft.CognitiveServices/stable/2025-06-01/examples/PutRaiBlocklistItem.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcognitiveservices_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cognitiveservices/armcognitiveservices/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/1004eed4202d64b48157c084fe2830760f8190f4/specification/cognitiveservices/resource-manager/Microsoft.CognitiveServices/stable/2025-06-01/examples/PutRaiBlocklistItem.json
func ExampleRaiBlocklistItemsClient_CreateOrUpdate() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcognitiveservices.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewRaiBlocklistItemsClient().CreateOrUpdate(ctx, "resourceGroupName", "accountName", "raiBlocklistName", "raiBlocklistItemName", armcognitiveservices.RaiBlocklistItem{
Properties: &armcognitiveservices.RaiBlocklistItemProperties{
IsRegex: to.Ptr(false),
Pattern: to.Ptr("Pattern To Block"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.RaiBlocklistItem = armcognitiveservices.RaiBlocklistItem{
// Name: to.Ptr("raiBlocklistItemName"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroupName/providers/Microsoft.CognitiveServices/accounts/accountName/raiBlocklists/raiBlocklistName/raiBlocklistItems/raiBlocklistItemName"),
// Properties: &armcognitiveservices.RaiBlocklistItemProperties{
// IsRegex: to.Ptr(false),
// Pattern: to.Ptr("Pattern To Block"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { CognitiveServicesManagementClient } = require("@azure/arm-cognitiveservices");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
/**
* This sample demonstrates how to Update the state of specified blocklist item associated with the Azure OpenAI account.
*
* @summary Update the state of specified blocklist item associated with the Azure OpenAI account.
* x-ms-original-file: specification/cognitiveservices/resource-manager/Microsoft.CognitiveServices/stable/2025-06-01/examples/PutRaiBlocklistItem.json
*/
async function putRaiBlocklistItem() {
const subscriptionId =
process.env["COGNITIVESERVICES_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["COGNITIVESERVICES_RESOURCE_GROUP"] || "resourceGroupName";
const accountName = "accountName";
const raiBlocklistName = "raiBlocklistName";
const raiBlocklistItemName = "raiBlocklistItemName";
const raiBlocklistItem = {
properties: { isRegex: false, pattern: "Pattern To Block" },
};
const credential = new DefaultAzureCredential();
const client = new CognitiveServicesManagementClient(credential, subscriptionId);
const result = await client.raiBlocklistItems.createOrUpdate(
resourceGroupName,
accountName,
raiBlocklistName,
raiBlocklistItemName,
raiBlocklistItem,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.CognitiveServices.Models;
using Azure.ResourceManager.CognitiveServices;
// Generated from example definition: specification/cognitiveservices/resource-manager/Microsoft.CognitiveServices/stable/2025-06-01/examples/PutRaiBlocklistItem.json
// this example is just showing the usage of "RaiBlocklistItems_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this RaiBlocklistResource created on azure
// for more information of creating RaiBlocklistResource, please refer to the document of RaiBlocklistResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "resourceGroupName";
string accountName = "accountName";
string raiBlocklistName = "raiBlocklistName";
ResourceIdentifier raiBlocklistResourceId = RaiBlocklistResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, accountName, raiBlocklistName);
RaiBlocklistResource raiBlocklist = client.GetRaiBlocklistResource(raiBlocklistResourceId);
// get the collection of this RaiBlocklistItemResource
RaiBlocklistItemCollection collection = raiBlocklist.GetRaiBlocklistItems();
// invoke the operation
string raiBlocklistItemName = "raiBlocklistItemName";
RaiBlocklistItemData data = new RaiBlocklistItemData
{
Properties = new RaiBlocklistItemProperties
{
Pattern = "Pattern To Block",
IsRegex = false,
},
};
ArmOperation<RaiBlocklistItemResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, raiBlocklistItemName, data);
RaiBlocklistItemResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
RaiBlocklistItemData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue