Drives are in pre-release in the Baseten CLI (
baseten drive and baseten sandbox drive) and in the Python, TypeScript, and Go SDKs (baseten, @basetenlabs/client, @basetenlabs/sandbox, and baseten-go). Commands, methods, and responses can change. The Management API drive operations are experimental.Set up
The drive examples use the same SDKs and CLI as sandboxes. The management client creates, gets, lists, updates, and deletes drives. Mounting goes through a sandbox. Every example reads your API key from theBASETEN_API_KEY environment
variable, so keep the key out of your code.
To set your API key:
Replace <BASETEN_API_KEY> with a
personal API key or a team API key with
Full access to all team models. Other key types, such as
Invoke dedicated models, can’t create the access token that drive requests
use. The SDKs and CLI create that token for you. Then run the following
command in the shell where you run the examples:
- TypeScript
- Python
- Go
- API
- CLI
-
Run the following command to install the SDK:
-
Create the management client, which reads the key from the
environment:
Select a team
If you belong to one team, requests use it. If you belong to more than one, every drive request must name a team, or it fails. Pass the same team when you create the sandbox client. Create the drive in the team whose sandboxes mount it. Replace<TEAM_ID> with the team’s ID. Select a team
shows how to find it for a sandbox. Use that same ID here.
To pass the team:
- TypeScript
- Python
- Go
- API
- CLI
Add
teamId to each drive call, and pass it when you create the sandbox client:Create a drive
You can’t change the name or region later. Creation returns before the drive is ready. The drive is ready when its status isDEPLOYED.
Each drive name is unique in your team. Use lowercase letters, digits, and
hyphens, from 1 to 49 characters, and don’t start or end with a hyphen. If
you don’t pass a name, Baseten generates one.
shared-notes:
- TypeScript
- Python
- Go
- API
- CLI
Run the following code, which waits until the drive is ready:
Create a drive in a specific region
A drive defaults to your default sandbox region. Only sandboxes in the drive’s region can mount it, so create it in the region that your sandboxes run in. To create a drive in a specific region:- TypeScript
- Python
- Go
- API
- CLI
Run the following code. It prints the regions available to your account,
then creates the drive in
us-was-1. Replace us-was-1 with a name from
the list.Get a drive
A drive’s record holds its name, region, status, and labels, and when and by whom it was created and last updated. Its status is one of these values:
To get the drive named
shared-notes:
- TypeScript
- Python
- Go
- API
- CLI
Run the following code:
List drives
Drives are listed newest first. The SDKs fetch further pages as you iterate. To list your team’s drives:- TypeScript
- Python
- Go
- API
- CLI
Run the following code:
Filter drives
Filter by a search over drive names, by status, or by both. The status values areDEPLOYING, DEPLOYED, FAILED, and DELETING, and you can pass more
than one.
To list drives with notes in their name that failed:
- TypeScript
- Python
- Go
- API
- CLI
Run the following code:
Replace drive labels
Labels are the only part of a drive you can change. The labels you send replace the drive’s current labels. They aren’t merged with the labels already on it. To set the labels ofshared-notes to project=alpha and env=dev:
- TypeScript
- Python
- Go
- API
- CLI
Run the following code:To remove every label, pass
labels: {}.Delete a drive
Delete a drive when no sandbox needs its files anymore. Before you delete a drive, unmount it from every sandbox that has it mounted. Baseten doesn’t block deleting a drive that’s still mounted, and a sandbox that has it mounted keeps the mount after the drive is gone, still able to read and write there. Deletion continues after the call returns, and the drive’s status isDELETING until it’s gone.
To delete the drive named shared-notes:
- TypeScript
- Python
- Go
- API
- CLI
Run the following code:
DELETING. To confirm the drive is gone,
get the drive. Once it’s gone, the request returns HTTP 404.
Next steps
Mount drives
Mount the drive in a running sandbox.
Drives
Decide when a drive fits better than a sandbox volume.