Replicate SDK

Use the official Replicate SDK with Hypery

Overview

The official Replicate SDK works with Hypery Hub by configuring the baseUrl.


Installation

npm install replicate

Setup

import Replicate from 'replicate'
 
const replicate = new Replicate({
  auth: process.env.GATEWAY_API_KEY,
  baseUrl: 'https://hypery.ai/api/v1'
})

Run a Model

Generate an image with automatic polling:

const output = await replicate.run(
  'black-forest-labs/flux-schnell',
  {
    input: {
      prompt: 'a cat wearing sunglasses',
      width: 1024,
      height: 1024
    }
  }
)
 
console.log('Generated image:', output[0])

The SDK automatically polls until the prediction completes.


Create Prediction

For more control, create a prediction manually:

const prediction = await replicate.predictions.create({
  model: 'black-forest-labs/flux-schnell',
  input: {
    prompt: 'a sunset over mountains',
    width: 1024,
    height: 1024
  }
})
 
console.log('Prediction ID:', prediction.id)
console.log('Status:', prediction.status)

Get Prediction

Check the status of a prediction:

const prediction = await replicate.predictions.get('abc123')
 
console.log('Status:', prediction.status)
if (prediction.status === 'succeeded') {
  console.log('Output:', prediction.output)
}

Wait for Prediction

Wait for a prediction to complete:

// Wait for completion (polls automatically)
const prediction = await replicate.wait(prediction.id)
 
console.log('Final output:', prediction.output)

Use these model IDs with the Replicate SDK:

ModelDescription
black-forest-labs/flux-schnellFast, high-quality image generation
black-forest-labs/flux-devHighest quality (slower)
stability-ai/stable-diffusion-3Versatile image generation
ideogram-ai/ideogram-v2Text in images

Browse all models →


Async/Await Pattern

The SDK handles all the complexity:

// Old way (manual polling)
const prediction = await replicate.predictions.create({...})
while (prediction.status !== 'succeeded') {
  await sleep(1000)
  prediction = await replicate.predictions.get(prediction.id)
}
 
// Easy way (SDK handles it)
const output = await replicate.run('model-name', { input: {...} })

Error Handling

try {
  const output = await replicate.run(
    'black-forest-labs/flux-schnell',
    { input: { prompt: 'a sunset' } }
  )
  
  console.log('Success:', output)
} catch (error) {
  if (error.message.includes('credits')) {
    console.error('Out of credits')
  } else {
    console.error('Error:', error.message)
  }
}

Next Steps