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.

  1. Log in to your Visual AI account
  2. Navigate to **Settings** → **API Keys** tab
  3. Click on **Generate New Key** button
  4. Enter a name for your API key (e.g., 'Production API', 'Development Key')
  5. 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:

POSThttps://yourapp.com/api/v1/generate

Generate 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.

Header:
Authorization: Bearer vsk_your_api_key_here

4. Request Parameters

Send a JSON payload in the request body with the following parameters:

ParameterTypeRequiredDescription
promptstringRequiredThe text description of the image you want to generate
modelstringRequiredThe 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 NameDescription
infographicProfessional infographic style with charts, graphs, and data visualization elements
3d3D rendered style with depth, lighting, and realistic textures
photoPhotorealistic style that mimics professional photography
abstractAbstract artistic style with creative shapes and patterns
illustrationHand-drawn illustration style with artistic elements
minimalClean, minimalist design with simple elements and lots of white space
social-postOptimized for social media posts with engaging layouts
presentationProfessional presentation slide style with clear hierarchy
timelineTimeline visualization showing chronological progression
comparisonSide-by-side comparison layout for contrasting elements
processProcess 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.

  1. Train a custom model in the **Train Model** section of your dashboard
  2. Upload training pairs (text prompts + reference images)
  3. Wait for training to complete
  4. Use your custom model name in the API request
  5. 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

bash
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

bash
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

javascript
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
{
  "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
{
  "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
}
FieldTypeDescription
successbooleanIndicates if the request was successful
imageUrlstringPublic URL of the generated image stored in cloud storage
visualIdnumberUnique identifier for the generated visual in the database
promptstringThe original prompt you provided
enhancedPromptstringAI-enhanced version of your prompt used for generation
stylestringThe model/style used (prefixed with 'custom_' for custom models)
createdAtstringISO 8601 timestamp of when the image was generated
isCustomModelbooleanTrue if a custom model was used, false for standard models
customModelNamestring | nullName of the custom model if used, null otherwise
trainingPairsCountnumberNumber of training pairs used (0 for standard models)

9. Error Responses

If something goes wrong, the API will return an error response:

401Missing API Key
{
  "error": "Missing or invalid Authorization header"
}
401Invalid API Key
{
  "error": "Invalid API key"
}
403Inactive API Key
{
  "error": "API key is inactive"
}
400Missing Parameters
{
  "error": "Both 'prompt' and 'model' are required in the request body"
}
500Generation Error
{
  "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

12. Support & Resources