Skip to main content

POST /credits/checkout

This endpoint creates a Stripe checkout session to allow a user to purchase a credit package. Requires session-based authentication (JWT access token from login).
This endpoint uses session authentication, not API key authentication. You need to be logged in via the dashboard or use a JWT access token.

Request Body

packageId
string
required
The ID of the credit package to purchase. Get available packages from /credits/packages.
successUrl
string
The URL to redirect to after a successful purchase. Defaults to dashboard with success indicator.
cancelUrl
string
The URL to redirect to if the purchase is canceled. Defaults to dashboard with canceled indicator.

Response

sessionId
string
The ID of the Stripe checkout session.
url
string
The URL of the Stripe checkout page. Redirect the user here to complete purchase.
package
object
Details of the selected package.
curl -X POST https://api.llmgenerator.com/api/v1/credits/checkout \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
        "packageId": "pkg_pro",
        "successUrl": "https://example.com/success?session_id={CHECKOUT_SESSION_ID}",
        "cancelUrl": "https://example.com/cancel"
      }'
{
  "sessionId": "cs_test_a1b2c3d4e5f6g7h8i9j0",
  "url": "https://checkout.stripe.com/c/pay/cs_test_a1b2c3d4e5f6g7h8i9j0",
  "package": {
    "id": "pkg_pro",
    "name": "Pro Pack",
    "credits": 500,
    "priceCents": 1999
  }
}