Light Logo
JavaScript SDK (v0.39.1)Guides

Predictions

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

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

Get a Prediction by ID

const prediction = await wriftai.predictions.get('your-prediction-id');

Create a Prediction

With the latest version of a model

const prediction = await wriftai.predictions.create({
  model: 'deepseek-ai/deepseek-r1',
  input: {
    prompt: 'Summarize quantum computing.',
  },
});

With a specific version of a model

const prediction = await wriftai.predictions.create({
  model: 'deepseek-ai/deepseek-r1:2',
  input: {
    prompt: 'Summarize quantum computing.',
  },
});

With a webhook for prediction updates

const prediction = await wriftai.predictions.create({
  model: 'deepseek-ai/deepseek-r1',
  input: {
    prompt: 'Summarize quantum computing.',
  },
  webhook: {
    url: 'https://example.com/webhooks/wriftai',
    secret: 'top-secret', // This is optional
  },
});

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.

const prediction = await wriftai.predictions.create({
  model: 'deepseek-ai/deepseek-r1',
  input: {
    prompt: 'Summarize quantum computing.',
  },
  validate_input: true,
});

Create and wait for completion

const prediction = await wriftai.predictions.create(
  {
    model: 'deepseek-ai/deepseek-r1',
    input: {
      prompt: 'Summarize quantum computing.',
    },
  },
  true,
);

Create and wait with custom options

const prediction = await wriftai.predictions.create(
  {
    model: 'deepseek-ai/deepseek-r1',
    input: {
      prompt: 'Summarize quantum computing.',
    },
  },
  true,
  {
    pollInterval: 500,
    onPoll: async (prediction) => {
      // your custom logic
    },
  },
);

Wait for an existing prediction to complete

const prediction = await wriftai.predictions.wait('your-prediction-id');

List Predictions

const predictions = await wriftai.predictions.list();