Documentation
¶
Index ¶
- Variables
- func Execute(ctx context.Context, options ExecuteOptions) error
- func FormatDeploymentLogLine(log managementapi.Log) string
- func GetAPIKey() (string, error)
- func NewAuthStore(insecureStorage bool) (*auth.Store, error)
- func OAuthConfig(host string) *oauth2.Config
- func Register[T any](path string, fn func(*CommandContext, *T) error)
- func ResolveTeam(ctx context.Context, api *managementapi.Client, input string) (string, error)
- func VerifyRunners()
- func WithHTTPClient(ctx context.Context, c *http.Client) context.Context
- func WithNow(ctx context.Context, fn func() time.Time) context.Context
- func WithS3APIClientFactory(ctx context.Context, f S3APIClientFactory) context.Context
- func WithSleep(ctx context.Context, fn func(context.Context, time.Duration) error) context.Context
- type CommandContext
- func (c *CommandContext) AuthTransport() (*auth.Transport, *Remote, error)
- func (c *CommandContext) ConfirmYesNo(title string) error
- func (c *CommandContext) IsInteractive() bool
- func (c *CommandContext) Log(v string)
- func (c *CommandContext) LogLine(v string)
- func (c *CommandContext) Logf(format string, args ...any)
- func (c *CommandContext) NewInferenceClient(flags cmd.InferenceClientFlags) (*client.InferenceClient, error)
- func (c *CommandContext) NewJSONArrayWriter() *JSONArrayWriter
- func (c *CommandContext) NewManagementClient() (*client.ManagementClient, error)
- func (c *CommandContext) NewManagementClientWithAuth(mgmtURL, authHeader string) (*client.ManagementClient, error)
- func (c *CommandContext) Now() time.Time
- func (c *CommandContext) Output(v string)
- func (c *CommandContext) OutputJSON(v any)
- func (c *CommandContext) OutputLine(v string)
- func (c *CommandContext) OutputTable(out TableOutput)
- func (c *CommandContext) Outputf(format string, args ...any)
- func (c *CommandContext) SetDefaultProfile(name string)
- func (c *CommandContext) Sleep(d time.Duration) error
- func (c *CommandContext) VerboseLog(v string)
- func (c *CommandContext) VerboseLogLine(v string)
- func (c *CommandContext) VerboseLogf(format string, args ...any)
- type DeploymentRef
- type ErrSubprocess
- type ExecuteOptions
- type JSONArrayWriter
- type ModelRef
- type Remote
- func (r *Remote) EnvironmentPredictURL(modelID, environment string) string
- func (r *Remote) HostLabel() string
- func (r *Remote) InferenceBaseURL(modelID, chainID, environment string) (string, error)
- func (r *Remote) InferenceHostHeader(modelID, chainID, environment string) (string, bool, error)
- func (r *Remote) IsDefault() bool
- func (r *Remote) LogsURL(modelID, deploymentID string) string
- func (r *Remote) ManagementURL() string
- func (r *Remote) ModelAPIInferenceURL() string
- func (r *Remote) PredictURL(modelID, deploymentID string, isDraft bool) string
- func (r *Remote) RemoteURL() string
- type S3APIClientFactory
- type TableOutput
- type TailDeploymentLogsOptions
- type TailDeploymentLogsResult
Constants ¶
This section is empty.
Variables ¶
var Version = "dev"
Version is the CLI version reported by `baseten version` and `baseten --version`. Overridden at release time via -ldflags:
-X github.com/basetenlabs/baseten-cli/internal/cmd.Version=<semver>
Functions ¶
func Execute ¶
func Execute(ctx context.Context, options ExecuteOptions) error
Execute builds the Cobra command tree and runs it.
func FormatDeploymentLogLine ¶
func FormatDeploymentLogLine(log managementapi.Log) string
FormatDeploymentLogLine renders a log record as "[YYYY-MM-DD HH:MM:SS]: (replica) message" in the local timezone. Replica segment is omitted when empty. Unparseable timestamps fall back to the raw string.
func GetAPIKey ¶
GetAPIKey returns the Baseten API key from the BASETEN_API_KEY environment variable or an ErrUsage if not set.
func NewAuthStore ¶
NewAuthStore creates an auth store using the default config directory.
func OAuthConfig ¶
OAuthConfig returns the OAuth2 configuration for the given host.
func Register ¶
func Register[T any](path string, fn func(*CommandContext, *T) error)
Register associates a run function with a command path (e.g. "api management"). Panics if the path is already registered.
func ResolveTeam ¶
ResolveTeam translates a --team flag value (team name or team ID) into a team ID by listing teams from the management API. Returns "" when input is "" so the server can route to the org's default team.
An exact match on Id wins over a name match: this lets users always pass an ID without colliding with a same-spelled name.
func VerifyRunners ¶
func VerifyRunners()
VerifyRunners panics if any command with Flags is missing a registered runner, or if a runner's flag type doesn't match.
func WithHTTPClient ¶
WithHTTPClient returns a context that overrides the HTTP client used by CommandContext and therefore all SDK clients created from it.
func WithNow ¶
WithNow returns a context that pins CommandContext.Now to fn. Intended for tests; production code uses time.Now via the default path.
func WithS3APIClientFactory ¶
func WithS3APIClientFactory(ctx context.Context, f S3APIClientFactory) context.Context
WithS3APIClientFactory returns a context that overrides how CommandContext.NewS3APIClient builds the S3 client used for archive uploads.
Types ¶
type CommandContext ¶
type CommandContext struct {
context.Context
Command *cobra.Command
Args []string
JSON bool
JSONCompact bool
JSONLines bool
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
ExitWithCode func(int)
// JQQuery is a compiled --jq expression installed by the framework. When
// non-nil, [OutputJSON] and [JSONArrayWriter.Write] route their input
// through the query before encoding. Leaves should not set this directly.
JQQuery *gojq.Query
// contains filtered or unexported fields
}
CommandContext is passed to run functions.
func (*CommandContext) AuthTransport ¶
func (c *CommandContext) AuthTransport() (*auth.Transport, *Remote, error)
AuthTransport builds an HTTP transport that injects the active session's credential on every request, regardless of the request host. Shared by the SDK clients and by commands that POST to non-SDK hosts (e.g. a Model API URL). The resolved remote is returned alongside so callers can derive URLs without resolving it again.
func (*CommandContext) ConfirmYesNo ¶
func (c *CommandContext) ConfirmYesNo(title string) error
ConfirmYesNo prompts the user with a yes/no question. Returns an ErrUsage when stdin is not a terminal so callers can instruct the user to pass --yes or similar. Returns a non-nil error if the user declines.
func (*CommandContext) IsInteractive ¶
func (c *CommandContext) IsInteractive() bool
IsInteractive returns true if the context's stdin is a terminal.
func (*CommandContext) LogLine ¶
func (c *CommandContext) LogLine(v string)
LogLine writes a line to stderr.
func (*CommandContext) Logf ¶
func (c *CommandContext) Logf(format string, args ...any)
Logf writes formatted output to stderr.
func (*CommandContext) NewInferenceClient ¶
func (c *CommandContext) NewInferenceClient(flags cmd.InferenceClientFlags) (*client.InferenceClient, error)
NewInferenceClient creates an inference API client that resolves credentials via the auth store.
func (*CommandContext) NewJSONArrayWriter ¶
func (c *CommandContext) NewJSONArrayWriter() *JSONArrayWriter
NewJSONArrayWriter returns a writer that outputs a JSON array incrementally. Call Write for each element and Close when done.
func (*CommandContext) NewManagementClient ¶
func (c *CommandContext) NewManagementClient() (*client.ManagementClient, error)
NewManagementClient creates a management API client that resolves credentials via the auth store (env var > stored credential).
func (*CommandContext) NewManagementClientWithAuth ¶
func (c *CommandContext) NewManagementClientWithAuth(mgmtURL, authHeader string) (*client.ManagementClient, error)
NewManagementClientWithAuth creates a management API client against mgmtURL with a specific auth header. Used during login to validate a credential before storing it, before any profile exists.
func (*CommandContext) Now ¶
func (c *CommandContext) Now() time.Time
Now returns the current wall-clock time, honoring any override installed via WithNow. Used by command runners for any "now" calculation so tests can pin the clock.
func (*CommandContext) OutputJSON ¶
func (c *CommandContext) OutputJSON(v any)
OutputJSON writes a value as JSON to stdout. Uses indentation unless JSONCompact is set. When CommandContext.JQQuery is set, the value is routed through the jq query and each result is emitted in turn; a jq runtime error is stashed on the context and surfaced by the framework after the runner returns.
func (*CommandContext) OutputLine ¶
func (c *CommandContext) OutputLine(v string)
OutputLine writes a line to stdout.
func (*CommandContext) OutputTable ¶
func (c *CommandContext) OutputTable(out TableOutput)
OutputTable writes a borderless table to stdout with bold headers. Header styling auto-degrades when stdout is not a terminal.
func (*CommandContext) Outputf ¶
func (c *CommandContext) Outputf(format string, args ...any)
Outputf writes formatted output to stdout.
func (*CommandContext) SetDefaultProfile ¶ added in v0.3.0
func (c *CommandContext) SetDefaultProfile(name string)
SetDefaultProfile sets a fallback profile, used only when no profile is selected via --profile, BASETEN_API_KEY, or BASETEN_PROFILE. It must be called before anything that resolves auth (AuthTransport, NewManagementClient, NewInferenceClient, or the Remote/Session accessors): the session resolves once and is cached, so a call afterward has no effect.
func (*CommandContext) Sleep ¶
func (c *CommandContext) Sleep(d time.Duration) error
Sleep pauses for d, honoring any override installed via WithSleep and returning early with ctx.Err() if the context is cancelled.
func (*CommandContext) VerboseLog ¶
func (c *CommandContext) VerboseLog(v string)
VerboseLog writes to stderr if verbose mode is enabled.
func (*CommandContext) VerboseLogLine ¶
func (c *CommandContext) VerboseLogLine(v string)
VerboseLogLine writes a line to stderr if verbose mode is enabled.
func (*CommandContext) VerboseLogf ¶
func (c *CommandContext) VerboseLogf(format string, args ...any)
VerboseLogf writes formatted output to stderr if verbose mode is enabled.
type DeploymentRef ¶ added in v0.3.0
DeploymentRef is the result of resolving cmd.ModelDeploymentIDFlags: a resolved model ID paired with a resolved deployment ID.
func ResolveDeploymentRef ¶ added in v0.3.0
func ResolveDeploymentRef( ctx context.Context, api *managementapi.Client, flags cmd.ModelDeploymentIDFlags, ) (DeploymentRef, error)
ResolveDeploymentRef resolves the model, then the deployment within it. When --deployment-id is set it is used directly; when --deployment-name is set the deployment is looked up by exact name within the model. Absent or ambiguous name matches return an error.
type ErrSubprocess ¶
ErrSubprocess carries a raw process exit code. Used for subprocess passthrough (e.g. truss) where we want the inner exit code verbatim, bypassing the standard typed-error classification.
func (*ErrSubprocess) Error ¶
func (e *ErrSubprocess) Error() string
func (*ErrSubprocess) ExitCode ¶
func (e *ErrSubprocess) ExitCode() cmd.ExitCode
func (*ErrSubprocess) Meaning ¶
func (*ErrSubprocess) Meaning() string
func (*ErrSubprocess) Unwrap ¶
func (e *ErrSubprocess) Unwrap() error
type ExecuteOptions ¶
type ExecuteOptions struct {
Args []string
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
ExitWithCode func(int)
}
ExecuteOptions configures command execution.
type JSONArrayWriter ¶
type JSONArrayWriter struct {
// contains filtered or unexported fields
}
JSONArrayWriter writes a JSON array to a writer incrementally.
func (*JSONArrayWriter) Write ¶
func (w *JSONArrayWriter) Write(v any)
Write writes a single element to the JSON array. When the owning context has CommandContext.JQQuery set, the element is routed through the query and each result is emitted as its own record; runtime errors are stashed on the context and surfaced by the framework.
type ModelRef ¶
ModelRef is the result of resolving cmd.ModelRefFlags against the management API. Team is the resolved team ID (empty when unscoped).
func ResolveModelRef ¶
func ResolveModelRef( ctx context.Context, api *managementapi.Client, flags cmd.ModelRefFlags, ) (ModelRef, error)
ResolveModelRef resolves cmd.ModelRefFlags into a ModelRef. When --model-id is set it returns immediately. When --model-name is set it resolves the optional team and looks up the model by name; absent or ambiguous matches return an error.
type Remote ¶
type Remote struct {
// contains filtered or unexported fields
}
Remote captures the resolved Baseten remote (app URL + override knobs) used to derive every URL the CLI talks to. Construct once via NewRemote at the start of a command; callers use the methods rather than reading env directly.
func NewRemote ¶
NewRemote resolves the remote URL (flag arg, then BASETEN_REMOTE_URL, then https://app.baseten.co), looks up any known per-remote URL overrides, and applies the optional override env vars on top.
func (*Remote) EnvironmentPredictURL ¶ added in v0.3.0
EnvironmentPredictURL returns the user-facing predict URL for a model environment, whose stable name selects the live deployment via the path.
func (*Remote) HostLabel ¶
HostLabel returns the remote's host without the "app." prefix or any port, used to disambiguate profile names across non-default remotes.
func (*Remote) InferenceBaseURL ¶
InferenceBaseURL returns the base URL (no path) for inference calls. When an inference base URL override is set, that is returned verbatim; otherwise the URL is built from the remote's scheme and management API host.
func (*Remote) InferenceHostHeader ¶
InferenceHostHeader returns the Host header value to use for inference requests when the remote requires one. The bool reports whether the caller should force the header; when false, the default URL-derived host is fine.
func (*Remote) ManagementURL ¶
ManagementURL returns the base URL for the REST management API.
func (*Remote) ModelAPIInferenceURL ¶
ModelAPIInferenceURL returns the base URL for Model API (shared endpoint) inference on this remote, e.g. https://inference.baseten.co. OpenAI-shaped routes (e.g. /v1/chat/completions) live underneath it.
func (*Remote) PredictURL ¶
PredictURL returns the user-facing predict URL printed in push output.
type S3APIClientFactory ¶
type S3APIClientFactory func(aws.Config) transfermanager.S3APIClient
S3APIClientFactory builds an S3 client from a fully-populated aws.Config (region + credentials). Tests can inject a fake to capture upload calls.
type TableOutput ¶
type TableOutput struct {
Headers []string
Rows [][]string
// RightAlignedColumns lists column indices whose header and cells are
// right-aligned; columns absent from the list default to left-aligned.
RightAlignedColumns []int
}
TableOutput describes a borderless table for OutputTable.
type TailDeploymentLogsOptions ¶
type TailDeploymentLogsOptions struct {
API *managementapi.Client
ModelID string
DeploymentID string
// StopOnActive stops the tail when the deployment reaches ACTIVE. By
// default ACTIVE is treated as a runnable state and tailing continues
// (matching `truss model logs --tail`). push --tail --wait sets this
// so a successful deploy ends the tail.
StopOnActive bool
// WarmupTimeout is how long to silently retry 404s from the logs API
// at the start of the tail, before any successful poll. After the
// first successful logs response, 404s are surfaced as errors. Zero
// means no warmup retries. (Status-API 404s are never retried here.)
WarmupTimeout time.Duration
}
TailDeploymentLogsOptions configures TailDeploymentLogs. API, ModelID, and DeploymentID are required.
type TailDeploymentLogsResult ¶
type TailDeploymentLogsResult struct {
// Logs yields log records in arrival order. A non-nil error indicates
// the stream is ending due to that error and the log pointer is nil.
// The iterator is single-use.
Logs iter.Seq2[*managementapi.Log, error]
// FinalFetchedDeployment returns the deployment as last fetched when
// the tail loop ended. Valid only after Logs is fully consumed. Nil
// if the loop ended before any status fetch (no logs ever arrived, or
// ctx was cancelled during phase 1).
FinalFetchedDeployment func() *managementapi.Deployment
}
TailDeploymentLogsResult bundles the streaming log iterator with an accessor for the final fetched deployment.
func TailDeploymentLogs ¶
func TailDeploymentLogs(ctx *CommandContext, opts TailDeploymentLogsOptions) *TailDeploymentLogsResult
TailDeploymentLogs tails a specific deployment's logs. It is a thin adapter over tailLogs that wires the deployment logs and describe endpoints.
Source Files
¶
- command.api.go
- command.auth.go
- command.go
- command.model.go
- command.model_api.go
- command.model_deployment.go
- command.model_deployment_logs.go
- command.model_deployment_metrics.go
- command.model_deployment_replica.go
- command.model_environment.go
- command.model_environment_logs.go
- command.model_environment_metrics.go
- command.model_predict.go
- command.model_push.go
- command.model_watch.go
- command.org.go
- command.org_apikey.go
- command.org_secret.go
- command.org_team.go
- command.org_user.go
- command.ssh.go
- command.truss.go
- command.version.go
- command.whoami.go
- command_context.go
- errors.go
- remote.go
- style.go
- team.go