OpenAI SDK

Use the official OpenAI SDK with Hypery

Overview

The official OpenAI SDK works perfectly with Hypery Hub - just change the baseURL.


Installation

npm install openai

Setup

import OpenAI from 'openai'
 
const client = new OpenAI({
  apiKey: process.env.GATEWAY_API_KEY,
  baseURL: 'https://hypery.ai/api/v1'
})

Chat Completions

const response = await client.chat.completions.create({
  model: 'anthropic/claude-3.5-sonnet',
  messages: [
    { role: 'user', content: 'Hello!' }
  ]
})
 
console.log(response.choices[0].message.content)

Streaming

const stream = await client.chat.completions.create({
  model: 'openai/gpt-4o',
  messages: [{ role: 'user', content: 'Tell me a story' }],
  stream: true
})
 
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '')
}

Image Generation

const image = await client.images.generate({
  model: 'dall-e-3',
  prompt: 'A sunset over mountains',
  size: '1024x1024'
})
 
console.log(image.data[0].url)

List Models

const models = await client.models.list()
 
for (const model of models.data) {
  console.log(model.id)
}

Next Steps