Skip to main content

Get Credits

Retrieves your OpenRouter account's credit balance and total usage information.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Connection Id - The connection identifier from Connect node (optional if API Key is provided directly).

Options

  • API Key - OpenRouter API key credential (optional if using Connection Id).
warning

This node does NOT support "Use Robomotion AI Credits" mode. You must use your own OpenRouter API key to check account credits.

Output

  • Credits - Credits information object containing:
    • total_credits - Total credits available in your account (in USD)
    • total_usage - Total amount used from your credits (in USD)

How It Works

When executed, the node:

  1. Validates the connection or credentials
  2. Blocks execution if using Robomotion AI Credits (not supported)
  3. Makes GET request to /credits endpoint
  4. Parses the response and extracts credit information
  5. Returns the credits data object

Requirements

  • Valid OpenRouter API Key (Robomotion AI Credits NOT supported)
  • Active OpenRouter account with credit information

Error Handling

The node will return specific errors in the following cases:

  • Using Robomotion AI Credits mode (unsupported)
  • API authentication errors (401)
  • API service errors (500, 502, 503, 504)

Calculations

// Remaining credits
remaining_credits = total_credits - total_usage

// Usage percentage
usage_percentage = (total_usage / total_credits) * 100

Examples

Example 1: Check Account Balance

Input:

  • Connection Id: msg.connection

Output:

{
total_credits: 25.00,
total_usage: 8.45
}

Analysis:

  • Remaining: $16.55
  • Used: 33.8% of credits

Example 2: Budget Alert System

// Get Credits Node
// Output: msg.credits

const remaining = msg.credits.total_credits - msg.credits.total_usage;
const usage_percent = (msg.credits.total_usage / msg.credits.total_credits) * 100;

if (remaining < 5.0) {
// Send alert - low balance
sendAlert("Low OpenRouter credits: $" + remaining.toFixed(2) + " remaining");
}

if (usage_percent > 90) {
// Send alert - high usage
sendAlert("OpenRouter usage at " + usage_percent.toFixed(1) + "%");
}

Example 3: Pre-Flight Check

// Before running expensive AI operation
// Get Credits Node
// Output: msg.credits

const remaining = msg.credits.total_credits - msg.credits.total_usage;
const estimated_cost = 2.50; // Estimated cost of operation

if (remaining < estimated_cost) {
throw new Error(`Insufficient credits. Need $${estimated_cost}, have $${remaining.toFixed(2)}`);
}

// Proceed with operation

Example 4: Daily Usage Report

// Store previous day's usage
msg.yesterday_usage = msg.yesterday_usage || 0;

// Get current usage
const today_usage = msg.credits.total_usage - msg.yesterday_usage;

console.log(`Daily Usage Report:
Total Credits: $${msg.credits.total_credits}
Total Usage: $${msg.credits.total_usage}
Today's Usage: $${today_usage.toFixed(2)}
Remaining: $${(msg.credits.total_credits - msg.credits.total_usage).toFixed(2)}
`);

// Update for next day
msg.yesterday_usage = msg.credits.total_usage;

Example 5: Auto Top-Up Trigger

// Get Credits Node
// Output: msg.credits

const MIN_BALANCE = 10.0;
const TOP_UP_AMOUNT = 50.0;

const remaining = msg.credits.total_credits - msg.credits.total_usage;

if (remaining < MIN_BALANCE) {
console.log(`Balance low ($${remaining.toFixed(2)}). Triggering top-up of $${TOP_UP_AMOUNT}`);

// Trigger your top-up process
// (This would require manual action or integration with payment system)
sendNotification("Please top up OpenRouter account");
}

Example 6: Usage Analytics

// Track over time
msg.usage_history = msg.usage_history || [];

msg.usage_history.push({
timestamp: new Date().toISOString(),
total_credits: msg.credits.total_credits,
total_usage: msg.credits.total_usage,
remaining: msg.credits.total_credits - msg.credits.total_usage
});

// Calculate usage trends
if (msg.usage_history.length >= 2) {
const last = msg.usage_history[msg.usage_history.length - 1];
const prev = msg.usage_history[msg.usage_history.length - 2];

const usage_increase = last.total_usage - prev.total_usage;
console.log(`Usage increased by $${usage_increase.toFixed(2)} since last check`);
}

Best Practices

  1. Regular Monitoring:

    • Check credits before expensive operations
    • Set up scheduled checks (daily or weekly)
    • Monitor trends over time
  2. Budget Management:

    • Set up low balance alerts
    • Implement pre-flight checks for large operations
    • Track usage patterns
  3. Automation:

    • Add credit checks to critical workflows
    • Fail gracefully when credits are insufficient
    • Log credit status for auditing
  4. Notifications:

    • Alert when balance is low
    • Notify on unusual usage spikes
    • Send regular usage reports
  5. Cost Control:

    • Pause non-critical operations when credits are low
    • Implement usage quotas per project
    • Monitor cost per operation

Use Cases for RPA

  1. Pre-Execution Validation: Check credits before running AI-heavy workflows
  2. Budget Enforcement: Prevent operations when credits are insufficient
  3. Usage Monitoring: Track AI spending across projects
  4. Alert Systems: Notify administrators of low balances
  5. Cost Analytics: Analyze spending patterns and optimize
  6. Automatic Reporting: Generate credit usage reports
  7. Multi-Team Management: Track usage when sharing an account
  8. Scheduled Audits: Regular credit balance checks
  • Get Generation - Get detailed cost information for specific generations
  • Get Current API Key - Check API key usage limits and status