Oblien Docs

API Reference

Complete reference for all Assets AI components, hooks, and utilities.

Components

Icon

Render icons with AI-powered descriptions or static files.

import { Icon } from 'assets-ai';

<Icon 
  description="home" 
  variant="regular"
  size={24}
  color="#000"
  className="icon"
  style={{ cursor: 'pointer' }}
  fallback={true}
  alt="Home icon"
/>

Props:

NameTypeDefaultDescription
descriptionstring-AI prompt for generating the icon (required if name not provided)
namestring-Static icon filename, bypasses AI (required if description not provided)
variant"regular" | "bold" | "light" | "broken" | "two-tone" | "outline""regular"Icon style variant
sizenumber | string24Icon size in pixels
colorstring-Icon color (any valid CSS color)
classNamestring""Additional CSS classes
styleCSSProperties-Inline styles object
fallbackboolean | ReactNode-Skeleton loader or custom fallback component
altstring-Alternative text for accessibility

Image

Render images with AI-powered descriptions or static files.

import { Image } from 'assets-ai';

<Image 
  description="sunset over mountains" 
  width={800}
  height={600}
  alt="Beautiful sunset"
  className="image"
  fallback={true}
/>

Props:

NameTypeDefaultDescription
descriptionstring-AI prompt for generating the image (required if name not provided)
namestring-Static image filename, bypasses AI (required if description not provided)
widthnumber | string-Image width in pixels or CSS value
heightnumber | string-Image height in pixels or CSS value
altstring-Alternative text (required for accessibility)
classNamestring""Additional CSS classes
fallbackboolean | ReactNode-Skeleton loader or custom fallback component

Video

Render videos with AI-powered descriptions or static files.

import { Video } from 'assets-ai';

<Video 
  description="ocean waves" 
  width={1280}
  height={720}
  controls
  autoPlay={false}
  loop={false}
  muted={false}
  className="video"
  fallback={true}
/>

Props:

NameTypeDefaultDescription
descriptionstring-AI prompt for generating the video (required if name not provided)
namestring-Static video filename, bypasses AI (required if description not provided)
widthnumber | string-Video width in pixels or CSS value
heightnumber | string-Video height in pixels or CSS value
controlsbooleantrueShow video controls
autoPlaybooleanfalseAuto-play video on load
loopbooleanfalseLoop video playback
mutedbooleanfalseMute audio by default
classNamestring""Additional CSS classes
fallbackboolean | ReactNode-Skeleton loader or custom fallback component

Skeleton

Loading placeholder component (used internally by fallback).

import { Skeleton } from 'assets-ai';

<Skeleton 
  type="icon"
  size={24}
  className="skeleton"
  alt="Loading icon"
/>

Props:

NameTypeDefaultDescription
type"icon" | "image" | "video"-Type of skeleton (required)
widthnumber | string-Skeleton width
heightnumber | string-Skeleton height
sizenumber | string-Size for icon type
classNamestring""Additional CSS classes
altstring-Alternative text

MediaProvider

Context provider for managing media state.

import { MediaProvider } from 'assets-ai';

<MediaProvider 
  batchDelay={500}
  maxCacheSize={2 * 1024 * 1024}
>
  {children}
</MediaProvider>

Props:

NameTypeDefaultDescription
childrenReactNode-Application components (required)
batchDelaynumber500Milliseconds to wait before batching requests
maxCacheSizenumber1048576Maximum cache size in bytes (1MB default)

Hooks

useMediaContext

Access the media context in your components.

import { useMediaContext } from 'assets-ai';

function MyComponent() {
  const { mediaMap, registerMedia, isItemLoading, getStaticUrl } = useMediaContext();
  
  // Use context values...
}

Returns:

NameTypeDescription
mediaMapMediaMapObject mapping media keys to URLs
registerMedia(type, description, variant?) => voidRegister a media request
isItemLoading(type, description, variant?) => booleanCheck if media is loading
getStaticUrl(type, name) => stringGet static CDN URL

Example:

function CustomMediaComponent() {
  const { mediaMap, registerMedia, isItemLoading } = useMediaContext();
  
  useEffect(() => {
    registerMedia("icon", "custom icon", "regular");
  }, [registerMedia]);
  
  const url = mediaMap["icon:custom icon:regular"];
  const loading = isItemLoading("icon", "custom icon", "regular");
  
  if (loading) return <div>Loading...</div>;
  if (url) return <img src={url} alt="Custom icon" />;
  return null;
}

Functions

configureMedia

Configure global media settings.

import { configureMedia } from 'assets-ai';

configureMedia({
  apiEndpoint: "https://api.oblien.com/icons/fetch",
  apiToken: process.env.NEXT_PUBLIC_OBLIEN_TOKEN,
  manifestUrl: "/media-manifest.json",
  maxCacheSize: 2 * 1024 * 1024,
  staticBaseUrls: {
    icon: "https://cdn.oblien.com/icons/",
    image: "https://cdn.oblien.com/images/",
    video: "https://cdn.oblien.com/videos/",
  },
});

Parameters:

NameTypeDefaultDescription
apiEndpointstring"https://api.oblien.com/icons/fetch"API endpoint for fetching media
apiTokenstring""Authentication token
manifestUrlstring"/media-manifest.json"Production manifest URL
maxCacheSizenumber1048576Max cache size in bytes
staticBaseUrlsobjectOblien CDN URLsBase URLs for static assets

clearMediaCache

Clear all cached media URLs from localStorage.

import { clearMediaCache } from 'assets-ai';

function Settings() {
  const handleClear = () => {
    clearMediaCache();
    console.log('Cache cleared!');
  };
  
  return <button onClick={handleClear}>Clear Cache</button>;
}

Parameters: None

Returns: void

Types

MediaType

Type of media asset.

type MediaType = "icon" | "image" | "video";

MediaMap

Object mapping media keys to URLs.

type MediaMap = Record<string, string>;

// Example:
const mediaMap: MediaMap = {
  "icon:home:regular": "https://cdn.oblien.com/icons/home-regular.svg",
  "image:sunset": "https://cdn.oblien.com/images/sunset.jpg",
  "video:demo": "https://cdn.oblien.com/videos/demo.mp4",
};

MediaRequest

Media request object structure.

interface MediaRequest {
  type: MediaType;
  description: string;
  variant?: "regular" | "bold" | "light" | "broken" | "two-tone" | "outline";
}

// Example:
const request: MediaRequest = {
  type: "icon",
  description: "home",
  variant: "regular"
};

MediaConfig

Configuration object structure.

interface MediaConfig {
  apiEndpoint: string;
  apiToken: string;
  manifestUrl?: string;
  maxCacheSize: number;
  staticBaseUrls?: {
    icon?: string;
    image?: string;
    video?: string;
  };
}

Environment Variables

NEXT_PUBLIC_OBLIEN_TOKEN

Your Oblien API token for authentication.

.env.local
NEXT_PUBLIC_OBLIEN_TOKEN=your_token_here

Usage:

configureMedia({
  apiToken: process.env.NEXT_PUBLIC_OBLIEN_TOKEN,
});

Cache Keys

Media URLs are stored in localStorage with generated keys:

Format: {type}:{description}:{variant}

Examples:

  • icon:home:regular
  • icon:search:bold
  • image:sunset over mountains:undefined
  • video:ocean waves:undefined

Storage Key: oblien_media_cache

// Access cache directly
const cache = localStorage.getItem('oblien_media_cache');
const data = JSON.parse(cache || '{}');
console.log(data);

Error Handling

Components handle errors gracefully:

// Missing API token - warnings in console
<Icon description="home" />
// Console: "[Media] API request failed"

// Invalid description - shows fallback
<Icon description="" fallback={<div>Error</div>} />

// Network error - shows fallback or empty space
<Image description="sunset" fallback={true} />

Performance Considerations

Batching

Multiple media requests within the batchDelay window are automatically batched:

// These 3 requests will be batched together
<Icon description="home" />
<Icon description="search" />
<Icon description="settings" />

// Single API request: POST /fetch with 3 items

Caching

Fetched URLs are cached in localStorage:

// First render - API request
<Icon description="home" />

// Subsequent renders - instant from cache
<Icon description="home" />

Production Manifest

In production, skip runtime requests by using a manifest:

public/media-manifest.json
{
  "icon:home:regular": "https://cdn.oblien.com/icons/home-regular.svg",
  "icon:search:regular": "https://cdn.oblien.com/icons/search-regular.svg"
}

Browser Support

Assets AI supports all modern browsers:

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

Requirements:

  • React 18+ or 19+
  • localStorage support
  • ES6+ JavaScript

TypeScript

Full TypeScript support included:

import type { 
  MediaType, 
  MediaMap, 
  MediaRequest,
  MediaContextType 
} from 'assets-ai';

const type: MediaType = "icon";
const map: MediaMap = {};
const request: MediaRequest = {
  type: "icon",
  description: "home",
  variant: "regular"
};