UNPKG

@skbhati199/ai-img-gen-js

Version:

JavaScript/TypeScript SDK for AI Image Generator API

111 lines (89 loc) 3.23 kB
# AI Image Generator JavaScript SDK [![npm version](https://img.shields.io/npm/v/@skbhati199/ai-img-gen-js.svg)](https://www.npmjs.com/package/@skbhati199/ai-img-gen-js) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/TypeScript-4.9.5-blue.svg)](https://www.typescriptlang.org/) A JavaScript/TypeScript SDK for interacting with the AI Image Generator API. ## Installation ```bash npm install @skbhati199/ai-img-gen-js const client = new AIImageGeneratorClient({ baseUrl: 'https://api.images.nbevc.com', // API base URL apiKey: 'YOUR_API_KEY', // Your API key timeout: 30000, // Request timeout in ms (optional) }); // Generate an image const imageUrl = await client.generateImage({ width: 512, // Image width height: 512, // Image height prompt: 'A futuristic city with flying cars', // Text prompt model: 'dall-e-2', // AI model (optional) format: 'png', // Output format (optional) quality: 90, // Image quality (optional) optimize: true, // Optimize for web (optional) }); // Resize an image const resizedUrl = await client.resizeImage('image-id', { width: 256, height: 256, format: 'png', quality: 80, }); // Convert an image to a different format const convertedUrl = await client.convertImage('image-id', { format: 'webp', quality: 85, }); // Optimize an image for web delivery const optimizedUrl = await client.optimizeImage('image-id', { format: 'jpeg', quality: 75, }); // Get supported AI models const models = await client.getSupportedModels(); // Get supported image sizes const sizes = await client.getSupportedSizes(); // Get supported image formats const formats = await client.getSupportedFormats(); // Get API metrics const metrics = await client.getMetrics(); // Check API health const health = await client.checkHealth(); import { AIImageGeneratorClient } from '@skbhati199/ai-img-gen-js'; // Initialize the client const client = new AIImageGeneratorClient({ baseUrl: 'https://api.images.nbevc.com', apiKey: 'YOUR_API_KEY', }); // Generate an image async function generateImage() { try { const imageUrl = await client.generateImage({ width: 512, height: 512, prompt: 'A futuristic city with flying cars and neon lights', model: 'dall-e-2', format: 'png', quality: 90, optimize: true, }); console.log('Generated Image URL:', imageUrl); } catch (error) { console.error('Error generating image:', error); } } generateImage(); try { const imageUrl = await client.generateImage({ width: 512, height: 512, prompt: 'A beautiful landscape', }); console.log('Success:', imageUrl); } catch (error) { console.error('Error:', error.message); // Handle specific error types if needed if (error.response) { console.error('Status:', error.response.status); console.error('Data:', error.response.data); } }