Jellyfin API Client
@get-coral/jellyfin
Section titled “@get-coral/jellyfin”A modern, fetch-based Jellyfin API client with full TypeScript types. No dependencies. Works in Node.js, browsers, and edge runtimes (Cloudflare Workers, Vercel Edge, etc).
Version
Section titled “Version”- Current version: 1.2.0
Installation
Section titled “Installation”pnpm add @get-coral/jellyfin# ornpm install @get-coral/jellyfinQuick Start
Section titled “Quick Start”import { createClient, getLibraryItems, fromJellyfin } from '@get-coral/jellyfin'
const client = createClient({ url: 'http://192.168.1.10:8096', apiKey: 'your-api-key', userId: 'your-user-id'})
// Fetch library itemsconst items = await getLibraryItems(client, { libraryId: 'library-id', limit: 50})
// Transform Jellyfin data to typed objectsconst movies = items.map(fromJellyfin.movie)Features
Section titled “Features”Type-Safe API
Section titled “Type-Safe API”- Full TypeScript support
- Strongly typed responses
- IntelliSense support
- No
anytypes
Zero Dependencies
Section titled “Zero Dependencies”- Tiny bundle size
- Uses native
fetchAPI - No external dependencies
- Fast installation
Works Everywhere
Section titled “Works Everywhere”- Node.js
- Browser
- Cloudflare Workers
- Vercel Edge Functions
- Deno
- And other edge runtimes
Comprehensive Coverage
Section titled “Comprehensive Coverage”- Browse libraries
- Get items and collections
- Fetch user sessions
- Update playback state
- Search functionality
- And much more
Core API
Section titled “Core API”Client Creation
Section titled “Client Creation”import { createClient } from '@get-coral/jellyfin'
const client = createClient({ url: 'http://your-jellyfin-server:8096', apiKey: 'your-api-key', userId: 'your-user-id'})Common Operations
Section titled “Common Operations”import { getLibraries, getLibraryItems, getItem, getNextUp, getContinueWatching, search, fromJellyfin} from '@get-coral/jellyfin'
// Get all librariesconst libraries = await getLibraries(client)
// Get items from a libraryconst items = await getLibraryItems(client, { parentId: 'library-id', limit: 50})
// Get a specific itemconst item = await getItem(client, 'item-id')
// Get continue watchingconst continuing = await getContinueWatching(client)
// Get next up (for series)const nextUp = await getNextUp(client, { parentId: 'series-id'})
// Searchconst results = await search(client, { searchTerm: 'test', limit: 20})
// Transform to typed objectsconst movie = fromJellyfin.movie(item)const series = fromJellyfin.series(item)Update Operations
Section titled “Update Operations”import { updatePlaybackState, markFavorite } from '@get-coral/jellyfin'
// Update user playback progressawait updatePlaybackState(client, { itemId: 'item-id', positionTicks: 12345, isPaused: false})
// Mark as favoriteawait markFavorite(client, { itemId: 'item-id', isFavorite: true})Data Transformation
Section titled “Data Transformation”Transform raw Jellyfin API responses to typed objects:
import { fromJellyfin } from '@get-coral/jellyfin'
const jellyfinItem = await getItem(client, 'item-id')
// Convert to strongly-typed objectsconst movie = fromJellyfin.movie(jellyfinItem)const series = fromJellyfin.series(jellyfinItem)const episode = fromJellyfin.episode(jellyfinItem)const person = fromJellyfin.person(jellyfinItem)Each transformer:
- Validates the data structure
- Extracts relevant fields
- Provides TypeScript types
- Handles missing data gracefully
Advanced Usage
Section titled “Advanced Usage”Authentication in Node.js
Section titled “Authentication in Node.js”import { authenticate } from '@get-coral/jellyfin'
const token = await authenticate(client, { username: 'your-username', password: 'your-password'})
// Use token for authenticated requestsWorking with Edge Runtimes
Section titled “Working with Edge Runtimes”import { createClient } from '@get-coral/jellyfin'
// Works with Vercel Edge Functionsexport default async (req: Request) => { const client = createClient({ url: process.env.JELLYFIN_URL, apiKey: process.env.JELLYFIN_API_KEY, userId: process.env.JELLYFIN_USER_ID })
const items = await getLibraryItems(client, { limit: 10 })
return Response.json(items)}Error Handling
Section titled “Error Handling”try { const item = await getItem(client, 'invalid-id')} catch (error) { if (error instanceof JellyfinError) { console.error('Jellyfin API error:', error.message) }}Performance Tips
Section titled “Performance Tips”- Use
limitandstartIndexfor pagination - Cache responses appropriate to your use case
- Use filter parameters to reduce data transfer
- Consider using
includeFieldsto limit response size
Contributing
Section titled “Contributing”Community contributions are welcome! See the Contributing guide.
License
Section titled “License”MIT