How to Use Our API
Complete guide to using the Visual AI API for image generation
Introduction
The Visual AI API allows you to generate images programmatically using both standard visual styles and custom-trained models. This guide will walk you through everything you need to know to get started.
1. Generate Your API Key
To use the API, you first need to generate an API key from your dashboard.
- Log in to your Visual AI account
- Navigate to **Settings** → **API Keys** tab
- Click on **Generate New Key** button
- Enter a name for your API key (e.g., 'Production API', 'Development Key')
- Click **Generate** and copy your API key immediately
Note: Each API key is associated with a specific workspace. Make sure you're in the correct workspace before generating a key.
2. API Endpoint
All image generation requests should be sent to the following endpoint:
https://yourapp.com/api/v1/generateGenerate images using standard or custom models
3. Authentication
The API uses Bearer token authentication. Include your API key in the Authorization header of every request.
Authorization: Bearer vsk_your_api_key_here4. Request Parameters
Send a JSON payload in the request body with the following parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| prompt | string | Required | The text description of the image you want to generate |
| model | string | Required | The visual style or custom model name to use for generation |
5. Available Standard Models
Choose from our pre-built visual styles for different use cases:
| Model Name | Description |
|---|---|
| infographic | Professional infographic style with charts, graphs, and data visualization elements |
| 3d | 3D rendered style with depth, lighting, and realistic textures |
| photo | Photorealistic style that mimics professional photography |
| abstract | Abstract artistic style with creative shapes and patterns |
| illustration | Hand-drawn illustration style with artistic elements |
| minimal | Clean, minimalist design with simple elements and lots of white space |
| social-post | Optimized for social media posts with engaging layouts |
| presentation | Professional presentation slide style with clear hierarchy |
| timeline | Timeline visualization showing chronological progression |
| comparison | Side-by-side comparison layout for contrasting elements |
| process | Process flow diagram showing step-by-step workflows |
6. Using Custom Models
You can use your own trained models by specifying the model name. Custom models use your training data to generate images that match your brand style.
- Train a custom model in the **Train Model** section of your dashboard
- Upload training pairs (text prompts + reference images)
- Wait for training to complete
- Use your custom model name in the API request
- The API will automatically detect and use your custom model's style
Example:
custom-model
Your custom-trained model that follows your specific brand guidelines, colors, and visual patterns
7. Example Requests
Here are complete examples of API requests:
Standard Model Request
curl -X POST https://yourapp.com/api/v1/generate \
-H "Authorization: Bearer vsk_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A beautiful sunset over mountains",
"model": "infographic"
}'Custom Model Request
curl -X POST https://yourapp.com/api/v1/generate \
-H "Authorization: Bearer vsk_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Create a product launch banner",
"model": "jayakannan-test"
}'JavaScript/Fetch Example
const response = await fetch('https://yourapp.com/api/v1/generate', {
method: 'POST',
headers: {
'Authorization': 'Bearer vsk_your_api_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'A futuristic city at night',
model: 'photo'
})
});
const data = await response.json();
console.log(data.imageUrl);8. Response Format
The API returns a JSON response with the generated image details:
Standard Model Response
{
"success": true,
"imageUrl": "https://supabase-url.com/storage/v1/object/public/visuals/workspace-12/api-visual-123.jpeg",
"visualId": 456,
"prompt": "A beautiful sunset over mountains",
"enhancedPrompt": "A stunning visual representation of a beautiful sunset...",
"style": "infographic",
"createdAt": "2025-01-08T12:45:30.123Z",
"isCustomModel": false,
"customModelName": null,
"trainingPairsCount": 0
}Custom Model Response
{
"success": true,
"imageUrl": "https://supabase-url.com/storage/v1/object/public/visuals/workspace-12/api-visual-789.jpeg",
"visualId": 789,
"prompt": "Create a product launch banner",
"enhancedPrompt": "Enhanced prompt using custom model training data...",
"style": "custom_jayakannan-test",
"createdAt": "2025-01-08T12:50:15.456Z",
"isCustomModel": true,
"customModelName": "jayakannan-test",
"trainingPairsCount": 5
}| Field | Type | Description |
|---|---|---|
| success | boolean | Indicates if the request was successful |
| imageUrl | string | Public URL of the generated image stored in cloud storage |
| visualId | number | Unique identifier for the generated visual in the database |
| prompt | string | The original prompt you provided |
| enhancedPrompt | string | AI-enhanced version of your prompt used for generation |
| style | string | The model/style used (prefixed with 'custom_' for custom models) |
| createdAt | string | ISO 8601 timestamp of when the image was generated |
| isCustomModel | boolean | True if a custom model was used, false for standard models |
| customModelName | string | null | Name of the custom model if used, null otherwise |
| trainingPairsCount | number | Number of training pairs used (0 for standard models) |
9. Error Responses
If something goes wrong, the API will return an error response:
{
"error": "Missing or invalid Authorization header"
}{
"error": "Invalid API key"
}{
"error": "API key is inactive"
}{
"error": "Both 'prompt' and 'model' are required in the request body"
}{
"error": "Failed to generate image",
"errorType": "generation_error"
}10. Best Practices
Follow these best practices for optimal API usage:
Secure Your API Keys
Never expose API keys in client-side code or public repositories. Use environment variables and server-side requests.
Handle Errors Gracefully
Always implement proper error handling to manage rate limits, network issues, and generation failures.
Use Descriptive Prompts
Provide clear, detailed prompts for better image generation results. Include specific details about colors, composition, and style.
Monitor Usage
Check your API usage logs in the dashboard to track consumption and identify any issues.
Test with Standard Models First
Before using custom models in production, test with standard models to ensure your integration works correctly.
Cache Generated Images
Store the returned image URLs and reuse them when possible to reduce API calls and costs.
11. Rate Limits & Usage
API usage is tracked and logged for each request:
- All API calls are logged with timestamps, response times, and status codes
- Check your usage statistics in the Settings → API Keys section
- Each API key is workspace-specific
- Inactive API keys cannot be used for generation
- Rate limits may apply based on your subscription plan