API Reference - cred.diy API documentation
API Reference
Complete reference for all API endpoints. Base URL: https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api
Quick Start
1. Generate an API key from the API Keys page (set an expiration date for security).
2. Include your API key in the x-api-key header.
3. Make requests to the endpoints below.
Authentication
All requests require an API key in the header. Rate limit: 100 requests/minute per key.
curl -H "x-api-key: sk_live_your_api_key" https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/balance?user_id=user_123/balanceGet the credit balance for a user. Supports email-first lookup for unified wallets.
Query parameters
emailstringUser's email (preferred, takes priority over user_id)user_idstringYour unique identifier for the user (required if email not provided)credit_type_idstringFilter to specific credit type
Example request
# Preferred: use email for cross-app wallet lookup
curl -X GET "https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/balance?email=user@example.com" \
-H "x-api-key: sk_live_your_api_key"
# Alternative: use user_id
curl -X GET "https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/balance?user_id=user_123" \
-H "x-api-key: sk_live_your_api_key"Response
{
"user_id": "user_123",
"email": "user@example.com",
"balances": [{
"credit_type_id": "ct_abc123",
"credit_type_name": "Tokens",
"credit_type_symbol": "TKN",
"balance": 75
}]
}Webhooks
Configure webhooks to receive real-time notifications when credit events occur. Use the Test button in the dashboard to verify your endpoints.
Available Events
credits.issuedcredits.deductedcredits.refundedpurchase.completedpurchase.failedswap.completedreferral.completedbalance.lowsubscription.createdsubscription.renewedsubscription.cancel_scheduledsubscription.canceledsubscription.payment_failed
Verify the X-Cred-Signature header using HMAC-SHA256 with your webhook secret.
Error Codes
| Code | Description |
|---|---|
| 400 | Bad Request — invalid parameters or insufficient user credits (code: INSUFFICIENT_CREDITS) |
| 401 | Unauthorized — invalid or missing API key |
| 402 | Payment Required — insufficient platform credits (CRD) |
| 404 | Not Found — user or resource not found |
| 409 | Conflict — already processed (e.g. a refund that was already issued) |
| 429 | Rate Limit Exceeded — 100 requests/minute per key |
| 500 | Internal Server Error |
Your first credit is one request away.
Create a project, copy an API key, and issue a credit from your server.
