go-replicate is a Go client library for Replicate.
go get github.com/dkgv/go-replicate
Get started by creating an API token on Replicate and instantiating a new client:
client := replicate.NewClient("REPLICATE_TOKEN")
model, err := client.Models.Get(ctx, "OWNER", "MODEL_NAME")
var input any
// ...
prediction, err := client.Predictions.Create(ctx, "MODEL_ID", input)
webhook := replicate.Webook{
CallbackURL: "https://example.com/callback",
Events: []replicate.PredictionEvent{
replicate.EventPredictionStarted,
replicate.EventPredictionCompleted,
},
}
prediction, err := client.Predictions.CreateWithWebhook(ctx, "MODEL_ID", input, webhook)
prediction, err := client.Predictions.Get(ctx, "PREDICTION_ID")
type Destination struct {
// ...
}
var destination Destination
err := client.Predictions.Await(ctx, "PREDICTION_ID", &destination)
err := client.Predictions.Cancel(ctx, "PREDICTION_ID")