ResourcesCredits

Credits

Check credit balances, deduct usage credits, create checkout sessions, manage auto-reload, and retrieve transaction history through the Talkturo API.

curl -X GET "https://api.talkturo.com/api/credits?accountId=8f6b7a40-8f86-4cfd-a7ec-0b0b52f5c8d2" \
  -H "Authorization: Bearer tk_live_example_9xmk7q2r5s8d4m1n6p3v7y2z"
{
  "success": true,
  "credits": {
    "id": "c8b74c77-8f54-4f72-bfc6-2dc0db7d6f0b",
    "account_id": "8f6b7a40-8f86-4cfd-a7ec-0b0b52f5c8d2",
    "credits": 18420,
    "total_purchased": 25000,
    "total_used": 6580,
    "auto_reload_enabled": true,
    "auto_reload_threshold": 5000,
    "auto_reload_amount_usd": 199
  }
}
curl -X POST "https://api.talkturo.com/api/credits" \
  -H "Authorization: Bearer tk_live_example_9xmk7q2r5s8d4m1n6p3v7y2z" \
  -H "Content-Type: application/json" \
  -d '{
    "accountId": "8f6b7a40-8f86-4cfd-a7ec-0b0b52f5c8d2",
    "amount": 320,
    "description": "Outbound call usage for campaign cmp_7d2fa19c",
    "metadata": {
      "assistantId": "0b760e0d-4b10-4ee8-9c8b-89f02d0a9149",
      "campaignId": "cmp_7d2fa19c",
      "minutes": 4.8
    }
  }'
{
  "success": true,
  "transactionId": "txn_credits_4aa92d1f6d10",
  "balance": 18100,
  "autoReloadTriggered": false
}
curl -X POST "https://api.talkturo.com/api/credits/checkout" \
  -H "Authorization: Bearer tk_live_example_9xmk7q2r5s8d4m1n6p3v7y2z" \
  -H "Content-Type: application/json" \
  -d '{
    "accountId": "8f6b7a40-8f86-4cfd-a7ec-0b0b52f5c8d2",
    "accountSlug": "acme-sales",
    "planId": "credits_growth_500"
  }'
{
  "success": true,
  "checkoutToken": "seti_example_4c0f6b0a2a594f0b8f5d1e5d",
  "sessionId": "cs_test_b1b8ac39f2f54ceaa55d4e9b2f13",
  "credits": 50000,
  "amount": 499
}

Credits endpoints

Use the credits API to read an account balance, record usage deductions, and start credit purchases through Stripe. The balance, deduction, and checkout endpoints support dual authentication, while account management endpoints for auto-reload and history use session authentication.

Authentication

  • GET /api/credits
  • POST /api/credits
  • POST /api/credits/checkout

These endpoints use dual authentication. Authenticate with either an API key or a signed-in session cookie.

The following endpoints require a session-authenticated browser request:

  • GET and POST /api/credits/auto-reload
  • POST /api/credits/claim-grants
  • GET /api/credits/plans
  • GET /api/credits/statement
  • GET /api/credits/transactions

Endpoint summary

MethodPathAuthPurpose
GET/api/creditsAPI key or sessionGet the current credit balance for an account
POST/api/creditsAPI key or sessionDeduct credits for usage tracking
POST/api/credits/checkoutAPI key or sessionCreate an embedded Stripe checkout session for a credit purchase
GET/api/credits/auto-reloadSessionGet auto-reload settings
POST/api/credits/auto-reloadSessionUpdate auto-reload settings
POST/api/credits/claim-grantsSessionClaim pending credit grants
GET/api/credits/plansSessionList available credit purchase plans
GET/api/credits/statementSessionGet credit statement history
GET/api/credits/transactionsSessionGet credit transaction history

Get credits balance

Read the current balance for an account with GET /api/credits. If you omit accountId, the API uses the authenticated account from the request context.

Query parameters

query
accountIdstring

Account UUID to read. If you omit accountId, the endpoint falls back to the authenticated account.

Response fields

successboolean
Required

Returns true when the request succeeds.

creditsobject
Required

Current credit record for the account. If the account does not already have a credits record, the API creates one before returning the response.

credits.idstring
Required

Unique identifier for the credits record.

credits.account_idstring
Required

Account UUID that owns the credits balance.

credits.creditsnumber
Required

Current available credit balance.

credits.total_purchasednumber
Required

Total credits purchased for the account.

credits.total_usednumber
Required

Total credits deducted from the account.

credits.auto_reload_enabledboolean
Required

Whether automatic credit reloading is enabled.

credits.auto_reload_thresholdnumber
Required

Balance threshold that can trigger auto-reload after a deduction.

credits.auto_reload_amount_usdnumber
Required

Dollar amount charged when auto-reload runs.

Deduct credits

Record usage and decrement an account balance with POST /api/credits. This endpoint calls the deduct_credits() database function and returns the updated balance.

Body parameters

body
accountIdstring
Required

Account UUID to charge.

body
amountnumber
Required

Number of credits to deduct.

body
descriptionstring

Human-readable description of the usage event or billing reason.

body
metadataobject

Structured metadata stored with the transaction. Use this field to attach internal identifiers such as assistant, campaign, call, or workflow IDs.

Response fields

successboolean
Required

Returns true when the deduction succeeds.

transactionIdstring
Required

Identifier for the credits transaction created by the deduction.

balancenumber
Required

Remaining credit balance after the deduction completes.

autoReloadTriggeredboolean
Required

Whether the deduction triggered an automatic reload because the updated balance fell below the configured threshold.

A deduction returns HTTP 402 when the account does not have enough credits to cover amount. Handle this response before retrying usage actions that would create duplicate charges in your application.

Auto-reload behavior after a deduction

If auto-reload is enabled and the remaining balance drops below auto_reload_threshold, the API attempts to trigger a reload after the deduction succeeds. The deduction response still returns immediately with autoReloadTriggered so your application can decide whether to notify the account owner or pause high-cost actions until the balance refreshes.

Create a checkout session

Start a credit purchase with POST /api/credits/checkout. Use either a predefined planId or a custom purchase amount and credit quantity.

Body parameters

body
accountIdstring
Required

Account UUID that will receive the purchased credits.

body
accountSlugstring
Required

Account slug used to associate the checkout session with the correct account.

body
planIdstring

Predefined credit purchase plan to buy. Provide planId or provide both customAmount and customCredits.

body
customAmountnumber

Custom purchase amount in USD. Custom purchases require both customAmount and customCredits, and customAmount must be at least 99.

body
customCreditsnumber

Number of credits to grant for a custom purchase amount.

body
customerIdstring

Existing Stripe customer ID to attach to the checkout session.

body
customerEmailstring

Customer email address for the Stripe checkout session.

body
toltReferralstring

Referral identifier forwarded with the checkout request when present.

Response fields

successboolean
Required

Returns true when the checkout session is created.

checkoutTokenstring
Required

Client secret for the embedded Stripe checkout session.

sessionIdstring
Required

Stripe Checkout session identifier.

creditsnumber
Required

Number of credits that the purchase will add after payment succeeds.

amountnumber
Required

Purchase amount returned by the API.

Purchase rules

  • Provide planId, or provide both customAmount and customCredits.
  • Custom purchases must have a minimum customAmount of 99.
  • The endpoint creates an embedded Stripe Checkout session and returns a client secret in checkoutToken.

Session-authenticated credits endpoints

Use the following endpoints from a signed-in browser session when you need account-level credits management and history screens.

Get or update auto-reload

GET /api/credits/auto-reload reads the current auto-reload settings. POST /api/credits/auto-reload updates those settings for the signed-in account.

auto_reload_enabledboolean

Whether automatic reloading is enabled when the balance falls below the threshold.

auto_reload_thresholdnumber

Balance threshold that qualifies the account for auto-reload.

auto_reload_amount_usdnumber

Dollar amount to charge when auto-reload runs.

Claim pending grants

POST /api/credits/claim-grants applies any pending credit grants to the signed-in account. Use this endpoint after account actions that provision promotional or manual credits.

List available plans

GET /api/credits/plans returns the purchase plans available to the signed-in account. Use it to populate a billing UI before calling checkout.

Get statement history

GET /api/credits/statement returns statement-style credit history for the signed-in account. Use it when you need a chronological ledger view.

Get transaction history

GET /api/credits/transactions returns transaction-level credit history for the signed-in account. Use it when you need detailed usage and purchase records.

Common integration patterns

Developers usually combine these endpoints in a short billing loop:

  • Read the current balance before starting a high-cost action.
  • Deduct credits when usage is confirmed.
  • Handle HTTP 402 by pausing work and prompting for a purchase flow.
  • Create a checkout session when the user needs to buy more credits.
  • Refresh the balance after purchase completion or auto-reload.

Credits deductions and checkout creation cover the API side of usage billing. The actual credit grant happens after payment succeeds through Stripe webhook processing, so a successful checkout session does not change the balance until payment completion is recorded.