Last Verified: 2025-01-27
Prerequisites
Before installing the HopX JavaScript SDK, ensure you have:- Node.js 18+ (20+ recommended for LTS support)
- npm, yarn, or pnpm (package manager)
- HopX API key - Get yours at console.hopx.dev
Install with npm
The recommended way to install the HopX JavaScript SDK:Install with yarn
Install with pnpm
Install Specific Version
Install a specific version:Install from Source
For development or to use the latest unreleased version:Building from source requires Node.js 18+, TypeScript 5.3+, and build tools. See the GitHub repository for detailed development setup instructions.
TypeScript Support
TypeScript definitions are included automatically. No additional@types package needed.
Verify Installation
Verify the installation:Set Up Authentication
The SDK requires an API key for authentication. You have three options:Option 1: Environment Variable (Recommended)
Set theHOPX_API_KEY environment variable:
Option 2: Pass API key Directly
Pass the API key when creating a sandbox:Option 3: Configuration File
Create a.env file in your project root:
dotenv package):
Get Your API key
- Sign up at console.hopx.dev
- Navigate to Settings → API Keys
- Create a new API key
- Copy the key (you’ll only see it once)
API keys are scoped to your account and have full access to create, manage, and delete sandboxes. Keep them secure.
Supported Node.js Versions
The SDK is tested and supported on:- Node.js 18.x - Minimum supported version
- Node.js 20.x - LTS, recommended for production
- Node.js 22.x - Latest LTS, fully supported
Module Systems
ES Modules (Recommended)
package.json has:
CommonJS
Dependencies
The SDK has minimal dependencies:node-fetch- HTTP client for API calls (Node.js 18+ has native fetch)ws- WebSocket client for streaming- Type definitions included
npm install @hopx-ai/sdk.
Browser Support
The SDK can be used in browsers with:- CORS Configuration - Configure your HopX account to allow browser origins
- Build Tool - Use a bundler (webpack, Vite, esbuild) to bundle the SDK
- API key Security - Never expose API keys in client-side code (use a backend proxy)
Troubleshooting
Import Errors
If you getCannot find module '@hopx-ai/sdk':
- Verify Node.js version:
node --version(should be 18+) - Check installation:
npm list @hopx-ai/sdk - Reinstall:
npm install --save @hopx-ai/sdk
TypeScript Errors
If TypeScript can’t find types:- Ensure
@hopx-ai/sdkis independencies(notdevDependencies) - Restart your TypeScript server/IDE
- Check
tsconfig.jsonincludesnode_modulesin type resolution
Authentication Errors
If you get authentication errors:- Verify API key is set:
echo $HOPX_API_KEY(Linux/macOS) orecho %HOPX_API_KEY%(Windows) - Check API key is valid at console.hopx.dev
- Ensure no extra spaces or quotes in the API key
Network Errors
If you encounter network errors:- Check internet connection
- Verify firewall allows outbound HTTPS (port 443)
- Check if you’re behind a corporate proxy (may need proxy configuration)
Related
- JavaScript SDK Quickstart - Get started with the SDK
- [API key Management](/API key) - Learn about API key security
- Sandbox Class Reference - Complete SDK reference
Next Steps
Once you’ve successfully installed the SDK:- Quickstart Guide - Create your first sandbox and run code
- API Reference - Explore the full SDK API
- CLI Installation - Install the HopX CLI

