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 replicatepip install replicateSetup
import Replicate from 'replicate'
const replicate = new Replicate({
auth: process.env.GATEWAY_API_KEY,
baseUrl: 'https://hypery.ai/api/v1'
})import replicate
client = replicate.Client(
api_token=os.getenv('GATEWAY_API_KEY'),
base_url='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])output = client.run(
'black-forest-labs/flux-schnell',
input={
'prompt': 'a cat wearing sunglasses',
'width': 1024,
'height': 1024
}
)
print('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)prediction = client.predictions.create(
model='black-forest-labs/flux-schnell',
input={
'prompt': 'a sunset over mountains',
'width': 1024,
'height': 1024
}
)
print('Prediction ID:', prediction.id)
print('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)
}prediction = client.predictions.get('abc123')
print('Status:', prediction.status)
if prediction.status == 'succeeded':
print('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)# Wait for completion (polls automatically)
prediction = client.wait(prediction.id)
print('Final output:', prediction.output)Popular Models
Use these model IDs with the Replicate SDK:
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)
}
}try:
output = client.run(
'black-forest-labs/flux-schnell',
input={'prompt': 'a sunset'}
)
print('Success:', output)
except Exception as e:
if 'credits' in str(e):
print('Out of credits')
else:
print('Error:', e)