title: ‘Image Generation’
description: “Blend Animus’ automatic media workflows with direct API control for character renders, photo edits, and more.”
icon: ‘image’
Image generation now ships with a unified set of REST endpoints (/generation/*) alongside the automatic workflows inside the Animus SDK. You can let the SDK detect when an assistant promises an image, or call the media API directly when you need precise control.
Detection Phase: The API analyzes the conversation to determine if the assistant has agreed to send an image
Generation Phase: If an image is requested, the SDK automatically generates it using the provided prompt
Copy
import { AnimusClient } from 'animus-client';const client = new AnimusClient({ tokenProviderUrl: 'https://your-backend.com/api/get-animus-token', chat: { model: 'vivian-llama3.1-70b-1.0-fp8', systemMessage: 'You are a helpful assistant.', check_image_generation: true // Enable automatic image generation }});// When the AI agrees to send an image, it's automatically generatedclient.chat.send("Can you show me a beautiful sunset over the ocean?");// The SDK handles everything automatically:// 1. AI responds with agreement and creates image prompt// 2. Image is generated using that prompt// 3. Image is added to chat history// 4. Events are emitted for UI updates
Enable automatic image generation in your client configuration:
Copy
const client = new AnimusClient({ tokenProviderUrl: 'https://your-backend.com/api/get-animus-token', chat: { model: 'vivian-llama3.1-70b-1.0-fp8', systemMessage: 'You are a creative assistant who can generate images.', check_image_generation: true // Enable automatic detection and generation }});
Important: Automatic image generation and adding images to message history only happens when using the chat.send() method. If you’re using chat.completions(), you’ll need to manually call client.generateImage() or use your own custom/3rd party image generation endpoint.
You can also generate images directly without going through chat:
Copy
try { const imageUrl = await client.generateImage("A serene mountain landscape at sunset with a lake reflection"); console.log('Generated image URL:', imageUrl); // The image is automatically added to chat history displayImage(imageUrl);} catch (error) { console.error('Image generation failed:', error);}
const detailedPrompt = ` A photorealistic image of a cozy coffee shop interior during golden hour. Warm lighting streaming through large windows, wooden furniture, plants on shelves, steam rising from coffee cups, soft shadows, inviting atmosphere, high quality, detailed textures.`;const imageUrl = await client.generateImage(detailedPrompt);
Image generation works seamlessly with conversational turns:
Copy
const client = new AnimusClient({ tokenProviderUrl: 'https://your-backend.com/api/get-animus-token', chat: { model: 'vivian-llama3.1-70b-1.0-fp8', systemMessage: 'You are a creative assistant.', autoTurn: true, // Enable conversational turns check_image_generation: true // Enable image generation }});// Listen for both auto-turn and image generation eventsclient.on('messageComplete', (data) => { console.log(`${data.messageType} message completed: ${data.content}`); // Check if all messages in the sequence are complete if (data.totalMessages) { console.log('All messages completed - image generation may start now'); }});client.on('imageGenerationStart', (data) => { console.log('Image generation started after conversation turns');});// This might trigger both auto-turn responses AND image generationclient.chat.send("I love Van Gogh's paintings! Can you paint something in his style for me?");
While the SDK handles image generation automatically, you can customize the process:
Copy
// The SDK uses these default settings for image generation// (These are handled internally, but shown for reference)const imageGenerationSettings = { model: 'flux-schnell', // Image generation model width: 1024, // Image width height: 1024, // Image height guidance_scale: 7.5, // How closely to follow the prompt num_inference_steps: 20, // Quality vs speed tradeoff seed: null // Random seed (null for random)};
When image generation is enabled, responses may include image prompts. However, automatic generation behavior differs between methods:
Copy
// Using completions() - requires manual image generationconst response = await client.chat.completions({ messages: [ { role: 'user', content: 'You have any more photos from your vacation in Spain?' } ], check_image_generation: true});const message = response.choices[0].message;if (message.image_prompt) { console.log('AI created image prompt:', message.image_prompt); console.log('AI response:', message.content); // With completions(), you must manually generate the image const imageUrl = await client.generateImage(message.image_prompt); // You also need to manually add it to history if desired // (This is handled automatically with chat.send())}
Key Difference: When using chat.completions(), the SDK will detect image prompts but will not automatically generate images or add them to chat history. You must handle this manually. Only chat.send() provides fully automatic image generation and history management.
Generated images are automatically added to chat history in a structured format:
Copy
// Images appear in chat history like this:const historyMessage = { role: 'assistant', content: '<image description="A serene mountain landscape at sunset with a lake reflection" />', timestamp: '2024-01-15T10:30:00Z'};// Get chat history including imagesconst history = client.chat.getChatHistory();history.forEach(message => { if (message.content.includes('<image')) { console.log('Found image in history:', message.content); }});
// After generating an image, the AI knows what was shownclient.chat.send("Can you show me something peaceful?");// Image is generated and added to history// The AI now has context about the imageclient.chat.send("Can you make the colors more vibrant?");// AI knows what image you're referring to
// Good: Specific, detailed promptsconst goodPrompts = [ "A photorealistic portrait of a golden retriever sitting in a sunny meadow, soft natural lighting, shallow depth of field", "Minimalist line art illustration of a coffee cup with steam, black ink on white background, simple and clean", "Digital art of a cyberpunk cityscape at night, neon lights reflecting on wet streets, futuristic architecture"];// Avoid: Vague or problematic promptsconst avoidPrompts = [ "Something cool", // Too vague "A picture", // No specific content "Make it look good" // No clear direction];