Skip to main content
GET
/
public
/
check-credits
curl "https://your-store.myshopify.com/apps/proxy_genlook-x/public/check-credits"
{
  "allowed": true
}
Check whether your shop has available credits for creating generations. This endpoint is cached for 2 minutes to reduce API calls.
This endpoint is cached for 2 minutes on both frontend and backend. Don’t call it more frequently than necessary.

Request

No parameters required. The shop is identified automatically through the app proxy authentication.
curl "https://your-store.myshopify.com/apps/proxy_genlook-x/public/check-credits"

Response

allowed
boolean
required
Whether credits are available for generation. true means you can create generations, false means quota is exhausted.
{
  "allowed": true
}

Usage Pattern

Check credits before creating a generation to provide better user experience:
async function checkBeforeGenerating() {
  // Check credits first
  const creditsResponse = await fetch('/apps/proxy_genlook-x/public/check-credits');
  const credits = await creditsResponse.json();
  
  if (!credits.allowed) {
    // Show message to user about quota
    alert('Generation quota has been reached. Please upgrade your plan.');
    return;
  }
  
  // Proceed with generation
  const generationResponse = await fetch('/apps/proxy_genlook-x/public/fitting-room', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      userImageId: 'file_abc123',
      productId: 'gid://shopify/Product/456'
    })
  });
  
  const generation = await generationResponse.json();
  // Handle generation...
}

Caching Strategy

Frontend caching: Cache the result for 2 minutes in your application to avoid unnecessary API calls.
Backend caching: The backend also caches results for 2 minutes, so even if you call it frequently, it won’t hit the database every time.
The cache is per-shop. Different shops will have different credit statuses.

Error Handling

This endpoint uses a “fail open” strategy. If there’s an error checking credits, it returns allowed: true to avoid blocking users. Always handle the create generation endpoint’s error codes for definitive quota checks.
{
  "allowed": true
}
Don’t rely solely on this endpoint for quota enforcement. The create generation endpoint will still return QUOTA_EXCEEDED if quota is actually exceeded, even if check-credits returned allowed: true.

Best Practices

Pre-check before UI: Check credits before showing the generation button to users. This provides a better UX than showing an error after they upload an image.
Cache results: Store the result in memory/localStorage for 2 minutes to reduce API calls.
Handle errors gracefully: If the check fails, still allow users to attempt generation - the create endpoint will provide definitive feedback.

Integration with Generation Flow

Recommended flow:
  1. On widget open: Check credits and show/hide generation button accordingly
  2. Before generation: Optionally check again (if cache expired)
  3. After generation: Clear credit check cache if generation succeeded (to reflect new usage)
let creditsCache = null;
let creditsCacheTime = null;
const CACHE_TTL = 2 * 60 * 1000; // 2 minutes

async function getCreditsStatus() {
  const now = Date.now();
  
  // Use cached result if available
  if (creditsCache && creditsCacheTime && (now - creditsCacheTime) < CACHE_TTL) {
    return creditsCache;
  }
  
  // Fetch fresh result
  const response = await fetch('/apps/proxy_genlook-x/public/check-credits');
  const result = await response.json();
  
  creditsCache = result;
  creditsCacheTime = now;
  
  return result;
}

// Clear cache after successful generation
function clearCreditsCache() {
  creditsCache = null;
  creditsCacheTime = null;
}