🔍 ⌘K

📌CLI & API Reference

Complete documentation for the CloudNexus command-line interface and RESTful API. Manage your cloud infrastructure programmatically at scale.

Overview

The CloudNexus CLI (cnx) and REST API provide full programmatic control over your cloud infrastructure. Create servers, manage databases, deploy applications, and monitor resources — all from your terminal or application code.

â„šī¸
API Base URL

All API requests should be made to https://api.cloudnexus.io/v3. The API uses standard HTTP methods and returns JSON responses.

1,000
Requests / minute
10K
Requests / hour
100ms
Avg. Response Time

CLI Installation

Install the CloudNexus CLI using your preferred package manager. The CLI is available for macOS, Linux, and Windows.

bash
$ brew install cloudnexus/tap/cnx
==> Downloading CloudNexus CLI v3.2.1
==> Installed CloudNexus CLI v3.2.1
$ cnx version
CloudNexus CLI v3.2.1 (2025-01-15)
bash
$ curl -fsSL https://cli.cloudnexus.io/install.sh | sudo sh
==> Installing CloudNexus CLI v3.2.1
==> CloudNexus CLI installed to /usr/local/bin/cnx
powershell
PS> winget install CloudNexus.CNX
Successfully installed CloudNexus CLI v3.2.1
bash
$ npm install -g @cloudnexus/cli
added 1 package in 3.2s
$ cnx version
CloudNexus CLI v3.2.1 (2025-01-15)

CLI Authentication

Authenticate the CLI with your CloudNexus account. You can use API keys or OAuth tokens for authentication.

Quick Authentication

bash
$ cnx auth login
Opening browser for authentication...
✓ Authenticated as sarah@cloudnexus.io
✓ Default project: production-main

API Key Authentication

bash
$ cnx auth login --api-key cnx_live_sk_4f8a2c...
✓ API key validated
✓ Configured profile: default
âš ī¸
Security Notice

Never commit API keys to version control. Use environment variables or secret managers to store credentials. Rotate keys regularly and use restricted-scoped keys for CI/CD pipelines.

CLI Commands

The CloudNexus CLI supports a wide range of commands for managing your infrastructure. All commands support --json output for scripting.

Server Management

bash
# List all servers
$ cnx servers list
ID              NAME              REGION     STATUS   CPU   MEMORY
srv_a8f3k2m   web-prod-01       us-east    running  2     8GB
srv_b7g4j1n   api-prod-01       eu-west    running  4     16GB
srv_c6h5i0o   db-primary        us-east    running  8     32GB

# Create a new server
$ cnx servers create --name web-prod-02 --plan professional --region us-east
✓ Server created: srv_d9i6l2p
  IP: 203.0.113.42
  SSH: ssh root@203.0.113.42

# Scale a server
$ cnx servers resize srv_a8f3k2m --plan enterprise
✓ Server resizing in progress...
✓ Server resized to enterprise plan

# Delete a server
$ cnx servers delete srv_a8f3k2m --confirm
✓ Server srv_a8f3k2m deleted

Database Operations

bash
# Create a PostgreSQL database
$ cnx databases create --name app-db --engine postgresql --version 16
✓ Database created: db_x3y7z1a
  Connection: postgresql://cnx:***@db-x3y7z1a.cloudnexus.io:5432/app-db

# List databases
$ cnx databases list --json
[{"id":"db_x3y7z1a","name":"app-db","engine":"postgresql","status":"active"},...]

# Create a read replica
$ cnx databases replica create db_x3y7z1a --region eu-west
✓ Read replica created: db_w2v6u9b

Deployment Commands

bash
# Deploy from Git repository
$ cnx deploy git --repo github.com/your-org/your-app --branch main
✓ Building application...
✓ Deploying to cloudnexus.app
✓ Deployment complete: https://your-app.cloudnexus.app

# Deploy a Docker image
$ cnx deploy docker --image your-app:latest --env NODE_ENV=production
✓ Container deployed successfully

# View deployment logs
$ cnx deploy logs --follow dep_abc123
2025-01-15T10:30:00Z [INFO] Application started on port 3000
✅
Pro Tip

Use cnx --json with any command to get machine-readable output, perfect for scripting and CI/CD pipelines. Combine with jq for powerful queries.

Configuration

The CLI configuration is stored in ~/.cloudnexus/config.json. You can also set configuration via environment variables.

Configuration File

json
{
  "profile": "default",
  "project": "production-main",
  "api_key": "cnx_live_sk_****",
  "output": "human",
  "auto_update": true,
  "telemetry": true,
  "default_region": "us-east"
}

Environment Variables

CNX_API_KEY cnx_live_sk_... Your API key for authentication
CNX_PROJECT production-main Default project identifier
CNX_REGION us-east Default deployment region
CNX_OUTPUT json Output format: human, json, yaml
CNX_TIMEOUT 300 Request timeout in seconds
CNX_RETRY 3 Max retry attempts

Environments

Manage multiple environments with the CLI. Switch between development, staging, and production contexts seamlessly.

bash
# List environments
$ cnx environments list
NAME          REGION       STATUS     SERVERS
development   us-east      active     3
staging       eu-west      active     5
production    multi        active     12

# Switch to an environment
$ cnx environments use production
✓ Switched to: production

# Set environment variables
$ cnx environments vars set production --var DB_URL=postgresql://...
✓ Variable DB_URL set for production

# List environment variables
$ cnx environments vars list production
DB_URL        postgresql://***@...
REDIS_URL     redis://***@...
API_KEY       cnx_live_sk_****

API Authentication

Authenticate API requests using Bearer tokens in the Authorization header. Generate API keys from your CloudNexus dashboard.

# cURL Example
$ curl -X GET https://api.cloudnexus.io/v3/servers \
  -H "Authorization: Bearer cnx_live_sk_4f8a2c..." \
  -H "Content-Type: application/json"

# Node.js Example (using axios)
const axios = require('axios');

const response = await axios.get(
  'https://api.cloudnexus.io/v3/servers',
  {
    headers: {
      'Authorization': `Bearer ${process.env.CNX_API_KEY}`,
    },
  }
);

# Python Example (using requests)
import requests

response = requests.get(
  'https://api.cloudnexus.io/v3/servers',
  headers={
    'Authorization': f'Bearer {os.environ["CNX_API_KEY"]}',
  }
)
🚨
API Key Security

API keys have full access to your account. Use scoped keys with minimal permissions. Never expose keys in client-side code, public repositories, or browser applications.

Servers API

Manage cloud servers programmatically. Create, configure, scale, and destroy virtual machines.

GET /v3/servers List all servers

Query Parameters

Parameter Type Required Description
region string Optional Filter by region (e.g., us-east, eu-west)
status string Optional Filter by status (running, stopped, creating)
limit integer Optional Max results per page (default: 20, max: 100)
cursor string Optional Pagination cursor for next page

Example Response

json
{
  "data": [
    {
      "id": "srv_a8f3k2m",
      "name": "web-prod-01",
      "region": "us-east",
      "status": "running",
      "plan": "professional",
      "ipv4": "203.0.113.42",
      "ipv6": "2001:db8::1",
      "cpu": 2,
      "memory_gb": 8,
      "storage_gb": 80,
      "created_at": "2025-01-10T08:30:00Z"
    }
  ],
  "meta": {
    "total": 12,
    "next_cursor": "eyJpZCI6MTJ9"
  }
}
POST /v3/servers Create a new server

Request Body

Parameter Type Required Description
name string Required Server name (max 64 chars, alphanumeric + hyphens)
plan string Required Server plan: starter, professional, enterprise
region string Required Deployment region ID
image string Optional OS image ID (default: ubuntu-24.04)
ssh_keys array Optional Array of SSH key IDs to deploy
tags object Optional Custom key-value tags for organization

Example Request

json
{
  "name": "api-server-01",
  "plan": "professional",
  "region": "eu-west",
  "image": "ubuntu-24.04",
  "ssh_keys": ["ssh_key_abc123"],
  "tags": {
    "env": "production",
    "team": "backend"
  }
}
PUT /v3/servers/{server_id} Update server configuration

Path Parameters

Parameter Type Required Description
server_id string Required The unique server identifier
DELETE /v3/servers/{server_id} Delete a server
âš ī¸
Destructive Action

This action permanently deletes the server and all associated data. A 14-day data retention window applies before complete erasure.

Example Response

json
{
  "id": "srv_a8f3k2m",
  "status": "deleting",
  "estimated_completion": "2025-01-15T10:35:00Z"
}

Databases API

Provision and manage managed database instances including PostgreSQL, MySQL, Redis, and MongoDB.

POST /v3/databases Create a database instance

Request Body

Parameter Type Required Description
name string Required Database name
engine string Required Database engine: postgresql, mysql, redis, mongodb
version string Optional Engine version (e.g., 16 for PostgreSQL)
plan string Required Plan tier: starter, professional, enterprise
region string Required Deployment region
GET /v3/databases/{db_id}/connection Get connection string

Example Response

json
{
  "connection_string": "postgresql://cnx_user:***@db-x3y7z1a.cloudnexus.io:5432/app-db",
  "host": "db-x3y7z1a.cloudnexus.io",
  "port": 5432,
  "database": "app-db",
  "username": "cnx_user",
  "ssl_required": true
}

Deployments API

Deploy applications from Git repositories, Docker images, or source code packages.

POST /v3/deployments Create a deployment
Parameter Type Required Description
type string Required Deployment type: git, docker, package
repo_url string Conditional Git repository URL (required for git type)
branch string Optional Git branch to deploy (default: main)
docker_image string Conditional Docker image reference (required for docker type)
env object Optional Environment variables as key-value pairs

Monitoring API

Access real-time metrics, logs, and alerting configurations for your infrastructure.

GET /v3/monitoring/metrics/{resource_id} Get resource metrics
Parameter Type Required Description
resource_id string Required Resource ID (server, database, etc.)
period string Optional Time period: 5m, 1h, 6h, 24h, 7d
metrics array Optional Specific metrics: cpu, memory, disk, network

Example Response

json
{
  "resource_id": "srv_a8f3k2m",
  "period": "24h",
  "metrics": {
    "cpu": {
      "avg": 34.2,
      "max": 78.5,
      "p99": 65.3,
      "unit": "percent"
    },
    "memory": {
      "avg": 5.2,
      "max": 7.1,
      "unit": "GB"
    },
    "network": {
      "in_avg": 45.8,
      "out_avg": 120.3,
      "unit": "Mbps"
    }
  }
}

HTTP Status Codes

The API uses standard HTTP status codes to indicate success or failure of requests.

200 OK — Request succeeded
201 Created — Resource created successfully
204 No Content — Delete succeeded
400 Bad Request — Invalid request parameters
401 Unauthorized — Invalid or missing API key
403 Forbidden — Insufficient permissions
404 Not Found — Resource does not exist
429 Too Many Requests — Rate limit exceeded
500 Internal Server Error — Unexpected server error
503 Service Unavailable — Temporary maintenance

SDKs & Libraries

Official SDKs are available for popular languages. All SDKs are open-source and automatically generated from our OpenAPI specification.

đŸŸĸ

Node.js

Promise-based SDK with TypeScript support and full IntelliSense.

npm install @cloudnexus/sdk
🐍

Python

Type-hinted SDK with async/await support and auto-completion.

pip install cloudnexus
🐹

Go

Idiomatic Go SDK with context support and goroutine-safe clients.

go get github.com/cloudnexus/go-sdk
đŸĻ€

Rust

Zero-cost abstractions with Tokio async runtime support.

cargo add cloudnexus
💎

Ruby

Elegant Ruby gem with Rails integration and DSL syntax.

gem install cloudnexus
☕

Java

Java SDK with Spring Boot starter and reactive support.

gradle implementation 'io.cloudnexus:-sdk:3.2.1'

Node.js SDK Example

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

// Initialize the client
const cnx = new CloudNexus({
  apiKey: process.env.CNX_API_KEY,
  project: 'production-main',
});

// List all servers
const servers = await cnx.servers.list({
  region: 'us-east',
  status: 'running',
});

// Create a new server
const server = await cnx.servers.create({
  name: 'api-server',
  plan: 'professional',
  region: 'eu-west',
});

console.log(`Server created: ${server.id}`);

// Deploy an application
const deployment = await cnx.deployments.create({
  type: 'git',
  repoUrl: 'https://github.com/org/app',
  branch: 'main',
  env: {
    NODE_ENV: 'production',
    DATABASE_URL: process.env.DATABASE_URL,
  },
});

console.log(`Deployed to: ${deployment.url}`);

Python SDK Example

python
import os
import cloudnexus

# Initialize the client
cnx = cloudnexus.CloudNexus(
    api_key=os.environ["CNX_API_KEY"],
    project="production-main",
)

# List all servers
servers = cnx.servers.list(
    region="us-east",
    status="running",
)

# Create a new server
server = cnx.servers.create(
    name="api-server",
    plan="professional",
    region="eu-west",
)

print(f"Server created: {server.id}")

# Deploy from Git
deployment = cnx.deployments.create(
    type="git",
    repo_url="https://github.com/org/app",
    branch="main",
    env={"NODE_ENV": "production"},
)

print(f"Deployed to: {deployment.url}")

Webhooks

Configure webhooks to receive real-time notifications about infrastructure events such as server status changes, deployment completions, and alert triggers.

json
// Webhook payload example
{
  "id": "evt_9x8w7v6u",
  "type": "server.status_changed",
  "timestamp": "2025-01-15T10:30:00Z",
  "data": {
    "server_id": "srv_a8f3k2m",
    "server_name": "web-prod-01",
    "previous_status": "stopped",
    "new_status": "running",
    "region": "us-east"
  }
}

Supported Events

Event Description
server.created A new server was provisioned
server.status_changed Server status changed (running/stopped/error)
server.deleted Server was deleted
deployment.started Deployment build started
deployment.completed Deployment finished successfully
deployment.failed Deployment failed
alert.triggered Monitoring alert was triggered
database.backup_completed Database backup finished

Error Response Format

Errors follow a consistent format with a machine-readable code and human-readable message.

json
{
  "error": {
    "code": "SERVER_NOT_FOUND",
    "message": "The server 'srv_invalid' does not exist in this project.",
    "status": 404,
    "request_id": "req_abc123xyz",
    "details": {
      "resource_type": "server",
      "resource_id": "srv_invalid"
    }
  }
}
â„šī¸
Error Codes Reference

All error codes are documented in our Error Codes Reference. Use the request_id field when contacting support for debugging assistance.

Recent Changes

🎉
v3.2.1 — January 15, 2025

Added Rust SDK (beta), new monitoring metrics endpoint, improved webhook retry logic, and fixed CLI environment variable parsing for values containing equals signs.

📋
v3.2.0 — January 1, 2025

Introduced multi-region deployments API, added PostgreSQL 16 support, new deployment health checks endpoint, and CLI autocomplete for zsh and fish.

âš ī¸
v3.0 — Breaking Changes (December 1, 2024)

API v2 deprecated. All v2 endpoints will stop working on March 1, 2025. Migrate using the Migration Guide. Key changes: pagination now uses cursor-based approach, response format unified, authentication moved to Bearer tokens.