Skip to main content

How to Create an Azure Cosmos DB Serverless Account Without Keys

· 13 min read
Jagdish Kumawat
Founder @ Dewiride

An Azure Cosmos DB account in serverless mode costs nothing while it sits idle, and with key-based authentication turned off, nobody can reach its data with a copied key. Here's how to create one in the Azure portal, step by step, and the same with one Azure CLI command.

Azure Cosmos DB is Microsoft's NoSQL database service. Its top level is the account: an account holds databases, a database holds containers, and a container holds your data as JSON items. This post creates the account, with two choices made on purpose:

  • Serverless. Microsoft's documentation: you're charged only for the request units (RUs) that your database operations consume and for the storage that your data consumes, with no minimum charge and no capacity planning required. A request unit is Cosmos DB's measure of the work one request does.
  • Key-based authentication off. A new account comes with keys, and a key opens every database in the account for anyone who has a copy. With keys off, the account accepts only Microsoft Entra ID identities, such as your own account or an app's managed identity, and each one gets exactly the role you give it.

My example is the database of a small notes app: an account named cosmos-howto-4224 in East US 2.

What It Costs​

A serverless account is billed for request units and storage. In East US 2, on the day I wrote this, the retail price was $0.25 per million request units and $0.25 per GB per month of storage. An empty account costs nothing.

For scale: in the notes app, creating a small note cost 5.9 RU, saving it again 10.29 RU and reading it back 1 RU. A million request units, $0.25, cover about 100,000 to 170,000 writes of a note that small.

Cosmos DB also has a free tier, but free tier is currently not available for serverless accounts, and a subscription can have only one free-tier account.

Prerequisites​

  • An Azure subscription, and a role that can create resources in it, such as Contributor on the resource group you'll use.
  • The Azure CLI, signed in with az login, for the CLI route and for deleting the account at the end.

Step 1: Find Azure Cosmos DB in the Marketplace​

In the Azure portal, select Create a resource. Type Azure Cosmos DB in the search box and press Enter. Select the Azure Cosmos DB card from Microsoft:

The Marketplace search for Azure Cosmos DB showing 116 results, with the first card, Azure Cosmos DB by Microsoft, an Azure Service described as a globally-distributed, multi-model database service, outlined in red, next to Azure Cosmos DB for MongoDB, Azure Cosmos DB Reserved Capacity and Azure Cosmos DB for PostgreSQL

The card opens the product's page. Leave the Plan as Azure Cosmos DB and select Create:

The Azure Cosmos DB product page from Microsoft with a rating, Add to Favorites, Azure benefit eligible, the Subscription list showing My Subscription, the Plan list showing Azure Cosmos DB, and the Create button outlined in red

Step 2: Choose Azure Cosmos DB for NoSQL​

The portal asks Which API best suits your workload? Each account speaks one API, and as the page says, the API selection cannot be changed after account creation. Select Create under Azure Cosmos DB for NoSQL, the service's own API for JSON documents, with client libraries for .NET, JavaScript, Python and Java:

The Which API best suits your workload? page with the Recommended APIs tab open and two cards, Azure Cosmos DB for NoSQL, outlined in red with its Create button, described as Azure Cosmos DB's core, or native API for working with documents, and Azure DocumentDB with MongoDB compatibility

Step 3: Fill In the Basics​

On the Basics tab, set these values and leave the rest as they are:

SettingValueWhy
Workload TypeDevelopment / TestingIt only picks the starting defaults; as the form says, you can customize each setting
SubscriptionYour subscription
Resource GroupAn existing group, or Create newMine already existed
Account NameA name of your own, such as cosmos-notes- and a suffixOnly lowercase letters, numbers and hyphens, 3 to 44 characters. It becomes the account's address, https://<name>.documents.azure.com, so it must be unique in all of Azure. Mine is cosmos-howto-4224
Availability ZonesDisableZone redundancy costs extra; for a serverless account it can only be turned on when you create it
LocationA region near your usersMine is (US) East US 2. The list shows only the regions your subscription can use
Capacity modeServerlessPay per request, with no minimum

The Basics tab with Workload Type Development / Testing, Subscription My Subscription, Resource Group rg-maf-servicedesk, Account Name cosmos-howto-4224 with a green check, Availability Zones Disable, Location (US) East US 2 and Capacity mode Serverless, with the account name, the location and Serverless outlined in red

Serverless changes what the form offers. Microsoft's documentation lists what isn't available with it: the free tier discount, the total throughput limit, geo-redundancy and multi-region writes. A serverless account can run only in a single Azure region, so the region you pick here is the account's only one.

Step 4: Turn Off Key-Based Authentication​

The Global distribution, Networking and Backup Policy tabs can keep their defaults. Open the Security tab and set Key-based Authentication to Disable:

The Security tab with Key-based Authentication set to Disable, outlined in red, under the explanation Key-based authentication uses account keys that are granted permissions to the entire Cosmos DB account. Disabling these methods improves security by ensuring that Cosmos DB database accounts exclusively require Entra ID identities for authentication.

With keys off, every request for data needs a Microsoft Entra ID identity that has a Cosmos DB data role, and that includes you. Creating the account doesn't give you one: your Azure role lets you manage the account, not read its data. You give yourself a data role with one Azure CLI command, which How to Give Your Account Access to Azure Cosmos DB Data with the Azure CLI walks through.

Step 5: Review and Create​

Select Review + create. Wait for Validation Success, then check the summary: Capacity mode is Serverless and Key-based Authentication is (new) Disable:

The Review + create tab with Validation Success, an estimated account creation time of 3 minutes, and the summary: Subscription My Subscription, Resource Group rg-maf-servicedesk, Location East US 2, Account Name (new) cosmos-howto-4224, API Azure Cosmos DB for NoSQL, Capacity mode Serverless, Availability Zones Disable, Backup policy Periodic with geo-redundant backup storage, Key-based Authentication (new) Disable and Data Encryption Service Managed

Select Create. The portal estimated 3 minutes; mine was ready in under two:

The deployment page with Your deployment is complete, the deployment name, My Subscription, the resource group rg-maf-servicedesk, a start time of 11/24/2026, 7:43:58 AM, and the Go to resource button outlined in red

Step 6: Copy the Account's URI​

Select Go to resource. The Essentials on the account's Overview show its state, its region, Capacity mode Serverless and its URI, the address apps connect to:

The Essentials of the account's Overview: Status Online, Resource group rg-maf-servicedesk, Subscription My Subscription, Read and Write Locations East US 2, Free Tier Discount Opted Out, Capacity mode Serverless, and the URI https://cosmos-howto-4224.documents.azure.com:443/ outlined in red

Copy the URI. With keys off, it's the only address an app needs: the app signs in with Microsoft Entra ID instead of sending a key, as in How to Connect to Azure Cosmos DB with Microsoft Entra ID in C#. The account is still empty: How to Create a Database and Container in Azure Cosmos DB Data Explorer adds the first container.

Do It with the Azure CLI​

One command creates the same kind of account. I ran it for a second account, cosmos-maf-servicedesk-cli-4224, in the same resource group:

Terminal
az cosmosdb create \
--name cosmos-maf-servicedesk-cli-4224 \
--resource-group rg-maf-servicedesk \
--locations regionName=eastus2 failoverPriority=0 isZoneRedundant=False \
--capabilities EnableServerless \
--disable-local-auth true \
--query "{name:name, endpoint:documentEndpoint, keyBasedAuthDisabled:disableLocalAuth, capabilities:capabilities[].name}"
  • --name is the account name, with the same rules as in the portal. Use your own.
  • --resource-group is the group that holds the account. Use your own.
  • --locations gives the account its region: regionName=eastus2, failoverPriority=0 (the write region; a serverless account has only this one) and isZoneRedundant=False.
  • --capabilities EnableServerless makes it a serverless account.
  • --disable-local-auth true turns key-based authentication off.
  • --query picks the fields to print, so the output isn't hundreds of lines of settings.

The command waits until the account exists. Mine took 71 seconds:

Output
{
"capabilities": [
"EnableServerless"
],
"endpoint": "https://cosmos-maf-servicedesk-cli-4224.documents.azure.com:443/",
"keyBasedAuthDisabled": true,
"name": "cosmos-maf-servicedesk-cli-4224"
}

keyBasedAuthDisabled is true and the only capability is EnableServerless: the same account as the portal made.

Cleanup: Delete the Account​

Deleting the account deletes every database, container and item in it, and can't be undone. When you no longer need it, delete it with its name and resource group:

Terminal
az cosmosdb delete --name cosmos-maf-servicedesk-cli-4224 --resource-group rg-maf-servicedesk --yes

--yes skips the Are you sure? question. The command prints nothing and waits until the deletion finishes, which took 750 seconds, 12½ minutes, for my account. Once it returns, the account no longer costs anything.

Common Mistakes​

MistakeWhat happensDo this instead
Leaving key-based authentication on because it's easierAnyone who copies a key can read and write every database in the accountTurn keys off and give each identity a data role
Expecting to read data right after creating the accountData Explorer and apps get Request blocked by Auth … does not have required RBAC permissionsGive your account a data role first
Choosing Provisioned throughput for a database that's idle most of the dayYou pay for the throughput every hour, whether it's used or notChoose Serverless
Picking another API by accidentThe API can't be changed after the account is createdDelete the account and create it again with Azure Cosmos DB for NoSQL

Troubleshooting​

SymptomLikely causeFix
The account name has no green checkThe name is taken, too short or too long, or has characters other than lowercase letters, numbers and hyphensAdd a suffix of your own
The region you want is greyed outAs the form says, the regions depend on your subscription's accessChoose another region near your users, or follow the form's link to request access to that region
Request blocked by Auth … readMetadata in Data ExplorerNo data role for your account (Fixed)Assign a data role with the Azure CLI

FAQ​

How do apps connect if there are no keys?​

They sign in with Microsoft Entra ID: on your computer with your Azure CLI sign-in, in Azure with a managed identity. Each identity needs a Cosmos DB data role on the account, a database or a container.

Is there a free way to try Cosmos DB?​

Not with serverless, which has no free tier. A provisioned-throughput account can have the free tier, one per subscription, and the Azure Cosmos DB emulator runs on your own computer at no cost.

Can I add more regions later?​

Not to a serverless account: it isn't possible to add more Azure regions to a serverless account after you create the account.

Conclusion​

In the Azure portal, find Azure Cosmos DB under Create a resource, choose Azure Cosmos DB for NoSQL, set Capacity mode to Serverless on the Basics tab and Key-based Authentication to Disable on the Security tab, then create the account and copy its URI. With the Azure CLI, it's one az cosmosdb create with --capabilities EnableServerless and --disable-local-auth true. The account costs nothing while it's idle, and only identities you give a data role can use its data.

Additional Resources​