tensorone logo

SDKs

Python API

This document outlines the core functionalities provided by the Tensor One API, including how to interact with Endpoints, manage Templates, and list available GPUs. These operations let you dynamically manage computational resources within the Tensor One environment.


Get Endpoints

To retrieve a comprehensive list of all available endpoint configurations within Tensor One , you can use the get_endpoints() function. This function returns a list of endpoint configurations, allowing you to understand what's available for use in your projects.

import tensorone
import os

tensorone.api_key = os.getenv("TENSORONE_API_KEY")

# Fetching all available endpoints
endpoints = tensorone.get_endpoints()

# Displaying the list of endpoints
print(endpoints)

Create Template

Templates in Tensor One serve as predefined configurations for setting up environments efficiently. The create_template() function facilitates the creation of new templates by specifying a name and a Docker image.

import tensorone
import os

tensorone.api_key = os.getenv("TENSORONE_API_KEY")

try:
    # Creating a new template with a specified name and Docker image
    new_template = tensorone.create_template(
        name="test",
        image_name="tensorone/base:0.1.0"
    )

    # Output the created template details
    print(new_template)

except tensorone.error.QueryError as err:
    # Handling potential errors during template creation
    print(err)
    print(err.query)

Create Endpoint

Creating a new endpoint with the create_endpoint() function. This function requires you to specify a name and a template_id. Additional configurations such as GPUs, number of Workers, and more can also be specified depending your requirements.

import tensorone
import os

tensorone.api_key = os.getenv("TENSORONE_API_KEY")

try:
    # Creating a template to use with the new endpoint
    new_template = tensorone.create_template(
        name="test",
        image_name="tensorone/base:0.4.4",
        is_serverless=True
    )

    # Output the created template details
    print(new_template)

    # Creating a new endpoint using the previously created template
    new_endpoint = tensorone.create_endpoint(
        name="test",
        template_id=new_template["id"],
        gpu_ids="AMPERE_16",
        workers_min=0,
        workers_max=1,
    )

    # Output the created endpoint details
    print(new_endpoint)

except tensorone.error.QueryError as err:
    # Handling potential errors during endpoint creation
    print(err)
    print(err.query)

Get GPUs

For understanding the computational resources available, the get_gpus() function lists all GPUs that can be allocated to endpoints in Tensor One . This enables optimal resource selection based on your computational needs.

import tensorone
import json
import os

tensorone.api_key = os.getenv("TENSORONE_API_KEY")

# Fetching all available GPUs
gpus = tensorone.get_gpus()

# Displaying the GPUs in a formatted manner
print(json.dumps(gpus, indent=2))

Get GPU by Id

Use get_gpu() and pass in a GPU Id to retrieve details about a specific GPU model by its ID. This is useful when understanding the capabilities and costs associated with various GPU models.

import tensorone
import json
import os

tensorone.api_key = os.getenv("TENSORONE_API_KEY")
gpus = tensorone.get_gpu("NVIDIA A100 80GB PCIe")

print(json.dumps(gpus, indent=2))

Through these functionalities, the Tensor One API enables efficient and flexible management of computational resources, catering to a wide range of project requirements.

Previous
Python