How Usage-Based Billing Works for Third-Party AI Applications: A Technical Look at Linked Billing

    This article examines "linked billing," an OAuth-based beta capability that lets users of a third-party AI application bill large language model calls directly to their own cloud organization instead of paying the developer, who then resells the usage. It explains the structural problems of the shared-key model (credential exposure, mismatched cost ownership, no hard spending limit, unclear governance boundaries), walks through the authorization-code flow with PKCE and Admin/Billing role verification, covers spending caps and unlinking, and shows how to choose the billing owner per request. It closes with the key security caveat: requests still run inside the developer's organization, so the developer's rate limits, model access, data retention, and encryption policies apply — paying for usage does not move governance.

    1. Background: The Billing Problem With Shared Keys

    As model capabilities become more accessible, third-party applications for AI coding, workflow automation, and document processing have multiplied. Their own business logic is often simple; the core value usually comes from orchestrating and packaging the underlying model. In this architecture, three questions are hard to avoid: who calls the model, who pays for it, and how is usage reconciled?

    The conventional approach is straightforward. Developers request their own model credentials, embed them on the server side, and resell usage to customers through subscription tiers, token packages, or project pricing. This pattern ships fast and requires zero configuration on the customer side, but it carries structural flaws:

    1. Credential exposure risk. If credentials are mistakenly delivered to a browser, mobile app, or desktop client, they can be extracted from captured traffic or decompiled binaries. Once leaked, an attacker can burn through them at scale, and the loss is often only noticed when the bill arrives.
    2. Mismatched billing ownership. The developer absorbs the model cost first, then converts it into commercial terms for the customer. Customers cannot see their actual usage, while the developer carries the working-capital burden, bad debt, and refund risk.
    3. No hard spending cap. With shared credentials, customers can only be throttled by a quota system the developer builds itself; there is no way to set an upper limit on their own spending at the platform level.
    4. Blurred governance accountability. Whether a request runs under your account and organization or the developer’s determines which party’s rate limits, data retention policy, and encryption arrangements apply. The traditional model usually has no clear written agreement on this point.

    2. The Core Model: From Paying Up Front and Reselling to Whoever Consumes, Pays

    A cloud provider recently introduced a beta OAuth capability called “linked billing” in its developer documentation. The idea follows the same logic as OAuth social sign-in. Federated login lets users authorize a third party to access specific resources without handing over their account credentials; linked billing extends that authorization to the billing domain.

    Under the new model, a user links their own organization to an application from inside the third-party app. Model calls made by the app are charged directly to the user’s organization bill and paid by the user, rather than being fronted by the developer and resold. For small and mid-sized AI application teams, this potentially changes the “platform pays first, then resells” business model.

    The core differences from the traditional approach:

    Dimension Shared key / reselling model Linked billing model
    Billing entity The developer’s organization The linked user organization
    Credential handling Held and managed solely by the developer Still held by the developer, but used to call the model on the user organization’s behalf
    Customer spending cap Depends on developer-built quotas Monthly limit can be set at the platform level
    Cost risk Developer carries working capital and bad debt User pays for actual usage
    Governance policy The developer’s policy applies uniformly Requests run inside the developer’s organization — see Section 6

    One clarification: this is not “bring your own key” (BYOK). The customer never holds, pastes, or stores a key. What it does is establish an application-to-user-organization authorization link at the platform level and attribute billing according to that link.

    3. Authorization: OAuth Authorization Code Flow and Role Verification

    3.1 Role Verification Before Linking

    Not every user should be able to complete the link. Under the design of this feature, the user must hold the Admin or Billing role in their organization to authorize it. This is a necessary separation of financial duties:

    • An ordinary member of the organization cannot bind it to a third-party app on their own, even after signing in, and therefore cannot generate charges.
    • Tying the authorization action to the organization’s billing responsibilities makes internal audit and accountability easier.

    3.2 Typical Authorization Flow

    1. The user clicks an entry such as “Link your organization” inside the app.
    2. The app redirects the browser to the platform’s authorization page, where the user signs in and confirms the requested scopes.
    3. The platform verifies the user’s role in the target organization; if it passes, a one-time authorization code is issued and sent back to the app.
    4. The app’s server exchanges the code for a token, stores the token encrypted, and the link takes effect.

    A simplified flow diagram:

    1. [User clicks "Link your organization"]
    2. |
    3. v
    4. [Redirect to platform authorization page, user signs in]
    5. |
    6. v
    7. [Verify user's role in the target organization]
    8. | |
    9. Not Admin/Billing Admin/Billing
    10. | |
    11. v v
    12. [Show no-permission [User confirms scopes]
    13. message] |
    14. v
    15. [Callback to app, exchange token]
    16. |
    17. v
    18. [Link active, requests billed to user organization]

    3.3 Engineering Implementation Notes

    • Use the authorization code flow with PKCE. Public clients such as browser and mobile apps cannot safely store a client secret. Pair the authorization code flow with PKCE so that a dynamically generated code_verifier prevents an intercepted code from being misused.
    • Bind a state parameter. state should map one-to-one to the user session and be validated on callback, which protects against CSRF attacks.
    • Request the minimum scopes. Ask only for what is needed for billing linkage and avoid over-requesting in a single authorization.
    • Store tokens securely. Keep tokens server-side only, encrypted, and mapped to the local user, tenant, and organization identifiers. Never write them to logs or return them to the frontend.
    1. # Illustrative code only; platform-specific endpoints and fields are omitted
    2. def build_authorize_url(client_id, redirect_uri, session):
    3. # PKCE: a dynamically generated verifier lets public clients safely use the authorization code flow
    4. session["code_verifier"] = random_string(64)
    5. session["state"] = random_string(32) # bound to the current session, validated on callback
    6. params = urlencode({
    7. "response_type": "code",
    8. "client_id": client_id,
    9. "redirect_uri": redirect_uri,
    10. "code_challenge": s256(session["code_verifier"]),
    11. "code_challenge_method": "S256",
    12. "state": session["state"],
    13. "scope": "linked_billing", # illustrative: only the minimum scope needed for billing linkage
    14. })
    15. return f"{AUTHORIZE_ENDPOINT}?{params}"
    16. def handle_callback(request, session):
    17. # 1. Validate state to block forged callbacks
    18. if request.state != session.get("state"):
    19. raise AuthError("invalid_state")
    20. # 2. Exchange the authorization code for a token; the token stays server-side only
    21. token = token_endpoint.exchange(
    22. grant_type="authorization_code",
    23. code=request.code,
    24. redirect_uri=REDIRECT_URI,
    25. client_id=CLIENT_ID,
    26. code_verifier=session["code_verifier"],
    27. )
    28. # 3. Verify the authorization result: the user must hold the Admin or Billing role
    29. require_role(token, allowed_roles=["Admin", "Billing"])
    30. # 4. Save the token and create the app tenant -> user organization binding
    31. vault.save(user_id=session["user_id"], secret=token, purpose="linked_billing")
    32. return bind_org(tenant_id=session["tenant_id"], org_id=token.org_id)

    4. Cost Control: Spending Caps, Usage Visibility, and Unlinking at Any Time

    Linked billing hands control over cost back to the party that pays, in three ways:

    1. Monthly spending cap. On the “Linked platforms” page in the console, users can set a monthly spending limit. This is a hard constraint enforced at the platform level. Applications in the beta stage must set a cap, and it may not exceed $50 per month.
    2. Cost transparency. The same page shows the charges generated by each linked application. For the first time, users can see per application “which tool cost how much” instead of a single lump-sum subscription fee.
    3. Unlink at any time. The link is not irreversible; users can unlink whenever they want. After unlinking, the application can no longer make billable calls under that user’s organization.

    The mechanism also places clear demands on application developers:

    • The link must be confirmed as still active before each call;
    • The app must anticipate degraded behavior when the quota is exhausted or the user unlinks, for example by stopping the service, prompting the user to top up, or switching to developer-funded billing with the user’s consent.

    For customers, pay-per-use also raises a new budgeting question. If several teams inside an organization share a single organization, they need to divide it into internal cost centers. This is a new scenario for cost allocation and tagging-based governance in the AI era.

    5. Per-Request Billing Ownership: Choosing Who Pays for Each Call

    The most useful engineering property of linked billing is that the developer can choose, per model request, whether the customer or the developer pays. This makes hybrid billing possible. For example:

    • Free trial usage is covered by the developer;
    • After the trial ends, the customer pays;
    • Low-frequency, lightweight features stay developer-funded to subsidize the experience, while high-consumption features are customer-funded.

    Illustrative implementation:

    1. def resolve_billing_owner(user, request_type, config):
    2. """
    3. Billing ownership, illustrative; actual parameters follow your platform's documentation:
    4. - customer: the link is active, quota is available, and the feature is configured as customer-paid,
    5. so the customer's organization is charged
    6. - developer: no active link, quota exhausted, or the feature is configured as developer-subsidized,
    7. so the developer pays
    8. """
    9. linked = billing.is_linked(user.id)
    10. quota_ok = linked and billing.remaining_quota(user.id) > 0
    11. if request_type in config.CUSTOMER_PAID and quota_ok:
    12. return "customer"
    13. return "developer"
    14. def handle_chat(user, messages, request_type):
    15. # Whoever pays, all calls go through your own backend: user keys are never delivered to clients,
    16. # which keeps auditing, rate limiting, and content safety controls in place
    17. return model_client.chat(
    18. model=config.MODEL,
    19. messages=messages,
    20. billing_owner=resolve_billing_owner(user, request_type, config),
    21. user_metadata={"tenant_id": user.tenant_id}, # illustrative: tenant identifier for usage reconciliation
    22. )

    Three principles matter when implementing per-request billing ownership:

    • Decide on the server; the client only passes semantics. Billing ownership must be computed server-side from link status, quota, and plan rules. The client should only send business semantics such as “feature type” and must never decide who pays, otherwise a malicious user can shift costs onto someone else.
    • Have a fallback. When the customer’s quota runs out or the user unlinks, there must be defined behavior — pause the service, prompt for a top-up, or switch to developer-funded billing — so requests do not fail unpredictably.
    • Keep the user experience consistent. Regardless of who pays, model choice, context length, and response quality should not be quietly degraded based on the paying party.

    6. Security and Compliance Boundaries: Migrating Billing Is Not Migrating Governance

    This is the most easily overlooked part of linked billing. According to the official explanation, requests under linked billing actually run inside the developer’s own organization. The developer’s rate limits, model access permissions, service tiers, data retention policies, and encryption keys therefore all apply. Customer-specific arrangements such as their own zero data retention (ZDR), business associate agreements, or customer-managed encryption keys (CMEK) do not automatically apply to these requests.

    This rule is fully consistent with the basic logic of account and resource ownership: whichever organization executes the request, that organization’s governance policy applies. Three conclusions follow:

    1. “Who pays” is not the same as “who governs.” Even if the customer bears the cost, data is still handled under the developer’s organization policy. For heavily regulated scenarios such as healthcare, finance, and government, the customer’s compliance requirements cannot be assumed to be satisfied merely because the customer pays.
    2. Sensitive customers need separate assessment. For customers that require zero data retention, a dedicated data processing agreement, or their own encryption keys, their needs should be met through isolated deployment or a custom arrangement, with data flows, retention periods, and responsibility boundaries spelled out in the contract.
    3. Transparent disclosure is a prerequisite. The Terms of Service, the authorization page, and product documentation should clearly state that requests run in the service provider’s organization, so the customer’s authorization is based on informed consent.

    7. Engineering Best Practices

    1. Minimize authorization and obtain explicit consent. Request only the permissions you need, and before linking, tell the customer on a dedicated page that usage will be billed to their organization at actual consumption, and get explicit confirmation. Do not let users click a “one-click link” button without understanding the consequences.
    2. Send budget alerts early. Proactively notify administrators at thresholds such as 80% and 95% of the customer’s monthly budget so that exhausted quota does not interrupt business abruptly.
    3. Carry the tenant identifier across the whole pipeline. Include a tenant identifier in request metadata and combine it with call logs and monitoring metrics to track usage and cost per customer, providing a basis for reconciliation and product pricing.
    4. Store link state reliably. Record the link’s creation time, granted scopes, and the latest refresh result; set up alerts for token expiration and unlinking events, and support automatic degradation.
    5. Never expose keys to the frontend. However billing is attributed, route all calls through your own backend. This centralizes content safety, audit trails, and rate control, and makes migration between model providers smoother.

    8. Current Limitations and Outlook

    Objectively, linked billing is still in beta and has the following limitations today:

    • Beta applications are required to set a monthly limit of no more than $50, which is not yet suitable for large-scale production workloads;
    • Someone in the customer organization must hold the Admin or Billing role, or authorization cannot be completed;
    • When the customer unlinks or exhausts the quota, the application must rely on its own degradation logic;
    • The customer’s data governance needs do not transfer automatically with the payment relationship.

    Over a longer horizon, linked billing reflects a trend in AI application commercialization: model calls are moving from bundled resale to metered settlement, much as cloud computing moved from renting whole machines to pay-as-you-go. Whoever consumes pays; whoever runs governs. These are becoming two basic principles of AI application architecture design. Developers should bring billing ownership, quota control, and governance boundaries into the architecture early, rather than patching them after the bills and compliance questions arrive.