docs
SupportConsole

Go

The official Go library for the Superslice API.

Source, issues and releases: superslice-co/superslice-go.

Install

Requires Go 1.21 or newer. No dependencies outside the standard library.

The package is not yet published to the Go module proxy index (pkg.go.dev). Install it straight from GitHub:

sh
go get github.com/superslice-co/superslice-go@v0.1.0

Quickstart

go
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/superslice-co/superslice-go"
)

func main() {
	ctx := context.Background()
	client := superslice.NewClient(superslice.WithAPIKey("ss_live_...")) // or set SUPERSLICE_API_KEY

	slice, err := client.Slices.Create(ctx, &superslice.SliceParams{
		Slicer:    superslice.SlicerBambuStudio,
		Printer:   superslice.PresetName("Bambu Lab X1 Carbon 0.4 nozzle"),
		Process:   superslice.PresetName("0.20mm Standard @BBL X1C"),
		Filament:  superslice.PresetName("Bambu PLA Basic @BBL X1C"),
		PlateType: "Textured PEI Plate",
		FilePath:  "cube.stl",
	})
	if err != nil {
		log.Fatal(err)
	}

	slice, err = client.Slices.Wait(ctx, slice.ID, nil) // polls every 2 s, gives up after 10 min
	if err != nil {
		log.Fatal(err)
	}
	if slice.Status == superslice.StatusFailed {
		log.Fatalf("slice failed: %s: %s", slice.Error.Code, slice.Error.Message)
	}

	fmt.Println(slice.Result.PrintTimeS, "s,", slice.Result.FilamentG, "g")
	if slice.Price != nil { // set when you have pricing rules
		fmt.Printf("%s %d minor units\n", slice.Price.Currency, slice.Price.TotalMinor)
	}
}

Pass the model as FilePath, as File (any io.Reader, with Filename), or as Model: &superslice.ModelRef{ID: "mdl_..."} or Model: &superslice.ModelRef{SourceURL: "https://..."}. The first two send a multipart upload; the file is read into memory so a retry can resend it. Use superslice.PresetID("pst_...") instead of PresetName for a preset you uploaded.

Money is always an integer in minor units (TotalMinor), never a float.

Catalogue lookup

go
engines, _ := client.Engines.List(ctx)
printers, _ := client.Engines.Printers(ctx, "bambu-studio@02.08.02.61+02.08.00.05")
processes, _ := client.Engines.Processes(ctx, release, printers[0].Name)
filaments, _ := client.Engines.Filaments(ctx, release, printers[0].Name)
plates, _ := client.Engines.PlateTypes(ctx, release, printers[0].Name)

Release names with @ and + are URL-encoded for you. Which releases your org may use is set with client.Slicers.Update.

Idempotency

go
slice, err := client.Slices.Create(ctx, params, superslice.WithIdempotencyKey("order-1234"))

Repeating a key returns the same slice. The same key with a different body returns a *ConflictError (idempotency_conflict).

Errors

Every API error is application/problem+json. Each family has its own type, and all of them wrap *superslice.APIError:

go
slice, err := client.Slices.Get(ctx, "job_missing")
var nf *superslice.NotFoundError
var api *superslice.APIError
switch {
case errors.As(err, &nf):
	fmt.Println("no such slice")
case errors.As(err, &api):
	fmt.Println(api.Status, api.Code, api.Title, api.Errors, api.RetryAfter)
}
TypeStatus
AuthenticationError401
PlanLimitError402
PermissionError403
NotFoundError404
ConflictError409
InvalidRequestError400, 413
RateLimitError429
ServerError5xx
ConnectionError, TimeoutErrortransport problems, and Slices.Wait running out of time

APIError carries Status, Code, Title, Errors (field details), RetryAfter and the raw Body. A slice that fails after it was accepted is not an error: Wait returns it with Status == "failed" and Error set.

Retries

  • A 429 waits for Retry-After seconds (1 s if the header is missing), then retries.
  • A 5xx or a network error retries after 0.5 s, 1 s, 2 s.
  • GET, PUT, PATCH and DELETE retry freely, up to WithMaxRetries times (default 2).
  • A POST is retried only when you passed an idempotency key, because a retry could otherwise slice twice.

Webhooks

Verify the raw request body, before parsing it:

go
func handler(w http.ResponseWriter, r *http.Request) {
	body, _ := io.ReadAll(r.Body)
	event, err := client.Webhooks.Verify(secret, r.Header.Get("Superslice-Signature"), body)
	if err != nil {
		http.Error(w, "bad signature", http.StatusBadRequest)
		return
	}
	if event.Event == "slice.completed" {
		slice, _ := event.Slice()
		fmt.Println(slice.ID, slice.Result.PrintTimeS)
	}
	w.WriteHeader(http.StatusOK)
}

The same event can arrive twice; skip event.EventID values you have seen. Verify rejects timestamps more than 5 minutes off; change that with superslice.WithTolerance(d). superslice.VerifyWebhook does the same without a client.

Other resources

go
client.Slices.List(ctx, &superslice.ListParams{Limit: 50})   // one page: Data, NextCursor

it := client.Slices.ListAll(ctx, nil)                          // every slice, across pages
for it.Next() { fmt.Println(it.Slice().ID) }
if err := it.Err(); err != nil { ... }

client.Models.Get(ctx, id)
client.Models.Delete(ctx, id)
client.Presets.Create(ctx, &superslice.PresetCreateParams{FilePath: "mine.json", Slicer: superslice.SlicerBambuStudio})
client.Presets.List(ctx)
client.Presets.Update(ctx, id, superslice.PresetUpdate{Name: "New name"})
client.Presets.Delete(ctx, id)
client.Pricing.Get(ctx)
client.Pricing.Set(ctx, superslice.PricingInput{...})
client.Pricing.Delete(ctx)
client.Slicers.List(ctx)
client.Slicers.Update(ctx, superslice.SlicerBambuStudio, superslice.SlicerUpdate{Mode: "latest"})

Unknown fields the API adds later are ignored, so older versions of this library keep working.

Configuration

OptionDefault
WithAPIKey(key)SUPERSLICE_API_KEY from the environment
WithBaseURL(url)https://api.superslice.co
WithTimeout(d)60 s per attempt
WithMaxRetries(n)2
WithHTTPClient(c)a plain http.Client

NewClient panics when no key is found. Use superslice.New(...) to get an error instead. Every call takes a context.Context; cancelling it stops the call and any retry wait.