devquarks-image-sdk
v1.0.2
Published
SDK for generating high-quality images via Devquarks API at 10x cheaper cost
Maintainers
Readme
Devquarks Image SDK
Generate high-quality AI images in your apps/websites at 10x cheaper cost using Devquarks API. This SDK provides a simple interface to integrate AI image generation into your Node.js applications.
Features
- 🚀 Ultra-fast image generation
- 💰 10x cheaper than competitors
- 🎨 High-quality AI-generated images
- 📦 Simple and lightweight SDK
- 🔒 Secure API authentication
- 📱 Works with any Node.js application
Installation
npm install devquarks-image-sdkQuick Start
import { generateImage } from 'devquarks-image-sdk';
import fs from 'fs';
async function createImage() {
try {
const imageBuffer = await generateImage({
token: 'your-api-token',
prompt: 'A beautiful sunset over mountains'
});
// Save the image to file
fs.writeFileSync('generated-image.png', imageBuffer);
console.log('Image generated successfully!');
} catch (error) {
console.error('Error generating image:', error.message);
}
}
createImage();API Reference
generateImage(options)
Generates an AI image based on the provided prompt.
Parameters
options(Object): Configuration objecttoken(string): Your Devquarks API tokenprompt(string): Text description of the image you want to generate
Returns
Promise<Buffer>: A Promise that resolves to a Buffer containing the generated image data
Example
const imageBuffer = await generateImage({
token: 'your-api-token',
prompt: 'A futuristic city with flying cars'
});Usage Examples
Basic Usage
import { generateImage } from 'devquarks-image-sdk';
const imageBuffer = await generateImage({
token: 'your-api-token',
prompt: 'A serene lake with mountains in the background'
});Saving to File
import { generateImage } from 'devquarks-image-sdk';
import fs from 'fs';
async function saveImage() {
const imageBuffer = await generateImage({
token: 'your-api-token',
prompt: 'A magical forest with glowing mushrooms'
});
fs.writeFileSync('magical-forest.png', imageBuffer);
}Using with Express.js
import express from 'express';
import { generateImage } from 'devquarks-image-sdk';
const app = express();
app.use(express.json());
app.post('/generate-image', async (req, res) => {
try {
const { prompt } = req.body;
const imageBuffer = await generateImage({
token: process.env.DEVQUARKS_API_TOKEN,
prompt
});
res.set('Content-Type', 'image/png');
res.send(imageBuffer);
} catch (error) {
res.status(500).json({ error: error.message });
}
});Converting to Base64
import { generateImage } from 'devquarks-image-sdk';
async function getBase64Image() {
const imageBuffer = await generateImage({
token: 'your-api-token',
prompt: 'A cyberpunk cityscape at night'
});
const base64Image = imageBuffer.toString('base64');
console.log(`data:image/png;base64,${base64Image}`);
}Getting Your API Token
- Visit Devquarks Dashboard
- Sign up for an account or log in
- Navigate to API Keys section
- Generate a new API token
- Copy and use the token in your application
Error Handling
The SDK throws errors for various scenarios. Always wrap your calls in try-catch blocks:
try {
const imageBuffer = await generateImage({
token: 'your-api-token',
prompt: 'A beautiful landscape'
});
} catch (error) {
console.error('Failed to generate image:', error.message);
// Handle the error appropriately
}Common Error Scenarios
- Invalid API Token: Check your token is correct and active
- Network Issues: Ensure stable internet connection
- Invalid Prompt: Make sure your prompt is descriptive and appropriate
- Rate Limiting: Implement proper rate limiting in your application
Best Practices
Environment Variables: Store your API token in environment variables
const token = process.env.DEVQUARKS_API_TOKEN;Error Handling: Always implement proper error handling
try { const imageBuffer = await generateImage({ token, prompt }); } catch (error) { // Handle error appropriately }Prompt Quality: Use descriptive and specific prompts for better results
// Good prompt const prompt = "A detailed oil painting of a red rose on a wooden table with soft lighting"; // Better than generic prompt const prompt = "flower";
TypeScript Support
This SDK is written in TypeScript and includes type definitions:
import { generateImage, ImageGenOptions } from 'devquarks-image-sdk';
const options: ImageGenOptions = {
token: 'your-api-token',
prompt: 'A majestic eagle soaring through clouds'
};
const imageBuffer: Buffer = await generateImage(options);Requirements
- Node.js 14.0 or higher
- Active Devquarks API token
License
MIT License - see LICENSE file for details
Support
- 📧 Email: [email protected]
Made with ❤️ by Devquarks
