v2.4.0

CloudNexus SDK

A high-performance, type-safe client library for interacting with the CloudNexus infrastructure API. Manage compute, networking, storage, and databases programmatically with minimal boilerplate.

Installation

Install the SDK using your preferred package manager:

npm install @cloudnexus/sdk@latest
yarn add @cloudnexus/sdk@latest
pip install cloudnexus
go get github.com/cloudnexus/sdk-go/v2

Quick Start

Initialize the client and list your active instances:

import { CloudNexus } from '@cloudnexus/sdk';

const cn = new CloudNexus({
  apiKey: process.env.CLOUDNEXUS_API_KEY,
  region: 'us-east-1'
});

async function listInstances() {
  const instances = await cn.servers.list();
  console.log(`Found ${instances.length} active servers`);
}

listInstances();
import cloudnexus

client = cloudnexus.Client(
    api_key=os.environ["CLOUDNEXUS_API_KEY"],
    region="us-east-1"
)

instances = client.servers.list()
print(f"Found {len(instances)} active servers")
package main

import (
    "fmt"
    "os"
    "github.com/cloudnexus/sdk-go/v2/client"
)

func main() {
    c := client.New(os.Getenv("CLOUDNEXUS_API_KEY"))
    instances, _ := c.Servers.List()
    fmt.Printf("Found %d active servers\n", len(instances))
}

Authentication

Generate API keys from the CloudNexus Dashboard under Settings > API Keys. The SDK automatically handles token rotation and refresh.

// Recommended: Use environment variables
export CLOUDNEXUS_API_KEY="cn_live_8f3a92b..."
export CLOUDNEXUS_ORG_ID="org_2938472"

For service accounts, use OAuth2 with JWT assertions:

const client = await CloudNexus.fromJWT({
  privateKey: fs.readFileSync('service.pem'),
  audience: 'api.cloudnexus.io'
});

Configuration

Customize SDK behavior using the configuration object:

d>30000
Parameter Type Default Description
timeout number Request timeout in milliseconds
retries number 3 Automatic retry count for failed requests
baseURL string api.cloudnexus.io Override API endpoint (for testing)
logLevel 'debug'|'info'|'warn' info SDK logging verbosity

Error Handling

The SDK throws typed errors for all API failures. Catch them using standard try/catch blocks:

try {
  await cn.servers.create({ plan: 'prod-lg' });
} catch (err) {
  if (err.isCloudNexusError()) {
    console.error(`[${err.code}] ${err.message}`);
    console.error("Request ID:", err.requestId);
  }
}