JavaScript
This guide helps you install and use the Youzu JavaScript API for direct integration.
InstallationCopied!
You can install the Youzu JavaScript API using npm, yarn, or by adding a script tag to your HTML.
npmCopied!
npm install @youzu/api
yarnCopied!
yarn add @youzu/api
script tagCopied!
Add the following script tag to the <head>
section of your HTML file:
<script src="https://cdn.youzu.ai/api/latest.js?secretKey=YOUR_SECRET_KEY"></script>
Replace YOUR_SECRET_KEY
with your actual secret key.
Basic UsageCopied!
npm/yarnCopied!
import { YouzuAPI } from '@youzu/api';
// Initialize the API client
const youzu = new YouzuAPI({
secretKey: 'YOUR_SECRET_KEY',
// Optional configurations
baseUrl: 'https://platform-api.youzu.ai',
timeout: 30000
});
// Example: Generate an image
async function generateImage() {
try {
const result = await youzu.generation.create({
prompt: 'a beautiful sunset over mountains'
});
console.log(result);
} catch (error) {
console.error('Error generating image:', error);
}
}
// Example: Search for products
async function searchProducts(imageFile) {
try {
const form = new FormData();
form.append('file', imageFile);
const results = await youzu.products.search(form);
console.log(results);
} catch (error) {
console.error('Error searching products:', error);
}
}
Script tagCopied!
// The API is available as window.YouzuAPI
const youzu = new YouzuAPI.Client();
async function generateImage() {
try {
const result = await youzu.generation.create({
prompt: 'a beautiful sunset over mountains'
});
console.log(result);
} catch (error) {
console.error('Error generating image:', error);
}
}
API ReferenceCopied!
The JavaScript API provides the following modules:
generation
- Methods for image generationproducts
- Methods for product search
For additional help, contact our support team at support@youzu.ai.