Skip to content

Agent Costs Power Platform Access

Sam Betts edited this page Nov 4, 2026 · 2 revisions

Agent Costs Setup → Agent Costs Power Platform Access

2. Copilot Studio credits

Consumption: connect the billing administrator

In 1852, consumption is delegated only, with no application-only fallback. Use the same account for portal sign-in and the billing connection, holding Portal.Administration and Power Platform Administrator or equivalent billing read access. See PII is needed to read per-person analytics, not to configure this operational connection.

  1. On the runtime app registration's Authentication → Web platform, keep the portal root URI and add https://contosoanalytics.azurewebsites.net/signin-agent-costs (synthetic). The real URI is WebAppURL.TrimEnd('/') plus /signin-agent-costs: no hash route, query or trailing slash. Register each slot/custom domain/local instance separately.
  2. Under API permissions → APIs my organization uses, select Power Platform API, public application ID 8578e004-a5c6-46e7-913e-12f58912df43. Add Delegated CopilotStudio.Licenses.Read and EnvironmentManagement.Environments.Read, then grant admin consent. If unavailable, consult Microsoft; do not invent a scope or substitute write access. The flow requests the configured permissions through https://api.powerplatform.com/.default.
  3. Configure the same Storage account and runtime identity on portal/importer. Ensure Table reachability and Storage Table Data Contributor when using Entra authentication. There is no browser-only or in-memory credential fallback.
  4. Open Administration → Copilot Studio billing connection, select Connect or reconnect an administrator, and use that same authorised account. The server checks renewal and consumption access before saving; a failed attempt preserves any previous connection.
  5. Keep CopilotStudioCredits=True and let the next scheduled importer cycle complete. A new connection permits a next-cycle retry rather than waiting behind the previous daily stamp.

The encrypted MSAL cache is in AnalyticsState / AgentCostDelegatedAuth. Restrict the partition and backups as credentials. Runtime credential rotation can require reconnecting. Disconnect stops future consumption reads, not already-running work or historical data; capacity and Azure costs remain independent.

Symptom Remedy
AADSTS50011 Register the exact Web callback sent by this instance; correct a wrong WebAppURL rather than authorising an unintended host
AADSTS650057, consent/admin approval required Add the correct Power Platform resource/delegated permissions and grant consent; start a fresh connection
Account mismatch / consumption access refused Use the same authorised account; check its billing access and Conditional Access
Storage unavailable Check Storage, Table endpoint/DNS and runtime Table permissions; do not paste refresh tokens into app settings
Reconnect needed Review consent/account access, renewal and encryption credential, then reconnect
Connection required No usable connection is configured; capacity can still import. This is not measured zero consumption

Import-outcome checks in 1852: a user-phase success flag means the user write actually completed, including a successful phase with no eligible rows. A failed user write records an error and does not publish the derived agent phase; check SQL connectivity/permissions and the import error, not only rows read. If the user phase completed but a later agent/resource phase failed, its success remains valid while the agent error needs attention. These flags do not prove tenant-wide zero consumption, and this correction changes neither retry cadence nor billing authorisation.

Scale: seven days × daily active Copilot Studio users, plus paging/retries. Synthetic examples: 10,000 active users/day means about 70,000 resource calls; 200,000 means about 1.4 million. Concurrency is six, paging is bounded, and the normal cadence is daily—not a small fixed tenant call budget. UserGroupsFilter restricts stored person rows but does not reduce these tenant-wide billing reads. See full connection/volume guidance.

Capacity: grant the runtime enterprise application Reader

For the app-only capacity path, Power Platform uses its own RBAC, separate from Azure roles. Assign Power Platform reader at tenant scope to the runtime enterprise application. This does not authorise the delegated consumption path. The installer does not create either grant for you.

Microsoft's documentation: Tutorial: Assign roles to service principals and Power Platform RBAC. Microsoft marks this feature as preview.

There is currently no admin centre screen for this. You assign the role by calling the Power Platform Authorization API. You need:

  • A person to run it who holds the Power Platform Administrator or Power Platform role-based access control administrator role.
  • Your tenant ID (Entra ID → Overview → Tenant ID).
  • The Object ID of the runtime app's enterprise application. Follow the steps below; the app registration's Object ID will not work.

Find the correct Object ID

  1. In the Entra admin centre, switch to the directory in which the runtime app is registered.
  2. Open App registrations, select the runtime app and open Overview. Copy its Directory (tenant) ID into $TenantId.
  3. On that same page, click the app's name beside Managed application in local directory. This opens the associated enterprise application.
  4. Copy the Object ID from the enterprise application's Overview page into $EnterpriseAppObjectId.

If you cannot find that link, open Enterprise applications → All applications and search using the runtime app's Application (client) ID. This avoids confusing two applications with the same display name.

Value What to use it for
Directory (tenant) ID $TenantId
Application (client) ID Finding the matching enterprise application
Object ID on the App registration Do not use for this role assignment
Object ID on the Enterprise application $EnterpriseAppObjectId

An error containing PrincipalDoesNotExist means the API cannot find the specified service principal in the specified tenant. Recheck both IDs and the selected directory. After changing either variable, rerun the script from sign-in onwards so that the token and request body are rebuilt.

Assign and verify the role

Install the sign-in module once if it is not already installed:

Install-Module Az.Accounts -Scope CurrentUser

Save the following as a .ps1 file, replace both placeholders, and run the whole script. It signs in afresh, checks for the assignment before creating it, and verifies the result. Running it again does not create another assignment. Do not run a separate verification command that depends on variables from a previously completed script: those variables are local to that script.

& {
$ErrorActionPreference = "Stop"
$TenantId = "<your tenant ID>"
$EnterpriseAppObjectId = "<enterprise application Object ID>"

# Validate and normalise the IDs before making any request.
$TenantId = ([guid]::Parse($TenantId)).ToString()
$EnterpriseAppObjectId = ([guid]::Parse($EnterpriseAppObjectId)).ToString()
if ($TenantId -eq [guid]::Empty.ToString() -or
    $EnterpriseAppObjectId -eq [guid]::Empty.ToString()) {
    throw "Replace the placeholder IDs with your tenant and enterprise application IDs."
}

$context = Connect-AzAccount -TenantId $TenantId
if ($context.Context.Tenant.Id -ne $TenantId) {
    throw "Sign-in selected a different tenant. Check the account and directory."
}
$access = Get-AzAccessToken -TenantId $TenantId `
    -ResourceUrl "https://api.powerplatform.com/"
$token = if ($access.Token -is [System.Security.SecureString]) {
    [System.Net.NetworkCredential]::new("", $access.Token).Password
} else {
    $access.Token
}
if ([string]::IsNullOrWhiteSpace($token)) {
    throw "No access token was returned. Do not continue with the role assignment."
}
$headers = @{ Authorization = "Bearer $token"; "Content-Type" = "application/json" }
$uri = "https://api.powerplatform.com/authorization/roleAssignments?api-version=2024-10-01"
$readerRoleId = "c886ad2e-27f7-4874-8381-5849b8d8a090"
$scope = "/tenants/$TenantId"

function Find-ReaderAssignment {
    $next = $uri
    $seen = @{}
    while ($next) {
        $pageUri = [uri]$next
        if ($pageUri.Scheme -ne "https" -or
            $pageUri.Host -ne "api.powerplatform.com" -or $seen.ContainsKey($next)) {
            throw "Unexpected or repeated continuation URL. Verification stopped."
        }
        $seen[$next] = $true
        $page = Invoke-RestMethod -Method Get -Headers $headers -Uri $next
        if ($null -eq $page.PSObject.Properties["value"]) {
            throw "Unexpected role-assignment response: missing value collection."
        }
        $page.value | Where-Object {
            $_.principalObjectId -eq $EnterpriseAppObjectId -and
            $_.roleDefinitionId -eq $readerRoleId -and $_.scope -eq $scope
        }
        $next = $page.nextLink
        if (-not $next) { $next = $page.'@odata.nextLink' }
    }
}

$existing = @(Find-ReaderAssignment)
if ($existing.Count -gt 0) {
    Write-Host "Verified: Power Platform reader is already assigned at tenant scope."
    $existing | Format-Table roleAssignmentId, roleDefinitionId, scope
    return
}
$body = @{
    roleDefinitionId  = $readerRoleId
    principalObjectId = $EnterpriseAppObjectId
    principalType     = "ApplicationUser"
    scope             = $scope
} | ConvertTo-Json

try {
    Invoke-RestMethod -Method Post -Headers $headers -Body $body -Uri $uri | Out-Null
} catch {
    if ($null -eq $_.Exception.Response -or
        [int]$_.Exception.Response.StatusCode -ne 409) {
        throw
    }
    Write-Warning "The API returned Conflict. Checking whether the required assignment exists."
}
$verified = @(Find-ReaderAssignment)
if ($verified.Count -eq 0) {
    throw "The reader assignment could not be verified. Allow time for propagation and rerun; if the conflict persists, contact Microsoft support."
}
Write-Host "Verified: Power Platform reader is assigned at tenant scope."
$verified | Format-Table roleAssignmentId, roleDefinitionId, scope
}

Only the Verified message confirms that the enterprise application has the reader role at the requested tenant scope. An authentication failure, failed lookup or unverified conflict stops the script instead of reporting success. Never share the access token or authorization headers.

If the POST returns HTTP 409 / Conflict: an existing assignment is one possible explanation, but the generic message does not establish the cause. The script rechecks the assignment. If it verifies the matching reader assignment at tenant scope, continue to the import check in step 5. Otherwise keep the response and any request/correlation ID privately and raise a persistent conflict with Microsoft support. Do not delete existing assignments or grant a broader role just to bypass the error.

Role verified, but the import still returns 401 or 403

A verified role assignment is not a successful licensing API test. The script checks the Authorization API, not the importer. In 1852 capacity uses the runtime application identity; consumption uses the connected administrator. Inspect which path failed before changing grants.

Microsoft's authentication guidance explicitly supports service-principal authentication through Power Platform RBAC. Its statement that Entra API permissions are delegated-only does not mean that the whole API requires a signed-in user. However, assigning a role does not establish that these specific licensing endpoints will accept the runtime app's request.

Import response What it establishes Next check
401 Unauthorized Authentication was not accepted; the status alone is not the cause. Capacity: runtime tenant/audience/credential. Consumption: connection renewal, consent, account/policy
403 Forbidden Access was refused; it does not prove the Reader assignment is absent. Capacity: verify Reader for the deployed enterprise application/tenant. Consumption: verify the connected account's billing access and delegated consent; reconnect if required

If the matching capacity grant or delegated connection is verified and the endpoint still refuses access, keep its response/correlation evidence privately for Microsoft support. A successful Entra sign-in or role lookup is not a completed import. Never share tokens/headers or tenant-specific responses, and do not use an app-only consumption test as the success criterion for the new build.

Older builds emit the same "assign the reader role" advice for every 401/403 and suggest the API may require a signed-in administrator. Those are generic suggestions, not a diagnosis based on an inspected assignment or Microsoft's response body. Updated builds distinguish 401 from 403 and explain what remains unverified.

To stop repeated failures while investigating, set CopilotStudioCredits=False in ImportJobSettings, keeping the other flags, and restart the App Service. This disables only the Copilot Studio credit import; audit/activity imports and the separate Azure cost import are unaffected. It does not fix the underlying refusal.

Optional App Service application settings:

Setting Default Meaning
CopilotStudioCreditsIntervalHours 24 Minimum hours between runs. 0 removes the limit.
CopilotStudioCreditsTrailingWindowDays 7 How many days back each run re-reads (maximum 180).

Per-agent consumption is derived from permitted per-user/resource reads and covers only usage Microsoft attributes to a person. Unattributed consumption can remain outside those rows; the capacity total is separate. These are not two independent breakdown APIs whose totals must always match.


Return to Agent Costs Setup · All topics in this guide

Previous: Agent Costs Setup · Next: Agent Costs Billing Connection

Start here

Copilot analytics

Using the portal

Install & configure

Beyond Copilot

Operate

Upgrading from an older build

Reference

Project

Clone this wiki locally