tensorone logo

CLI

Deploying a Project

Develop and deploy your project entirely on Tensor One's infrastructure.


With Tensor One projects, you can create and implement Serverless Endpoints without the need for manual container management or Docker expertise. Because code changes are automatically reflected in a live environment without requiring rebuilding or redeploying Docker images, this speeds up development.

How to Set Up a Basic Endpoint

This tutorial will teach you how to obtain the IP address of the machine that is executing your code. By the end, you will know how to deploy your code as a Serverless Endpoint, interact with it locally and on Tensor One, and set up a project environment.

Prerequisites

  • Installed tensoronecli
  • Python 3.8+

Step 1: Set Up Project Environment

Configure your CLI with your API key:

tensoronecli config --apiKey <API_KEY>

Create a new project directory:

tensoronecli project create

Select Hello World and follow the prompts.

Step 2: Writing and Testing Code Locally

Navigate into the project folder:

cd my_ip

Replace the default code in src/handler.py with:

from tensoroneGPU import tensoroneClient import requests

def get_my_ip(job): response = requests.get('https://httpbin.org/ip') return response.json()['origin']

tensoroneClient.serverless.start({"handler": get_my_ip})

Test your code locally with:

python3 src/handler.py --test_input '{"input": {"prompt": ""}}'

You'll receive your local machine's IP address as output.

Step 3: Running a Development Server

Launch a live development server on a Tensor One Cluster:

tensoronecli project dev

Monitor the logs for a URL indicating successful deployment.

Step 4: Interacting with Your Code

Your project relies on the external library requests. Include it in your requirements.txt: tensoroneGPU requests

The development server automatically syncs these changes. Once synced, use curl to interact:

curl -X POST

'https://${YOUR_ENDPOINT}-8080.proxy.tpu.one/runsync'

-H 'accept: application/json'

-H 'Content-Type: application/json'

-d '{"input": {}}'

You'll receive the Cluster's IP address in the response.

Step 5: Deploying Your Endpoint

Stop your development server (Ctrl + C), and deploy to Tensor One:

tensoronecli project deploy

Once deployed, you'll see Endpoint URLs in your logs, such as:

https://api.tpo.one/v2/${YOUR_ENDPOINT}/runsync

Step 6: Interacting with Your Serverless Endpoin

Now interact directly with the deployed Endpoint:

curl -X POST

'https://api.tpu.one/v2/${YOUR_ENDPOINT}/runsync'

-H 'accept: application/json'

-H 'authorization: ${YOUR_API_KEY}'

-H 'Content-Type: application/json'

-d '{"input": {}}'

This returns the IP address of the Cluster hosting your Endpoint.

Conclusion

You've successfully created, tested, and deployed your first Tensor One Serverless Endpoint. You're now ready to explore more complex projects and capabilities within Tensor One’s powerful infrastructure.

Previous
Installing TensorOne CLI