Python client
Start, manage and stop instances
Cortecs-py is a ligthweight Python wrapper of our REST API. It provides you with the necessary tools to dynamically manage your instances directly from your workflow.
Setup
In order to use the API you need to create your access credentials in your profile page first. Before accessing the API make sure your environment variables are set:
OPENAI_API_KEY
-> use your cortecs api keyCORTECS_CLIENT_ID
CORTECS_CLIENT_SECRET
Methods Overview
The client helps you start, manage and stop your models.
Method | Description | Return |
---|---|---|
Starts an instance. | An | |
Restarts a stopped instance by the given | An | |
If an instance with the same | An | |
Polls an instance until it is running. | An | |
Retrieves an | An | |
Retrieves only the | An | |
Retrieves a list of all instances (both running and stopped). | A list of | |
Retrieves a list of all running instances. | A list of | |
Stops an instance by its |
| |
Stops all running instances. | A list of | |
Deletes an instance by its | The | |
Deletes all instances. They must first be stopped to be deleted. | A list of |
*If not using poll=True, the Instance object won't be complete. For more information visit the Objects page.
Additionally, the client can be used to retrieve information about models and hardware types.
Method | Description | Return |
---|---|---|
get_all_models | Retrieve a list of all supported | A list of |
get_all_hardware_types | Retrieve a list of all supported | A list of |
get_available_hardware_types | Retrieve a list of the | A list of |
Starting instances
The client offers several methods for starting an instance: start
, ensure_instance
, and restart
. Given that model startup times can take up to a few minutes (unless using Instant Provisioning), users have the option to wait for the instance to become ready by setting the poll
argument to True
. Alternatively, users can set the poll
argument to False
and use the poll_instance
method separately for more control.
start
start
Start an instance with the given instance arguments. It accepts the same arguments as ensure_instance
.
ensure_instance
ensure_instance
Checks if an instance with the same arguments is already running, in which case that one is returned. If there is an equivalent pending instance, that one is returned. If there is an equivalent stopped instance, it's restarted and returned. Otherwise, a new instance with the given arguments is started.
Both start
and ensure_instance
accept the following arguments:
Parameters | Description | Default |
---|---|---|
| The model id (equivalent to HuggingFace name with the slash replaced by two dashes, eg. | Required |
| The id of the HardwareType to use, eg. | The recommended hardware configuration |
| The maximum context length the model should be initialized with. A larger context length slows down inference, so it's good practice to limit it according to your use case. | 32k tokens or the maximum context length of the corresponding hardware configuration (if it is smaller than 32k) |
| The interval in which the instance should be billed. Can be |
|
| If |
|
restart
restart
Restart an instance that has already been started and stopped by its instance_id
.
Parameters | Description | Default |
---|---|---|
| The id of the instance. | Required |
| If |
|
poll_instance
poll_instance
Poll an instance until it is running.
Parameters | Description | Default |
---|---|---|
| The id of the instance. | Required |
| The interval in seconds between each status check. |
|
| The maximum number of retries before raising an error. | 150 |
Example
Managing instances
get_instance
get_instance
Get an instance by its id.
Parameters | Description | Default |
---|---|---|
| The id of the instance. | Required |
get_instance_status
get_instance_status
Get the instance status by its id.
Parameters | Description | Default |
---|---|---|
| The id of the instance. | Required |
get_all_instances
get_all_instances
Get all instances.
get_running_instances
get_running_instances
Get running instances.
Example
Stopping instances
Stopping an instance lets the user halt an instance as soon as a job is complete, avoiding additional costs while preserving the instance setup for future convenience.
stop
stop
Stop a specific instance by its id.
Parameters | Description | Default |
---|---|---|
| The id of the instance. | Required |
stop_all
stop_all
Stop all running instances.
Example
Deleting instances
When a setup is no longer needed, the instance can be deleted from the user's console. Note that
delete
delete
Delete a stopped instance. Note that the instance must be stopped to be deleted, otherwise the method produces an error.
Parameters | Description | Default |
---|---|---|
| The id of the instance. | Required |
delete_all
delete_all
Delete all instances.
Parameters | Description | Default |
---|---|---|
| If set to | False |
Example
Last updated