cred.diy/ docs
    Sign inGet an API key
    All documentation

    End Users - cred.diy API documentation

    End Users

    Manage end users in your credit system. Users are identified by email (preferred) or external_id. The same email always maps to the same wallet within your project.

    Create or Get User

    Create a new user or retrieve an existing user by email. If the email already exists, the existing user is returned.

    // Create or get a user
    // Note: If a user with this email already exists, returns existing user's wallet
    const response = await fetch(
      'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/users',
      {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'x-api-key': 'sk_live_your_api_key'
        },
        body: JSON.stringify({
          external_id: 'user_123',
          email: 'user@example.com', // Primary identifier - one email = one wallet
          name: 'John Doe',
          metadata: { plan: 'pro' }
        })
      }
    );
    
    const result = await response.json();
    // { user: { id: '...', external_id: 'user_123', email: 'user@example.com', ... }, created: true }

    Bulk Sync Users

    Sync up to 1000 users at once from your existing database. Great for initial setup.

    // Sync all your existing users to CRED (up to 1000 per request)
    const response = await fetch(
      'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/users/bulk',
      {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'x-api-key': 'sk_live_your_api_key'
        },
        body: JSON.stringify({
          users: [
            { external_id: 'user_1', email: 'user1@example.com', name: 'User One' },
            { external_id: 'user_2', email: 'user2@example.com', name: 'User Two' },
            { external_id: 'user_3', email: 'user3@example.com', name: 'User Three' }
          ]
        })
      }
    );
    
    const result = await response.json();
    // { success: true, created: 2, updated: 1 }

    List Users

    Retrieve all users with pagination support.

    // List all users with pagination
    const response = await fetch(
      'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/users?limit=100&offset=0',
      {
        headers: {
          'x-api-key': 'sk_live_your_api_key'
        }
      }
    );
    
    const result = await response.json();
    // { users: [...], total: 150, limit: 100, offset: 0 }

    Update User

    Update user details like name or metadata.

    // Update a user
    const response = await fetch(
      'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/users',
      {
        method: 'PATCH',
        headers: {
          'Content-Type': 'application/json',
          'x-api-key': 'sk_live_your_api_key'
        },
        body: JSON.stringify({
          external_id: 'user_123',
          name: 'Jane Doe',
          metadata: { plan: 'enterprise' }
        })
      }
    );
    
    const result = await response.json();
    // { user: { id: '...', external_id: 'user_123', name: 'Jane Doe', ... } }

    User Identity Model

    Users are identified primarily by email within your project:

    • One email = one wallet across all your apps
    • The external_id is your internal reference
    • Credits issued to the same email are consolidated
    • Users can access their balance from any app using their email

    Your first credit is one request away.

    Create a project, copy an API key, and issue a credit from your server.