Skip to content

Latest commit

 

History

History
96 lines (73 loc) · 6.45 KB

README.md

File metadata and controls

96 lines (73 loc) · 6.45 KB

Billing

Overview

Available Operations

buyCredits

Purchases credits for a Vercel team using the default payment method on file. The purchase is charged immediately via Stripe invoice. Supported credit types are v0, gateway, and agent. The amount field specifies the number of credits to purchase and must be a positive integer. An optional source query parameter can be provided to identify the caller. Defaults to api if not specified. This is only available for Owner, Member, Developer, Security, and Billing roles for the supplied team.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.billing.buyCredits({
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      item: {
        type: "credits",
        creditType: "agent",
        amount: 890808,
      },
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { billingBuyCredits } from "@vercel/sdk/funcs/billingBuyCredits.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await billingBuyCredits(vercel, {
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      item: {
        type: "credits",
        creditType: "agent",
        amount: 890808,
      },
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("billingBuyCredits failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.BuyCreditsRequest ✔️ The request object to use for the request.
options RequestOptions ➖ Used to set various options for making HTTP requests.
options.fetchOptions RequestInit ➖ Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig ➖ Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.BuyCreditsResponseBody>

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*