Skip to main content

GET /api/credits

Retrieves the current credit balance for the authenticated user.

Authentication

This endpoint requires authentication. Include valid Clerk authentication credentials in your request.

Response

credits
number
The current number of credits available for the user. Returns 0 if no credits record exists.

Code examples

curl -X GET https://gitread.dev/api/credits \
  -H "Authorization: Bearer YOUR_AUTH_TOKEN"

Response example

{
  "credits": 5
}

Error responses

401
Unauthorized
Authentication required
{
  "error": "Unauthorized"
}
500
Internal Server Error
Error fetching credits from database
{
  "error": "Error fetching credits"
}

POST /api/credits

Updates the credit balance for the authenticated user. This endpoint is typically used internally by the system for credit management.

Authentication

This endpoint requires authentication. Include valid Clerk authentication credentials in your request.

Request body

credits
number
required
The new credit balance to set for the user. Must be a non-negative number.

Response

success
boolean
Indicates whether the credit update was successful
credits
number
The updated credit balance

Code examples

curl -X POST https://gitread.dev/api/credits \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_AUTH_TOKEN" \
  -d '{
    "credits": 10
  }'

Response example

{
  "success": true,
  "credits": 10
}

Error responses

400
Bad Request
Invalid credits value provided
{
  "error": "Invalid credits value"
}
This error occurs when:
  • Credits value is not a number
  • Credits value is negative
401
Unauthorized
Authentication required
{
  "error": "Unauthorized"
}
500
Internal Server Error
Error updating credits in database
{
  "error": "Error updating credits"
}
or
{
  "error": "Unexpected error updating credits"
}

Database operations

The POST endpoint uses an upsert operation, which means:
  • If a credits record exists for the user, it will be updated
  • If no record exists, a new one will be created
  • The updated_at timestamp is automatically set to the current time

Credit pricing

Credits can be purchased through the checkout endpoints. Current pricing:
  • $1.25 per credit
  • Each credit allows one README generation

Build docs developers (and LLMs) love