Power Platform · Copilot Credits

Managing Copilot Credits with Environment-Level Allocation

How Copilot credits are governed per environment in the Power Platform admin center, and how the PowerShell scripts in this repository apply exactly the same settings programmatically and at scale through the Power Platform Licensing REST API.

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.

TenantCredits purchased and pooled at tenant level.
AllocationA fixed slice of credits reserved for one environment.
Enforcement ruleDecides what happens when the slice runs out.
EnvironmentCopilot workloads consume the slice, then optionally the 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:

  1. Sign in to the Power Platform admin center as a Power Platform or Global Administrator.
  2. Open Licensing (or Capacity) and select the Copilot Credits currency summary.
  3. Choose Manage capacity, or select the target environment from the allocation list.
  4. Enter the number of credits to allocate to that environment.
  5. Set the capacity-overage behaviour — the “Draw from the available capacity in my tenant” toggle.
  6. 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.

SettingAPI fieldMeaning
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 typeBehaviour when the allocation is exhausted
TenantPoolControls whether the environment may keep consuming from the shared tenant capacity pool.
AlertRaises a notification rather than blocking consumption.
PayGoAllows overage to bill through the pay-as-you-go arrangement.
DenyBlocks 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.

ConfigurationResult
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.
Caution Disabling tenant-pool access restricts or interrupts Copilot workloads as soon as the environment's allocated credits are exhausted. Validate the behaviour in a non-production environment before applying it to production.

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.
Do not use 1–499 Values between 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
ScaleOne environment at a timeHundreds of environments from a single CSV
RepeatabilityManual clicks, easily inconsistentThe same input produces the same result every run
ReviewNo dry run-WhatIf prints the exact PATCH body before anything changes
Source controlNot versionableThe allocation CSV lives in Git as reviewable configuration
AutomationHuman in the loopRuns unattended in a pipeline, on a schedule or at environment provisioning
IdentityInteractive admin sign-inService 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

ScriptPurpose
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

Step 1Read parameters (or CSV rows) and validate the values.
Step 2Acquire an app-only token from Microsoft Entra for api.powerplatform.com.
Step 3Build the currencyAllocations JSON body and print it.
Step 4Honour -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 (or Licensing.Allocations.Read for 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.

Important A Power Platform management application receives broad tenant-management access. Use a dedicated app registration, store its secret in Azure Key Vault or an equivalent secret manager, rotate it regularly, and never commit it to source control.

12. Safety and troubleshooting

Before every production run

  • Run with -WhatIf and 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

ErrorCheck
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.
Disclaimer These scripts modify live Power Platform credit allocations and enforcement behaviour, and are provided without warranty. You remain responsible for validating capacity availability, licensing requirements, security configuration, API permissions, operational impact, and compliance with your organisation's policies.