Overview

The Gbox SDK automatically retries certain types of failed requests to improve reliability. By default, retry is disabled (0 retries), but you can configure this behavior based on your needs.

Automatic Retry Conditions

The SDK will automatically retry requests that fail due to:

  • Connection errors (network connectivity issues)
  • 408 Request Timeout
  • 409 Conflict
  • 429 Rate Limit
  • 5xx Server Errors (500, 502, 503, etc.)

Configuration

Global Retry Settings

Configure retry behavior when initializing the SDK:

import GboxSDK from "gbox-sdk";

const gboxSDK = new GboxSDK({
  apiKey: process.env["GBOX_API_KEY"],
  maxRetries: 3, // Retry up to 3 times (default is 0)
});

Per-Request Retry Settings

Override retry settings for specific requests:

// Create device with custom retry settings
const box = await gboxSDK.create(
  { type: "android" },
  {
    maxRetries: 5, // Retry up to 5 times for this request
  }
);

Retry Behavior

Exponential Backoff

The SDK uses exponential backoff between retries:

  • 1st retry: ~1 second delay
  • 2nd retry: ~2 seconds delay
  • 3rd retry: ~4 seconds delay
  • And so on…

Example Usage

import GboxSDK from "gbox-sdk";

const gboxSDK = new GboxSDK({
  apiKey: process.env["GBOX_API_KEY"],
  maxRetries: 3,
});

async function createDeviceWithRetry() {
  try {
    const box = await gboxSDK.create({ type: "android" });
    console.log("Device created successfully:", box.id);
    return box;
  } catch (error) {
    console.error("Failed to create device after retries:", error);
    throw error;
  }
}

createDeviceWithRetry();

Best Practices

  • Start with low retry counts (2-3) and increase if needed
  • Use higher retry counts for critical operations
  • Set appropriate timeouts to avoid long waits
  • Handle final failures gracefully in your application
  • Monitor retry patterns to identify infrastructure issues

Disable Retries

To disable automatic retries completely:

const gboxSDK = new GboxSDK({
  apiKey: process.env["GBOX_API_KEY"],
  maxRetries: 0, // Disable retries
});