TypeScript Quickstart
Prerequisites
Installation
npm install shortgeniusyarn add shortgeniuspnpm add shortgeniusbun add shortgeniusQuick Start
1
import { ShortGenius } from 'shortgenius'
const client = new ShortGenius({
bearerAuth: 'YOUR_API_KEY' // or use process.env.SHORTGENIUS_BEARER_AUTH
})2
async function checkHealth() {
const status = await client.status.check()
console.log('API Status:', status) // { status: "ok" }
}
checkHealth()3
async function listMusicGenres() {
const genres = await client.getMusicGenres()
console.log('Available genres:', genres)
// Get tracks for a specific genre
if (genres.length > 0) {
const tracks = await client.getMusic(genres[0].id)
console.log(`Tracks in ${genres[0].name}:`, tracks)
}
}
listMusicGenres()4
async function draftVideo() {
const draft = await client.draftVideo({
topic: 'Benefits of Drinking Water',
duration: '120',
locale: 'en-US'
})
console.log('Draft created:', draft)
console.log(`Title: ${draft.title}`)
console.log(`Scenes: ${draft.scenes.length}`)
return draft
}
draftVideo()5
async function createVideo() {
// First, get your publishing connections
const connections = await client.getConnections()
// Get available voices
const voices = await client.getVoices({ locale: 'en-US' })
// Create the draft
const draft = await client.draftVideo({
topic: 'Benefits of Drinking Water',
duration: '120',
locale: 'en-US'
})
// Create the video
const video = await client.createVideo({
contentType: 'Custom',
locale: 'en-US',
connectionIds: [connections[0].id], // Use your first connection
title: draft.title,
caption: draft.caption,
scenes: draft.scenes,
voiceId: voices[0].id,
aspectRatio: '9:16' // 9:16 for vertical video
})
console.log('Video created:', video)
console.log(`Video ID: ${video.id}`)
console.log(`Status: ${video.publishingState}`)
}
createVideo()Complete Example
import { ShortGenius } from 'shortgenius'
const client = new ShortGenius({
bearerAuth: process.env.SHORTGENIUS_BEARER_AUTH!
})
async function main() {
// 1. Check API status
const status = await client.status.check()
console.log('✅ API is', status.status)
// 2. Get resources
const [connections, voices, genres] = await Promise.all([
client.getConnections(),
client.getVoices({ locale: 'en-US' }),
client.getMusicGenres()
])
console.log(`📺 Found ${connections.length} publishing connections`)
console.log(`🎤 Found ${voices.length} voices`)
console.log(`🎵 Found ${genres.length} music genres`)
// 3. Draft a video
const draft = await client.draftVideo({
topic: '5 Amazing Space Facts',
duration: '60',
locale: 'en-US'
})
console.log(`\n📝 Draft created: "${draft.title}"`)
console.log(` ${draft.scenes.length} scenes generated`)
// 4. Get soundtrack
const tracks = await client.getMusic(genres[0].name)
// 5. Create the video
const video = await client.createVideo({
contentType: 'Custom',
locale: 'en-US',
connectionIds: [connections[0].id],
title: draft.title,
caption: draft.caption,
scenes: draft.scenes,
voiceId: voices[0].id,
soundtrackId: tracks[0].id,
aspectRatio: '9:16'
})
console.log(`\n🎬 Video created!`)
console.log(` ID: ${video.id}`)
console.log(` Status: ${video.publishingState}`)
// 6. Check video status
const videoDetails = await client.getVideo(video.id)
console.log(` Publishing state: ${videoDetails.publishingState}`)
}
main()Error Handling
Configuration Options
Custom Timeout
Custom Base URL
Retry Configuration
TypeScript Support
Next Steps
Last updated