{"openapi":"3.0.3","info":{"title":"US Tax API","version":"1.4.0","description":"Nationwide US destination-based sales tax calculator for Cloudflare Workers + D1.\n\n### How it works\n1. When `customer_address.street` is present, **auto-verify** via free US Census Geocoder and standardize the address (override with `verify_address: false`).\n2. Resolve tax from **SSTGB street A-records** in R2 when possible (`rate_source=sst_street`), else ZIP5 Z in D1 (`sst_official`), else local fallback.\n3. Apply state-law product taxability by `items[].category` (exemptions, price caps, reduced rates).\n4. Apply state sales-tax holidays when `transaction_date` falls in a published holiday window (e.g. MA Aug 8–9, 2026).\n\n### Address verification (free)\nDefault provider `census` = US Census TIGER (no API key). Response also includes `sst_street_matched` when SST A-packs cover the ZIP.\nOptional paid: Google / Smarty via secrets.\n\n### Auth\nProtected endpoints require header `x-api-key: <per-client-key>` (keys look like `ustax_…`).\n**Self-serve:** create an account at `/account`, subscribe (Stripe when configured), then Reveal key in your profile.\n**Admin:** `/dashboard` or CLI `npm run clients:create -- --name \"Acme Corp\"`.\nDaily plan quotas return **429** when exceeded (UTC midnight reset).\nIn Swagger: click **Authorize** and paste the key."},"servers":[{"url":"/","description":"Current host"}],"tags":[{"name":"Meta","description":"Health and coverage"},{"name":"Address","description":"Address verification (free Census Geocoder by default)"},{"name":"Tax","description":"Calculate and lookup"}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"x-api-key","description":"Per-client API key from /account profile or admin dashboard"}},"schemas":{"ErrorResponse":{"type":"object","properties":{"code":{"type":"integer","example":400},"status":{"type":"string","example":"error"},"message":{"type":"string"},"detail":{"type":"string"}}},"CustomerAddress":{"type":"object","required":["state","zip"],"properties":{"street":{"type":"string","example":"123 Market St"},"street2":{"type":"string","example":"Suite 400"},"city":{"type":"string","example":"Philadelphia"},"county":{"type":"string","example":"Philadelphia"},"state":{"type":"string","example":"PA","description":"2-letter US state code"},"zip":{"type":"string","example":"19103","description":"5-digit ZIP (ZIP+4 accepted, uses first 5)"},"country":{"type":"string","example":"US"}}},"LineItem":{"type":"object","required":["unit_price"],"properties":{"id":{"type":"string","example":"sku-1"},"sku":{"type":"string","example":"TSHIRT-BLK-M"},"name":{"type":"string","example":"T-Shirt"},"category":{"type":"string","example":"clothing.general","description":"Product taxability category. Defaults to goods.general. Examples: clothing.general, goods.electronics, food.grocery, medical.rx, software.saas"},"unit_price":{"type":"number","example":40},"quantity":{"type":"number","example":2,"default":1}}},"CalculateRequest":{"type":"object","required":["transaction_date","customer_address","items"],"properties":{"transaction_date":{"type":"string","format":"date","example":"2026-06-01"},"customer_address":{"$ref":"#/components/schemas/CustomerAddress"},"shipping_amount":{"type":"number","example":5,"default":0},"verify_address":{"type":"boolean","default":true,"description":"Auto-true when street is present. Free Census verify + standardize. Set false to skip."},"require_deliverable":{"type":"boolean","default":false,"description":"Return 422 if address cannot be confirmed"},"items":{"type":"array","minItems":1,"items":{"$ref":"#/components/schemas/LineItem"}}}},"AddressVerifyRequest":{"type":"object","required":["street","state","zip"],"properties":{"street":{"type":"string","example":"1600 Amphitheatre Parkway"},"street2":{"type":"string","example":""},"city":{"type":"string","example":"Mountain View"},"state":{"type":"string","example":"CA"},"zip":{"type":"string","example":"94043"},"country":{"type":"string","example":"US"},"provider":{"type":"string","enum":["census","google","smarty","auto"],"default":"census"},"match":{"type":"string","enum":["strict","invalid","enhanced"],"default":"invalid"},"candidates":{"type":"integer","default":1,"minimum":1,"maximum":10}}},"AddressVerification":{"type":"object","properties":{"provider":{"type":"string","enum":["census","google","smarty","none"]},"deliverable":{"type":"boolean"},"matched":{"type":"boolean"},"dpv_match_code":{"type":"string","nullable":true,"description":"Y = confirmed match; N = not"},"dpv_vacant":{"type":"string","nullable":true},"footnotes":{"type":"string","nullable":true},"standardized":{"$ref":"#/components/schemas/CustomerAddress"},"delivery_line_1":{"type":"string","nullable":true},"last_line":{"type":"string","nullable":true},"zip_plus4":{"type":"string","nullable":true},"county":{"type":"string","nullable":true},"latitude":{"type":"number","nullable":true},"longitude":{"type":"number","nullable":true},"precision":{"type":"string","nullable":true},"rdi":{"type":"string","nullable":true},"record_type":{"type":"string","nullable":true},"candidates":{"type":"integer"},"sst_street_matched":{"type":"boolean","nullable":true,"description":"Whether SSTGB A-record packs also match this street/number"}}},"Jurisdiction":{"type":"object","properties":{"type":{"type":"string","enum":["State","County","City","Special District"]},"name":{"type":"string"},"rate":{"type":"number"},"tax_amount":{"type":"number"}}},"LineResult":{"type":"object","properties":{"id":{"type":"string","nullable":true},"sku":{"type":"string","nullable":true},"name":{"type":"string","nullable":true},"category":{"type":"string"},"quantity":{"type":"number"},"unit_price":{"type":"number"},"line_subtotal":{"type":"number"},"taxable_amount":{"type":"number"},"exempt_amount":{"type":"number"},"tax_amount":{"type":"number"},"taxability":{"type":"object","properties":{"treatment":{"type":"string","example":"exempt"},"taxable":{"type":"boolean"},"note":{"type":"string","nullable":true}}}}},"CalculateResponse":{"type":"object","properties":{"code":{"type":"integer","example":200},"status":{"type":"string","example":"success"},"data":{"type":"object","properties":{"transaction_date":{"type":"string"},"customer_address":{"type":"object"},"rate_matched":{"type":"boolean"},"combined_tax_rate":{"type":"number","example":0.08},"freight_taxable":{"type":"boolean"},"subtotal":{"type":"number"},"shipping":{"type":"number"},"taxable_amount":{"type":"number"},"exempt_amount":{"type":"number"},"total_tax":{"type":"number"},"grand_total":{"type":"number"},"taxing_jurisdictions":{"type":"array","items":{"$ref":"#/components/schemas/Jurisdiction"}},"items":{"type":"array","items":{"$ref":"#/components/schemas/LineResult"}}}}}}}},"paths":{"/health":{"get":{"tags":["Meta"],"summary":"Health check","description":"Returns DB connectivity and row counts. No API key required.","responses":{"200":{"description":"Service healthy","content":{"application/json":{"schema":{"type":"object","example":{"code":200,"status":"ok","data":{"service":"us-tax-api","database":"connected","tax_rate_rows":40977,"taxability_rows":1734}}}}}}}}},"/api/v1/tax/coverage":{"get":{"tags":["Meta"],"summary":"Nationwide coverage stats","description":"ZIP and taxability coverage by state. No API key required.","responses":{"200":{"description":"Coverage summary"}}}},"/api/v1/address/verify":{"post":{"tags":["Address"],"summary":"Verify US address","description":"Default: free US Census Bureau Geocoder (TIGER address ranges, lat/lng). Optional providers: google / smarty if configured.","security":[{"ApiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AddressVerifyRequest"},"example":{"street":"1600 Amphitheatre Parkway","city":"Mountain View","state":"CA","zip":"94043"}}}},"responses":{"200":{"description":"Verification result","content":{"application/json":{"schema":{"type":"object","properties":{"code":{"type":"integer","example":200},"status":{"type":"string","example":"success"},"data":{"$ref":"#/components/schemas/AddressVerification"}}}}}},"400":{"description":"Validation error"},"502":{"description":"Upstream geocoder failed"}}}},"/api/v1/tax/calculate":{"post":{"tags":["Tax"],"summary":"Calculate sales tax","description":"Destination-based tax calculation with per-item product taxability. Street present auto-verifies via Census; set verify_address:false to skip.","security":[{"ApiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CalculateRequest"},"examples":{"philadelphiaClothing":{"summary":"Philadelphia: clothing exempt + electronics taxed","value":{"transaction_date":"2026-06-01","customer_address":{"street":"123 Market St","city":"Philadelphia","state":"PA","zip":"19103"},"shipping_amount":5,"items":[{"id":"shirt","name":"T-Shirt","category":"clothing.general","unit_price":40,"quantity":2},{"id":"laptop","name":"Laptop","category":"goods.electronics","unit_price":100,"quantity":1}]}},"losAngeles":{"summary":"Los Angeles electronics","value":{"transaction_date":"2026-06-01","customer_address":{"street":"6801 Hollywood Blvd","city":"Los Angeles","state":"CA","zip":"90028"},"items":[{"name":"Headphones","category":"goods.electronics","unit_price":100,"quantity":1}]}},"oregonNoTax":{"summary":"Portland OR — no sales tax","value":{"transaction_date":"2026-06-01","customer_address":{"city":"Portland","state":"OR","zip":"97209"},"items":[{"name":"Laptop","category":"goods.electronics","unit_price":100,"quantity":1}]}}}}}},"responses":{"200":{"description":"Tax calculated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CalculateResponse"}}}},"400":{"description":"Validation error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Invalid or missing API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/tax/rates":{"get":{"tags":["Tax"],"summary":"Lookup ZIP tax rate","security":[{"ApiKeyAuth":[]}],"parameters":[{"name":"state","in":"query","required":true,"schema":{"type":"string","example":"PA"}},{"name":"zip","in":"query","required":true,"schema":{"type":"string","example":"19103"}},{"name":"date","in":"query","required":false,"schema":{"type":"string","format":"date","example":"2026-06-01"}}],"responses":{"200":{"description":"Rate found"},"401":{"description":"Unauthorized"},"404":{"description":"Rate not found"}}}},"/api/v1/tax/categories":{"get":{"tags":["Tax"],"summary":"List product taxability categories","description":"Pass `state` to see that state’s taxable/exempt rules per category.","security":[{"ApiKeyAuth":[]}],"parameters":[{"name":"state","in":"query","required":false,"schema":{"type":"string","example":"PA"}}],"responses":{"200":{"description":"Category list"},"401":{"description":"Unauthorized"}}}}}}