GridBase
    Console

    Search the API reference

    Find an endpoint by name or path

    Billing

    The plans on offer, the caller's subscription, and cancelling it.

    GET/billing/plans
    GET/billing/plans/all
    GET/billing/subscription
    POST/billing/subscription/cancel
    GET/billing/subscription/checkout
    POST/billing/subscription/sync
    How billing behaves

    Authorization

    /billing/plans/all requires the admin role. It lists the plans deliberately hidden from the pricing page, which is not something an ordinary authenticated caller should be able to enumerate.

    Behaviour worth knowing

    Plans are projected, field by field, so the response cannot widen the day the Clerk SDK is upgraded.

    A plan states the limits this API enforces. rate_limit_per_minute and max_tokens come from internal/plan, the same table the sync routes apply — so a caller comparing plans can see the thing that actually differs between them from this API's point of view.

    A free trial is reported only when enabled. The upstream plan carries a trial-day count independently of the enabled flag, so a disabled trial with a leftover count would otherwise advertise a trial that does not exist.

    Stripe identifiers are dropped from the subscription: nothing in this API takes them as input.

    plan_name is null when unset, never "" — "no name recorded" and "named empty" are different facts.

    A malformed cancel body is refused, not treated as a default. This is the one request where the caller most wants to be sure what they asked for.

    The local write after a cancel is checked. Clerk is the source of truth, but the row this API reads for every subsequent /billing/subscription is the local one — so a swallowed failure there tells the caller they cancelled and then shows them an active subscription.

    subscribe is a GET. Clerk Billing subscriptions are created by Clerk's frontend SDK; this route reads the caller's Clerk id and returns a fixed instructions object. A POST that changes nothing invites a client to retry it as though it might.

    The reconciliation lives in one place. internal/subsync is shared by this package's sync route and the admin one, so the two cannot drift. A test here fails if subscription-writing queries reappear in this package.

    An unlinked account is 409, not 400. The request is well formed and the account is in a state that cannot be billed; a 400 says the caller sent something wrong, and they did not.

    List Plans

    GET/api/v2/billing/plans

    The publicly visible user plans.

    Publicly visible plans, payer type user, projected field by field rather than passed through -- so the response cannot widen the day the Clerk SDK is upgraded.

    Each plan carries limits, which is what this API enforces for it, not Clerk's billing metering.

    replays its original status.

    Errors

    502upstreamClerk could not be reached or rejected the request
    Cache
    slow tier. Only 2xx responses are stored, and a cached response
    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/billing/plans" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Try it in the Explorer

    List All Plans

    GET/api/v2/billing/plans/all

    Every user plan, including the hidden ones.

    Requires the admin role -- see the folder docs. This lists the plans deliberately hidden from the pricing page, which is not something an ordinary authenticated caller should be able to enumerate.

    meta.notes says the list includes hidden plans, so a caller cannot mistake it for the pricing-page set.

    Errors

    403forbiddencaller lacks the admin role
    502 upstream
    Cache
    not cached.
    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/billing/plans/all" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Try it in the Explorer

    Get Subscription

    GET/api/v2/billing/subscription

    The caller's subscription.

    No subscription is 200 with item: null and a warning -- the free tier is a real state, not a missing record, and it answers in the same shape as a subscribed account rather than a second one.

    Carries limits, the allowances this API enforces for the plan. Does not carry Stripe identifiers: nothing here takes them as input.

    No Clerk link is required. The lookup is by user_id, so demanding one refused this read for accounts the API itself creates -- POST /api/v2/admin/users never sets clerk_user_id -- and contradicted this route's own rule that a missing subscription is 200 with item: null.

    Errors

    401unauthorizedthe credential's user no longer exists
    Cache
    not cached.
    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/billing/subscription" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Try it in the Explorer

    Cancel Subscription

    POST/api/v2/billing/subscription/cancel

    Cancel the caller's subscription.

    immediate: false (the default, and what an absent body means) ends the subscription at the period end; true ends it now.

    A malformed body is a 400. This is the one request where the caller most wants to be sure what they asked for, so an unparseable body is not quietly read as "cancel at period end". An absent body still means period-end.

    The body is parsed regardless of Content-Length. Gating on it discarded chunked bodies -- curl piping stdin, most HTTP/2 and streaming clients send Transfer-Encoding: chunked with no length -- so {"immediate":true} silently became a period-end cancellation, which is the same silent default this route exists to remove. The local write is checked, not logged and reported as success.

    The response is the stored subscription afterwards, with a warning saying which kind of cancellation happened.

    If the local write fails

    This is the one write in v2 that cannot be atomic, because half of it is at Clerk. Clerk goes first deliberately: if the local write then fails, billing has stopped and this API still shows the subscription active, which is the safe direction to be wrong in.

    That failure is a 500 that says so, naming POST /api/v2/billing/subscription/sync as the way to reconcile. A bare 500 would read as "nothing happened", and the caller is not still subscribed.

    Errors

    400invalid_parambody is not valid JSON
    409conflictno subscription to cancel; account not linked
    500internal_errorcancelled upstream, local record not updated (`detail.cancelled_upstream: true`)
    502 upstream
    curl -X POST "https://utility-api-86672132515.us-east1.run.app/api/v2/billing/subscription/cancel" \
      -H "Authorization: $GRIDBASE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "immediate": false
      }'

    Checkout Info

    GET/api/v2/billing/subscription/checkout

    What a frontend needs to start a subscription.

    A GET, because it creates nothing. Clerk Billing subscriptions are created by Clerk's frontend SDK; this route reads the caller's Clerk id and returns a fixed instructions object. A POST that changes nothing invites a client to retry it as though it might.

    Errors

    409conflictthis account is not linked to the billing provider
    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/billing/subscription/checkout" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Response200
    {
      "meta": { "source": "clerk.billing", "notes": [...] },
      "item": {
        "provider": "clerk",
        "clerk_user_id": "user_...",
        "steps": ["render Clerk's <Pricing> component to display plans", ...]
      }
    }
    Try it in the Explorer

    Sync Subscription

    POST/api/v2/billing/subscription/sync

    Reconcile the caller's own subscription from Clerk.

    Scoped to the caller, where the admin route of the same name takes a user id. Same reconciliation -- it is literally the same function, in internal/subsync -- and the same rule about writes: every one is checked. The writes here are the user's limits and every token's rate limit, so a swallowed failure is the whole purpose of the route going missing while it answers success.

    Applies the plan's rate_limit and max_tokens, updates every existing token's rate limit, evicts the token cache so the change is immediate, and writes an audit note. A failure in any of those is reported.

    Errors

    409conflictthis account is not linked to the billing provider
    502 upstream
    curl -X POST "https://utility-api-86672132515.us-east1.run.app/api/v2/billing/subscription/sync" \
      -H "Authorization: $GRIDBASE_API_KEY"