1. The Copilot credit model
Copilot capabilities in Power Platform — Copilot Studio messages, agent actions, generative answers and related AI features — are metered in Copilot Credits. Credits are purchased at the tenant level and land in a shared tenant capacity pool.
Without governance, any environment can consume from that shared pool. One busy test environment or a runaway agent can therefore burn credits that a production workload depends on. Environment-level allocation is the control that fixes this: it lets an administrator reserve a fixed number of credits for an environment and decide whether that environment may reach past its reservation into the tenant pool.
Predictable spend
Each environment gets a ceiling, so a single project cannot consume the tenant's entire credit balance.
Protected production
Dev, test and sandbox environments can be fenced off so production keeps access to pooled capacity.
Chargeback clarity
Allocations map credits to business units, making internal cost attribution straightforward.
2. Setting it in the Power Platform admin center
The manual path an administrator would normally take:
- Sign in to the Power Platform admin center as a Power Platform or Global Administrator.
- Open Licensing (or Capacity) and select the Copilot Credits currency summary.
- Choose Manage capacity, or select the target environment from the allocation list.
- Enter the number of credits to allocate to that environment.
- Set the capacity-overage behaviour — the “Draw from the available capacity in my tenant” toggle.
- Save, and repeat the whole sequence for every remaining environment.
That last step is the problem. The portal is fine for one environment, but the workflow is manual, click-heavy, easy to get wrong, hard to review, and has no repeatability across dozens or hundreds of environments.
3. What each setting actually controls
Behind the portal UI, every environment allocation is made up of three values.
| Setting | API field | Meaning |
|---|---|---|
| Currency type | currencyType |
Which metered currency is being allocated, for example MCSMessages for Copilot Studio messages/credits. The currency must already exist for the environment. |
| Allocated credits | allocated |
The fixed number of credits reserved for the environment. |
| Enforcement rule | enforcementRules[].ruleType + enabled |
What happens once the allocation is consumed — alert, pay-as-you-go, draw from the tenant pool, or deny. |
Enforcement rule types
| Rule type | Behaviour when the allocation is exhausted |
|---|---|
TenantPool | Controls whether the environment may keep consuming from the shared tenant capacity pool. |
Alert | Raises a notification rather than blocking consumption. |
PayGo | Allows overage to bill through the pay-as-you-go arrangement. |
Deny | Blocks further consumption. |
The TenantPool toggle
The TenantPool rule is the direct equivalent of the portal's
“Draw from the available capacity in my tenant” switch.
| Configuration | Result |
|---|---|
TenantPool enabled = true |
The environment may draw from available tenant capacity after its own allocation is used up. |
TenantPool enabled = false |
The environment cannot draw from tenant capacity. Once its allocation reaches zero, Copilot consumption stops there. |
4. Allocation value rules
The API accepts only certain allocation values:
0— allocate no environment-specific credits.- Any value greater than or equal to 500, for example
500,1000,2500.
1 and 499 are rejected. The requested allocation must also be
available in the tenant — the API will refuse an allocation that exceeds the tenant's remaining capacity.
5. Why do this programmatically
| Admin center (manual) | Scripts in this repository | |
|---|---|---|
| Scale | One environment at a time | Hundreds of environments from a single CSV |
| Repeatability | Manual clicks, easily inconsistent | The same input produces the same result every run |
| Review | No dry run | -WhatIf prints the exact PATCH body before anything changes |
| Source control | Not versionable | The allocation CSV lives in Git as reviewable configuration |
| Automation | Human in the loop | Runs unattended in a pipeline, on a schedule or at environment provisioning |
| Identity | Interactive admin sign-in | Service principal with a scoped app registration |
6. The underlying API
The scripts call the Microsoft Power Platform Licensing REST API directly.
Read current allocations
GET https://api.powerplatform.com/licensing/allocationsByEnvironment/{environmentId}?api-version=2024-10-01
Update allocations
PATCH https://api.powerplatform.com/licensing/allocationsByEnvironment?api-version=2024-10-01
Request body
{
"environmentId": "00000000-0000-0000-0000-000000000000",
"currencyAllocations": [
{
"currencyType": "MCSMessages",
"allocated": 0,
"enforcementRules": [
{
"ruleType": "TenantPool",
"enabled": false
}
]
}
]
}
Reference: Get Allocations By Environment · Update Allocations By Environment
7. What the scripts do
| Script | Purpose |
|---|---|
Set-PowerPlatformSingleEnvironmentAllocation.ps1 |
Sets the credit allocation and enforcement rule for one environment. |
Set-PowerPlatformEnvironmentAllocationsFromCsv.ps1 |
Applies allocation settings to many environments from a CSV file, authenticating once and issuing one PATCH per row. |
Execution flow
api.powerplatform.com.currencyAllocations JSON body and print it.-WhatIf, or send the PATCH and return the API response.
The client secret is taken as a PowerShell SecureString, converted in memory only at the
moment the token is requested, and cleared immediately afterwards — it never appears in a script
file, a CSV, or the command line.
8. Updating a single environment
Always preview first with -WhatIf:
$clientSecret = Read-Host "Enter client secret" -AsSecureString
.\Set-PowerPlatformSingleEnvironmentAllocation.ps1 `
-EnvironmentId "00000000-0000-0000-0000-000000000000" `
-TenantId "11111111-1111-1111-1111-111111111111" `
-ClientId "22222222-2222-2222-2222-222222222222" `
-ClientSecret $clientSecret `
-CurrencyType MCSMessages `
-Allocated 0 `
-EnforcementRuleType TenantPool `
-EnforcementRuleEnabled $false `
-WhatIf
Review the printed PATCH body. If it is correct, run the same command without -WhatIf to apply it.
9. Updating many environments from CSV
The CSV describes the desired allocation state for the whole estate:
EnvironmentId,Allocated,EnforcementRuleType,EnforcementRuleEnabled
00000000-0000-0000-0000-000000000000,0,TenantPool,false
11111111-1111-1111-1111-111111111111,500,TenantPool,true
22222222-2222-2222-2222-222222222222,1000,Alert,true
The -CurrencyType parameter applies to every row.
$clientSecret = Read-Host "Enter client secret" -AsSecureString
.\Set-PowerPlatformEnvironmentAllocationsFromCsv.ps1 `
-CsvPath ".\examples\allocations.example.csv" `
-TenantId "11111111-1111-1111-1111-111111111111" `
-ClientId "22222222-2222-2222-2222-222222222222" `
-ClientSecret $clientSecret `
-CurrencyType MCSMessages `
-WhatIf
PowerShell prints one What if message per environment. Remove -WhatIf to apply.
Because the CSV is a plain text file, it can be committed, diffed and pull-request reviewed like any
other configuration — the allocation plan becomes code.
10. Common scenarios
Fence off a non-production environment completely
Stop a sandbox from consuming any Copilot credits, including pooled tenant capacity:
Allocated = 0
EnforcementRuleType = TenantPool
EnforcementRuleEnabled = false
Give a project a fixed budget with no overage
Reserve credits, but do not let the environment exceed them:
Allocated = 1000
EnforcementRuleType = TenantPool
EnforcementRuleEnabled = false
Reserve credits but allow burst from the pool
Typical production configuration — a guaranteed baseline plus access to spare tenant capacity:
Allocated = 2500
EnforcementRuleType = TenantPool
EnforcementRuleEnabled = true
Monitor without blocking
Let the workload continue but raise a notification on overage:
Allocated = 500
EnforcementRuleType = Alert
EnforcementRuleEnabled = true
11. Prerequisites
- PowerShell 5.1 or newer.
- A Microsoft Entra app registration with a client secret.
- Power Platform API permission
Licensing.Allocations.ReadWrite(orLicensing.Allocations.Readfor read-only), with admin consent granted. - The service principal registered as a Power Platform management application via
New-PowerAppManagementApp. - Power Platform administrative access in the tenant.
The Power Platform API application ID is 8578e004-a5c6-46e7-913e-12f58912df43.
Full step-by-step setup instructions are in the repository
README.
12. Safety and troubleshooting
Before every production run
- Run with
-WhatIfand read the PATCH body. - Review the CSV contents and confirm each environment ID.
- Confirm the tenant has enough remaining capacity for the requested allocations.
- Test the enforcement-rule change in a non-production environment first.
Common errors
| Error | Check |
|---|---|
403 Forbidden |
Secret not expired; admin consent granted; correct tenant; service principal registered with New-PowerAppManagementApp; app authorised to update licensing allocations. |
UnknownError |
Currency type already exists for the environment; allocation is 0 or at least 500; tenant has sufficient capacity; no empty ruleType; EnforcementRuleEnabled is true or false. |
| Invalid CSV row | Valid environment GUID; allocation 0 or at least 500; supported enforcement rule type; boolean true/false. |