Light Logo
Go SDK (v0.41.1)Guides

Predictions

A guide on how to work with predictions using the WriftAI Go client

This section demonstrates common prediction operations you can perform with the WriftAI Go client. These examples are not exhaustive — check the client reference for all options.

Get a Prediction by ID

prediction, err := client.Predictions.Get(context.TODO(), "your-prediction-id")

Create a Prediction

With the latest version of a model

prediction, err := client.Predictions.Create(
    context.TODO(),
    "deepseek-ai/deepseek-r1",
    wriftai.CreatePredictionParams{
        Input: json.RawMessage(`{"prompt":"Summarize quantum computing."}`),
    },
    false, // do not wait for completion
    nil, // no custom wait options
)

With a specific version of a model

prediction, err := client.Predictions.Create(
    context.TODO(),
    "deepseek-ai/deepseek-r1:2",
    wriftai.CreatePredictionParams{
        Input: json.RawMessage(`{"prompt":"Summarize quantum computing."}`),
    },
    false, // do not wait for completion
    nil, // no custom wait options
)

With a webhook for prediction updates

webhookSecret := "top-secret"

prediction, err := client.Predictions.Create(
    context.TODO(),
    "deepseek-ai/deepseek-r1",
    wriftai.CreatePredictionParams{
        Input: json.RawMessage(`{"prompt":"Summarize quantum computing."}`),
        Webhook: &wriftai.Webhook{
            URL:    "https://example.com/webhooks/wriftai",
            Secret: &webhookSecret, // This is optional
        },
    },
    false, // do not wait for completion
    nil, // no custom wait options
)

With input validation enabled

Enable early input validation against the model’s input schema before a prediction is created. This catches invalid inputs upfront and prevents unnecessary model execution and cost.

validate := true
prediction, err := client.Predictions.Create(
    context.TODO(),
    "deepseek-ai/deepseek-r1",
    wriftai.CreatePredictionParams{
        Input: json.RawMessage(`{"prompt":"Summarize quantum computing."}`),
        ValidateInput: &validate,
    },
    false, // do not wait for completion
    nil,   // no custom wait options
)

Create and wait for completion

prediction, err := client.Predictions.Create(
    context.TODO(),
    "deepseek-ai/deepseek-r1",
    wriftai.CreatePredictionParams{
        Input: json.RawMessage(`{"prompt":"Summarize quantum computing."}`),
    },
    true, // wait for completion
    nil, // no custom wait options
)

Create and wait with custom options

onPoll := func(pred *wriftai.PredictionWithIO) error {
		// your custom logic
		return nil
}
options := wriftai.WaitOptions{PollInterval: time.Second, OnPoll: onPoll}

prediction, err := client.Predictions.Create(
    context.TODO(),
    "deepseek-ai/deepseek-r1",
    wriftai.CreatePredictionParams{
        Input: json.RawMessage(`{"prompt":"Summarize quantum computing."}`),
    },
    true,     // wait for completion
    &options, // custom wait options
)

Wait for an existing prediction to complete

prediction, err := client.Predictions.Wait(
    context.TODO(),
    "your-prediction-id",
    nil, // no custom wait options
)

List Predictions

predictions, err := client.Predictions.List(
    context.TODO(),
    nil, // default pagination options
)