Skip to main content

Overview

The Limrun class is the primary entry point for interacting with the Limrun API. It provides access to all resource endpoints and handles authentication, retries, timeouts, and logging.

Constructor

Create a new Limrun client instance.
import Limrun from 'limrun';

const client = new Limrun({
  apiKey: 'your-api-key',
  baseURL: 'https://api.limrun.com',
  timeout: 60000,
  maxRetries: 2,
});

Parameters

options
ClientOptions
Configuration options for the client. See Client Options for detailed information.

Properties

Resource Properties

The Limrun client exposes the following resource properties for accessing API endpoints:
androidInstances
AndroidInstances
Access Android instance operations. See Android Instances for available methods.
const instance = await client.androidInstances.create({
  spec: {
    region: 'us-west-2',
    inactivityTimeout: '10m',
  },
});
iosInstances
IosInstances
Access iOS instance operations. See iOS Instances for available methods.
const instance = await client.iosInstances.create({
  spec: {
    region: 'us-west-2',
    inactivityTimeout: '10m',
  },
});
assets
Assets
Access asset management operations. See Assets for available methods.
const asset = await client.assets.getOrUpload({
  path: './my-app.apk',
});

Configuration Properties

apiKey
string | null
The API key used for authentication. Can be null if using custom authentication headers.
baseURL
string
The base URL for API requests. Defaults to https://api.limrun.com.
maxRetries
number
Maximum number of retry attempts for failed requests. Defaults to 2.
timeout
number
Request timeout in milliseconds. Defaults to 300000 (5 minutes).
logger
Logger
The logger instance used for logging. Defaults to console.
logLevel
LogLevel | undefined
The current log level. Can be 'debug', 'info', 'warn', or 'error'.
fetchOptions
RequestInit | undefined
Additional fetch options passed to all requests.

HTTP Methods

The Limrun client provides low-level HTTP methods for making custom API requests. These methods are primarily used internally by resource classes but can be used directly for custom integrations.

get()

Make a GET request.
get<Rsp>(path: string, opts?: RequestOptions): APIPromise<Rsp>
path
string
required
The API endpoint path (e.g., /v1/android_instances).
opts
RequestOptions
Additional request options including query parameters, headers, and timeout overrides.
Example:
const response = await client.get('/v1/android_instances/123');

post()

Make a POST request.
post<Rsp>(path: string, opts?: RequestOptions): APIPromise<Rsp>
path
string
required
The API endpoint path.
opts
RequestOptions
Request options including body, query parameters, and headers.
Example:
const response = await client.post('/v1/android_instances', {
  body: {
    spec: {
      region: 'us-west-2',
      inactivityTimeout: '10m',
    },
  },
});

patch()

Make a PATCH request.
patch<Rsp>(path: string, opts?: RequestOptions): APIPromise<Rsp>
path
string
required
The API endpoint path.
opts
RequestOptions
Request options including body, query parameters, and headers.

put()

Make a PUT request.
put<Rsp>(path: string, opts?: RequestOptions): APIPromise<Rsp>
path
string
required
The API endpoint path.
opts
RequestOptions
Request options including body, query parameters, and headers.

delete()

Make a DELETE request.
delete<Rsp>(path: string, opts?: RequestOptions): APIPromise<Rsp>
path
string
required
The API endpoint path.
opts
RequestOptions
Request options including query parameters and headers.
Example:
await client.delete('/v1/android_instances/123');

Instance Methods

withOptions()

Create a new client instance with modified options, inheriting all settings from the current client.
withOptions(options: Partial<ClientOptions>): Limrun
options
Partial<ClientOptions>
required
Options to override in the new client instance.
Returns: A new Limrun instance with the specified options. Example:
// Create a new client with a different timeout
const clientWithTimeout = client.withOptions({
  timeout: 120000, // 2 minutes
});

// Create a new client for a different region
const euClient = client.withOptions({
  baseURL: 'https://eu.api.limrun.com',
});

Static Properties

Error Classes

The Limrun class exposes error classes as static properties:
Limrun.LimrunError
class
Base error class for all Limrun SDK errors.
Limrun.APIError
class
Error thrown when the API returns an error response.
Limrun.APIConnectionError
class
Error thrown when a connection to the API fails.
Limrun.APIConnectionTimeoutError
class
Error thrown when a request times out.
Limrun.APIUserAbortError
class
Error thrown when a request is aborted by the user.
Limrun.NotFoundError
class
Error thrown for 404 responses.
Limrun.ConflictError
class
Error thrown for 409 conflict responses.
Limrun.RateLimitError
class
Error thrown when rate limits are exceeded.
Limrun.BadRequestError
class
Error thrown for 400 bad request responses.
Limrun.AuthenticationError
class
Error thrown for authentication failures.
Limrun.InternalServerError
class
Error thrown for 500 internal server errors.
Limrun.PermissionDeniedError
class
Error thrown for 403 permission denied responses.
Limrun.UnprocessableEntityError
class
Error thrown for 422 unprocessable entity responses.

Utility Methods

Limrun.toFile
function
Utility function for creating file uploads. See Uploads for details.

Constants

Limrun.DEFAULT_TIMEOUT
number
Default timeout value in milliseconds. Set to 300000 (5 minutes).

Usage Examples

Basic Initialization

import Limrun from 'limrun';

const client = new Limrun({
  apiKey: process.env.LIM_API_KEY,
});

With Environment Variables

import Limrun from 'limrun';

// Automatically reads from LIM_API_KEY and LIMRUN_BASE_URL environment variables
const client = new Limrun();

Custom Configuration

import Limrun from 'limrun';

const client = new Limrun({
  apiKey: 'your-api-key',
  baseURL: 'https://api.limrun.com',
  timeout: 60000,
  maxRetries: 3,
  logLevel: 'debug',
  fetchOptions: {
    headers: {
      'X-Custom-Header': 'value',
    },
  },
});

Error Handling

import Limrun from 'limrun';

const client = new Limrun();

try {
  const instance = await client.androidInstances.create({
    spec: {
      region: 'us-west-2',
      inactivityTimeout: '10m',
    },
  });
  console.log('Instance created:', instance.metadata.id);
} catch (error) {
  if (error instanceof Limrun.AuthenticationError) {
    console.error('Authentication failed - check your API key');
  } else if (error instanceof Limrun.RateLimitError) {
    console.error('Rate limit exceeded - please retry later');
  } else if (error instanceof Limrun.APIConnectionTimeoutError) {
    console.error('Request timed out');
  } else {
    console.error('An error occurred:', error);
  }
}

Using Multiple Clients

import Limrun from 'limrun';

// Production client
const prodClient = new Limrun({
  apiKey: process.env.PROD_API_KEY,
  baseURL: 'https://api.limrun.com',
});

// Staging client
const stagingClient = new Limrun({
  apiKey: process.env.STAGING_API_KEY,
  baseURL: 'https://staging.api.limrun.com',
});

// Use the appropriate client
const instance = await prodClient.androidInstances.create({
  spec: { region: 'us-west-2', inactivityTimeout: '10m' },
});

See Also

Build docs developers (and LLMs) love