Billing
Create a top-up checkout
Generate a hosted checkout URL to add credits to your personal balance or your team’s shared credit pool.
POST
/
api
/
v1
/
billing
/
checkout
Create a top-up checkout
curl --request POST \
--url https://api.example.com/api/v1/billing/checkout \
--header 'Content-Type: application/json' \
--data '
{
"amount_cents": 123,
"scope": "<string>",
"success_url": "<string>"
}
'import requests
url = "https://api.example.com/api/v1/billing/checkout"
payload = {
"amount_cents": 123,
"scope": "<string>",
"success_url": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({amount_cents: 123, scope: '<string>', success_url: '<string>'})
};
fetch('https://api.example.com/api/v1/billing/checkout', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/billing/checkout",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'amount_cents' => 123,
'scope' => '<string>',
'success_url' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/billing/checkout"
payload := strings.NewReader("{\n \"amount_cents\": 123,\n \"scope\": \"<string>\",\n \"success_url\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/billing/checkout")
.header("Content-Type", "application/json")
.body("{\n \"amount_cents\": 123,\n \"scope\": \"<string>\",\n \"success_url\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/billing/checkout")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount_cents\": 123,\n \"scope\": \"<string>\",\n \"success_url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_bodyTop up credits against the caller’s personal balance or an organization’s
shared team billing pool. Returns a hosted checkout URL your application
opens in a new tab or redirects the user to.
Authentication
Requires a Bearer token with thebilling scope. See
Authentication.
Body
integer
required
Amount to add, in cents. Minimum
500 (5.00),maximum‘100000‘(1,000.00).string
"user" (default when personal) or "org" (default when the caller is
inside a team and holds manageBilling). When "org", the top-up
lands on the team’s shared credit pool at
organizations.polar_customer_id and all subsequent team-scoped API
usage draws from that pool until it’s depleted.string
Optional. URL to redirect the user to after successful checkout.
Defaults to
/dashboard/billing?topup=success (or
/dashboard/billing?topup=success&scope=team when scope: "org").Example: personal top-up
curl
curl -X POST "https://api.hitheo.ai/api/v1/billing/checkout" \
-H "Authorization: Bearer $THEO_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "amount_cents": 2500 }'
Example: team top-up
curl
curl -X POST "https://api.hitheo.ai/api/v1/billing/checkout" \
-H "Authorization: Bearer $THEO_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "amount_cents": 10000, "scope": "org" }'
SDK
// Fund the team pool. Admins with `manageBilling` can call this; any
// other scope returns 403.
const { checkout_url } = await theo.billingCheckout({
amount_cents: 10_000,
scope: "org",
});
window.open(checkout_url, "_blank");
Response
{
"checkout_url": "https://checkout.hitheo.ai/...",
"scope": "org"
}
Errors
| Status | Code | Meaning |
|---|---|---|
| 400 | missing_amount | amount_cents missing or not an integer. |
| 400 | amount_too_low | Below the $5.00 minimum. |
| 400 | amount_too_high | Above the $1,000.00 maximum. |
| 400 | org_context_required | Requested scope: "org" without an active team. |
| 402 | team_payment_method_required | Team key creation blocked until the team funds billing. Retry after a checkout. |
| 403 | permission_denied | Caller lacks manageBilling in the active team. |
| 503 | billing_unavailable | Billing isn’t configured on this deployment. |
Lifecycle
- Client calls this endpoint with
amount_centsand optionalscope. - The billing service reserves the right customer (personal or team),
creates a checkout session, and returns
checkout_url. - The user completes checkout.
- A background webhook routes the top-up to the correct credit pool (user vs team) and marks the customer as having a payment method on file.
- Subsequent API usage drafts from the funded pool.
Was this page helpful?
Create a top-up checkout
curl --request POST \
--url https://api.example.com/api/v1/billing/checkout \
--header 'Content-Type: application/json' \
--data '
{
"amount_cents": 123,
"scope": "<string>",
"success_url": "<string>"
}
'import requests
url = "https://api.example.com/api/v1/billing/checkout"
payload = {
"amount_cents": 123,
"scope": "<string>",
"success_url": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({amount_cents: 123, scope: '<string>', success_url: '<string>'})
};
fetch('https://api.example.com/api/v1/billing/checkout', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/billing/checkout",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'amount_cents' => 123,
'scope' => '<string>',
'success_url' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/billing/checkout"
payload := strings.NewReader("{\n \"amount_cents\": 123,\n \"scope\": \"<string>\",\n \"success_url\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/billing/checkout")
.header("Content-Type", "application/json")
.body("{\n \"amount_cents\": 123,\n \"scope\": \"<string>\",\n \"success_url\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/billing/checkout")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount_cents\": 123,\n \"scope\": \"<string>\",\n \"success_url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body