Copilot Quota and AI consumption in Business Central.

Agents and a growing set of AI features in Business Central are no longer free to run without limits. They are billed in Copilot Credits (the new AI money💸 in Redmond😅), and when an environment runs out of capacity, AI features simply stop working until an admin adds more.

The System Application ships a small codeunit that sits right on that boundary: codeunit 7785 “Copilot Quota”. For a cloud extension it exposes a single method, CanConsume(). Behind it there’s an internal implementation and a background task that drives the quota notifications on the Copilot & agent capabilities page.

It follows the usual facade pattern of the System Application: a thin public codeunit that delegates every call to an internal implementation codeunit.

ObjectIDAccessRole
Codeunit “Copilot Quota”7785PublicFacade you call from your code
Codeunit “Copilot Quota Impl.”7786InternalTalks to the platform through the ALCopilotFunctions .NET type
Codeunit “Copilot Notifications”–InternalShows the “capacity used up” and “nearly used up” notifications
Page “Copilot AI Capabilities”––Runs the Impl codeunit as a page background task

CanConsume() is the procedure of the codeunit you can call from a cloud extension:

It asks the platform for the tenant’s quota details and returns whether the tenant is still allowed to consume Copilot capacity. More in details:

  • If the platform can’t return quota details, the method returns false. On-premises or in a Docker sandbox you should not expect true, so don’t gate features on it outside SaaS.
  • It emits telemetry every time (0000P7N as a warning, 0000P7O as normal). The scope is ExtensionPublisher and the category is the Copilot category. Calling it in a tight loop produces telemetry noise, so call it once per user action.

The Impl codeunit also has an OnRun trigger. It collects three values from the platform and hands them back as a page background task result:

This is how the Copilot & agent capabilities page knows whether to warn you, without slowing down page load. The Impl codeunit is internal, so you can’t enqueue it from your own pages.

Two callers reach the platform’s quota service: your extension through the public facade, and the capabilities page through the internal implementation:

Your extension can only ask whether the tenant can consume. The capabilities page skips the facade and runs the Impl codeunit as a background task, then turns its three values into notifications. If billing is set up, the 80% warning is suppressed.

Using CanConsume() in your own extensions.

For a partner, CanConsume() is a pre-flight check. It matters most when your capability runs on the Business Central AI resources (SetManagedResourceAuthorization), because those calls consume the customer’s Copilot Credits. If you bring your own Azure OpenAI resource, Copilot Credits aren’t consumed and the check is less relevant.

Personal suggestion is to wrap the check once, so every feature behaves the same way and you skip it outside SaaS, where CanConsume() returns false. For example:

Perform the check before you build the prompt and call the model. The user gets a clear message instead of a generic failure from the Azure OpenAI call:

In unattended processing (Job Queue), check once before the loop, not per record. If quota is gone, log it and exit. The job queue entry ends without an error, the documents stay Pending, and the next scheduled run picks them up. An error on every run would only fill the job queue log and hide real failures:

Beyond quota: tracking AI consumption.

CanConsume() tells you whether you can call the model. To know who pays and how much you consume, System.AI has three more public tools.

Since version 27.0, you can declare who bills a capability when you register it. Enum 7786 “Copilot Billing Type” has three usable values:

ValueMeaning
Not BilledThe capability is free for the customer
Microsoft BilledMicrosoft bills it, in Copilot Credits
Custom BilledYou, the publisher, bill it

A fourth value, Undefined, is for internal use only. The old RegisterCapability and ModifyCapability overloads without a billing type are obsolete: they store the billing type as Undefined and disappear once CLEAN27 code is removed.

The value is stored in the “Copilot Settings” table and shown in the Billing Type column on the capabilities page. It’s also added as a BillingType dimension to the capability’s telemetry. To change it in a later version, call ModifyCapability from an upgrade codeunit.

Regarding tokens, codeunit 7759 “AOAI Token” gives you two different views of token usage:

MethodWhenWhat it measures
GetGPT4TokenCount, GetGPT35TokenCount, GetAdaTokenCount, GetDavinciTokenCountBefore the callA local estimate of the input, using the cl100k_base or p50k_base tokenizer
GetTotalServerSessionTokensConsumedAfter the callActual tokens consumed in the session, as counted by the platform. The total tokens used is aggregated for all the models.

On the chat messages side, AOAIChatMessages.GetHistoryTokenCount() and SetHistoryLength() keep the context you send under control.

Regarding GetTotalServerSessionTokensConsumed, remember that:

  • It’s cumulative for the server session, across all models. There’s no split by prompt and completion, capability or app.
  • Every session has its own counter (a web client session, a background session, a job queue task, a page background task).

Because the counter is cumulative, read it before and after your call and log the difference:

The actual delta minus the estimated prompt tokens gives a rough figure for the output tokens. That’s enough to set a token budget per operation.

If your capability is Custom Billed, this delta is also the starting point for your own metering. Store it per company and capability in a table you control, not only in telemetry, so your invoices don’t depend on telemetry sampling or retention.

What’s left in telemetry.

Two signals give you the consumption picture in Application Insights:

SignalEmitted byWhat it carries
0000LT4“Azure OpenAI Impl”, on every chat, completion or embeddings callEstimated metaprompt, prompt and total token counts
RT0055 “AI Consumption Recorded”The platformCopilot Credits consumed, with copilotCredits, agentTaskId, actions and featureName

RT0055 appears in environment telemetry for every feature with consumption-based billing. In extension telemetry it only covers agents that are published to the environment as part of your app.

Conclusion

“Copilot Quota” codeunit combined with the billing type, the token counters in “AOAI Token” and the consumption telemetry, it gives you what you need to keep AI costs visible. It also lets you build features that tell the user what’s going on when capacity runs out, instead of failing with a cryptic error.

  1. Before the call: declare the right billing type, check CanConsume() and estimate the prompt with “AOAI Token”.
  2. During the call: read GetTotalServerSessionTokensConsumed() before and after, and log the delta.
  3. After the call: follow 0000LT4 and RT0055 in Application Insights to see what each feature really costs.

With this in place, your AI features tell users clearly when capacity runs out. You can now also answer the question every customer will soon ask: how much is Copilot costing us, and for what? 😅

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.