How to Use the Tensor One JavaScript SDK

The Tensor One JavaScript SDK allows you to build web applications, automate backend processes, and interact with the Tensor One API using Node.js or browser-based environments.

Set Up the SDK

Ensure you have Node.js and npm or Yarn installed. Install the SDK:
npm install --save tensorone-sdk
# or
yarn add tensorone-sdk
This will add tensorone-sdk to your package.json dependencies.

Add Your API Key

Import the SDK and initialize it using your API key and endpoint ID. Warning: Use environment variables to store sensitive credentials securely.

Example (Node.js / ESM)

import tensoroneSdk from 'tensorone-sdk'

const { TENSORONE_API_KEY, ENDPOINT_ID } = process.env

const tensorone = tensoroneSdk(TENSORONE_API_KEY)
const endpoint = tensorone.endpoint(ENDPOINT_ID)
This code:
  • Imports the SDK
  • Initializes the client using your API key
  • Prepares a reference to your endpoint
Note: The Tensor One SDK is based on ES Modules and supports asynchronous functions.

Secure Your API Key

Never hardcode your API key in code.

Best Practice: Use a .env file

TENSORONE_API_KEY=your-api-key
ENDPOINT_ID=your-endpoint-id
Then load it with dotenv:
import 'dotenv/config'