đ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.
All API requests should be made to https://api.cloudnexus.io/v3. The API uses standard HTTP methods and returns JSON responses.
CLI Installation
Install the CloudNexus CLI using your preferred package manager. The CLI is available for macOS, Linux, and Windows.
$ 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)
$ curl -fsSL https://cli.cloudnexus.io/install.sh | sudo sh ==> Installing CloudNexus CLI v3.2.1 ==> CloudNexus CLI installed to /usr/local/bin/cnx
PS> winget install CloudNexus.CNX Successfully installed CloudNexus CLI v3.2.1
$ 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
$ cnx auth login Opening browser for authentication... â Authenticated as sarah@cloudnexus.io â Default project: production-main
API Key Authentication
$ cnx auth login --api-key cnx_live_sk_4f8a2c... â API key validated â Configured profile: default
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
# 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
# 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
# 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
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
{
"profile": "default",
"project": "production-main",
"api_key": "cnx_live_sk_****",
"output": "human",
"auto_update": true,
"telemetry": true,
"default_region": "us-east"
}
Environment Variables
Environments
Manage multiple environments with the CLI. Switch between development, staging, and production contexts seamlessly.
# 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 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.
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
{
"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"
}
}
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
{
"name": "api-server-01",
"plan": "professional",
"region": "eu-west",
"image": "ubuntu-24.04",
"ssh_keys": ["ssh_key_abc123"],
"tags": {
"env": "production",
"team": "backend"
}
}
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| server_id | string | Required | The unique server identifier |
This action permanently deletes the server and all associated data. A 14-day data retention window applies before complete erasure.
Example Response
{
"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.
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 |
Example Response
{
"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.
| 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.
| 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
{
"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.
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
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
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.
// 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.
{
"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"
}
}
}
All error codes are documented in our Error Codes Reference. Use the request_id field when contacting support for debugging assistance.
Recent Changes
Added Rust SDK (beta), new monitoring metrics endpoint, improved webhook retry logic, and fixed CLI environment variable parsing for values containing equals signs.
Introduced multi-region deployments API, added PostgreSQL 16 support, new deployment health checks endpoint, and CLI autocomplete for zsh and fish.
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.