baseten-go

module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: MIT

README

Baseten Go SDK

Release Go Reference

Go SDK for Baseten. See the API documentation and usage below.

⚠️ SDK may change in incompatible ways between releases until the SDK reaches 1.0.

Install

go get github.com/basetenlabs/baseten-go

Usage

The SDK is a thin client over the Baseten management and inference APIs, plus a few operations that take more than one call, such as pushing a model. It has no dependencies of its own.

Calling the API
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/basetenlabs/baseten-go/client"
	"github.com/basetenlabs/baseten-go/client/managementapi"
)

func main() {
	// Create a management client
	cl, err := client.NewManagementClient(client.ManagementClientOptions{
		APIKey: "my-api-key",
	})
	if err != nil {
		log.Fatal(err)
	}

	// List all models
	resp, err := cl.API().GetModels(context.Background(), managementapi.GetV1ModelsParams{})
	if err != nil {
		log.Fatal(err)
	}

	// Print each model name
	for _, m := range resp.Models {
		fmt.Println(m.Name)
	}
}
Pushing a model

PushModel validates the push, builds a tar archive of the model directory, uploads it, and creates the model or adds a deployment to an existing one. Since the SDK has no dependencies, the caller supplies the upload itself:

// The parsed config.yaml is what the server builds from; the raw text is kept
// verbatim on the deployment for display.
raw, err := os.ReadFile("./my-model/config.yaml")
if err != nil {
	log.Fatal(err)
}
var config map[string]any
if err := yaml.Unmarshal(raw, &config); err != nil {
	log.Fatal(err)
}

result, err := cl.PushModel(context.Background(), client.PushModelOptions{
	Config:          config,
	RawConfig:       string(raw),
	Archive:         modelarchive.BuildModelArchiveOptions{Dir: "./my-model"},
	EnvironmentName: "production",
	ModelUploader: func(ctx context.Context, upload client.ModelUpload) error {
		s3Client := s3.NewFromConfig(aws.Config{
			Region: upload.Region,
			Credentials: credentials.NewStaticCredentialsProvider(
				upload.AccessKeyID, upload.SecretAccessKey, upload.SessionToken),
		})
		_, err := transfermanager.New(s3Client).UploadObject(ctx, &transfermanager.UploadObjectInput{
			Bucket: &upload.Bucket,
			Key:    &upload.Key,
			Body:   upload.Body,
		})
		return err
	},
})
if err != nil {
	log.Fatal(err)
}

// The deployment is not live yet; poll it to wait for a terminal status.
fmt.Println(result.Model.Id, result.Deployment.Id, result.Deployment.Status)

Directories

Path Synopsis
Package client provides Go clients for the Baseten management, inference, and sandbox APIs.
Package client provides Go clients for the Baseten management, inference, and sandbox APIs.
inferenceapi
Package inferenceapi is a generated client for the Baseten inferenceapi.
Package inferenceapi is a generated client for the Baseten inferenceapi.
managementapi
Package managementapi is a generated client for the Baseten managementapi.
Package managementapi is a generated client for the Baseten managementapi.
modelarchive
Package modelarchive builds uncompressed tar archives of model directories for upload to Baseten.
Package modelarchive builds uncompressed tar archives of model directories for upload to Baseten.
modelconfig
Package modelconfig contains generated types for Baseten model configuration (also known as Truss config).
Package modelconfig contains generated types for Baseten model configuration (also known as Truss config).
sandboxapi
Package sandboxapi is a generated client for the Baseten sandboxapi.
Package sandboxapi is a generated client for the Baseten sandboxapi.
internal
require
Package require loosely mimics testify/require but keeps the dependency out of the module.
Package require loosely mimics testify/require but keeps the dependency out of the module.
volume
Package volume implements the client side of the BDN volume transfer protocol: the canonical wire records, source scanning and chunking, and the push and pull engines.
Package volume implements the client side of the BDN volume transfer protocol: the canonical wire records, source scanning and chunking, and the push and pull engines.
volume/bdn
Package bdn is the HTTP client for BDN, the data-plane API of the volume service — the thing a bdn:// ref names and a bdn_endpoint points at.
Package bdn is the HTTP client for BDN, the data-plane API of the volume service — the thing a bdn:// ref names and a bdn_endpoint points at.
volume/limiter
Package limiter is an additive-increase/multiplicative-decrease concurrency limiter with a latency-gradient soft-stall detector, for governing how many object operations a transfer runs against one origin at a time.
Package limiter is an additive-increase/multiplicative-decrease concurrency limiter with a latency-gradient soft-stall detector, for governing how many object operations a transfer runs against one origin at a time.
volume/transfer
Package transfer runs a push or a pull: it drives the protocol client through an upload session or a download, applying the concurrency limits and reporting progress.
Package transfer runs a push or a pull: it drives the protocol client through an upload session or a download, applying the concurrency limits and reporting progress.
Package sandbox creates and works with Baseten sandboxes.
Package sandbox creates and works with Baseten sandboxes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL