Prompt
How do I calculate tax for subscriptions and one-time purchases with one API?
Latest observation
Oct 6, 2026
OpenAI APIWeb search: off
You can calculate tax for both subscriptions and one-time purchases with a single tax API by treating both as the same kind of taxable “line item” and sending the right context with each request.
Basic idea
For each purchase, send:
- customer location
- product/service details
- price
- currency
- whether it’s recurring or one-time
- billing frequency / subscription period if recurring
The tax engine then returns the tax amount/rate for that transaction.
Recommended approach
Use one endpoint like:
POST /tax/quotePOST /calculate-taxPOST /transactions/tax
Example payload for a one-time purchase
{
"customer": {
"country": "US",
"state": "CA",
"zip": "94107"
},
"items": [
{
"id": "ebook_001",
"description": "E-book",
"quantity": 1,
"unit_price": 20.00,
"tax_code": "DIGITAL_BOOK",
"type": "one_time"
}
],
"currency": "USD"
}
Example payload for a subscription
{
"customer": {
"country": "US",
"state": "CA",
"zip": "94107"
},
"items": [
{
"id": "pro_plan_monthly",
"description": "Pro Plan",
"quantity": 1,
"unit_price": 15.00,
"tax_code": "SAAS",
"type": "subscription",
"billing_period": "month",
"billing_frequency": 1
}
],
"currency": "USD"
}
Important things to include
1. Location
Tax depends heavily on where the customer is located.
2. Product tax code
Subscriptions and one-time items may be taxed differently based on category:
- SaaS
- digital goods
- physical goods
- services
3. Recurring details
For subscriptions, include:
- billing interval
- billing frequency
- trial or prorations if relevant
4. Tax behavior
Depending on the API, you may specify:
- tax-inclusive vs tax-exclusive pricing
- whether tax should be calculated at checkout or on invoice
- exemptions / VAT IDs
Common pattern in code
You can use the same function for both:
function calculateTax(order) {
return taxApi.calculate({
customer: order.customer,
items: order.items,
currency: order.currency
});
}
Then create either:
- a one-time item object
- a subscription item object
If you’re using Stripe, Avalara, TaxJar, etc.
Most tax providers support both by:
- using the same tax calculation endpoint
- distinguishing recurring vs one-time via product metadata or invoice/line item type
Best practice
Model everything as invoice line items:
- one-time purchase = invoice line item with no recurring metadata
- subscription = invoice line item with recurring metadata
That lets one API handle both.
If you want, I can show you:
- a Stripe example
- a TaxJar/Avalara example
- a generic REST API design for both in one endpoint