AI Visual Studio

API Documentation

v1

Overview

The AI Visual Studio API enables you to generate stunning AI images and videos programmatically. Build powerful integrations into your applications with our RESTful API.

Base URL

https://aivisualstudio.co/api/v1

Format

JSON (application/json)

Authentication

Bearer Token (API Key)

Quick Start

  1. 1
    Get an API Key

    Create an API key from your account dashboard

  2. 2
    Make your first request

    Use the code examples below to generate your first image

  3. 3
    Set up webhooks (optional)

    Receive real-time notifications when generations complete

Authentication

All API requests require authentication using an API key. Include your key in the Authorization header as a Bearer token.

Authorization Header
Authorization: Bearer avs_live_your_api_key_here
Keep your API key secure!

Never expose your API key in client-side code or public repositories. Use environment variables or secret management tools.

API Key Scopes

API keys can have different permission scopes:

ScopeDescription
readRead generations, models, and account info
generate:imageCreate image generations
generate:videoCreate video generations
webhooksManage webhooks

Rate Limits

API requests are rate limited to 60 requests per minute per API key. This limit ensures fair resource distribution across all API consumers.

Rate Limit Headers

Every API response includes headers showing your current rate limit status:

HeaderDescription
X-RateLimit-LimitMaximum requests allowed per window
X-RateLimit-RemainingRequests remaining in current window
X-RateLimit-ResetUnix timestamp when the window resets
Rate Limit Exceeded?

If you exceed your rate limit, you'll receive a 429 Too Many Requests response. Wait until the reset time before making more requests.

Generate Image

Create AI-generated images from text prompts.

POST /api/v1/generate/image

Request Body

ParameterTypeRequiredDescription
promptstringYesText description of the image to generate
modelstringNoModel ID (default: prunaai/z-image-turbo). Use GET /api/v1/models to list all available models.
aspect_ratiostringNoImage aspect ratio: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3
output_formatstringNoOutput image format: webp, png, jpg (default: webp)
webhook_urlstringNoURL to receive a webhook when generation completes

Example Request

curl
curl -X POST https://aivisualstudio.co/api/v1/generate/image \
  -H "Authorization: Bearer avs_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A futuristic city at sunset, cyberpunk style",
    "model": "prunaai/z-image-turbo",
    "aspect_ratio": "16:9"
  }'

Response

200 OK
{
  "id": "gen_abc123def456",
  "status": "processing",
  "prompt": "A futuristic city at sunset, cyberpunk style",
  "model": "prunaai/z-image-turbo",
  "type": "image",
  "credits_charged": 5,
  "created_at": "2025-01-09T12:00:00Z"
}

Generate Video

Create AI-generated videos from text prompts or images.

POST /api/v1/generate/video

Request Body

ParameterTypeRequiredDescription
promptstringYesText description of the video to generate
modelstringNoModel ID (default: minimax/hailuo-2.3-fast). Use GET /api/v1/models?type=video to list all available models.
aspect_ratiostringNoVideo aspect ratio: 16:9, 9:16, 1:1, 4:3, 3:4 (default: 16:9)
durationintegerNoVideo duration in seconds, 1-10 (default: 5)
first_frame_imagestringNoSource image URL for image-to-video generation
webhook_urlstringNoURL to receive a webhook when generation completes

Example Request

curl
curl -X POST https://aivisualstudio.co/api/v1/generate/video \
  -H "Authorization: Bearer avs_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A spaceship flying through an asteroid field",
    "model": "minimax/hailuo-2.3-fast",
    "duration": 5
  }'

List Generations

Retrieve a list of your generations with pagination support.

GET /api/v1/generations

Query Parameters

ParameterTypeDescription
typestringFilter by type: image or video
statusstringFilter by status: processing, completed, failed
limitintegerNumber of results (default: 20, max: 100)
offsetintegerPagination offset

Example Request

curl
curl -X GET "https://aivisualstudio.co/api/v1/generations?limit=10&type=image" \
  -H "Authorization: Bearer avs_live_your_api_key"

Get Single Generation

GET /api/v1/generations/:id

Retrieve details of a specific generation by ID.

Models

List all available AI models for image and video generation.

GET /api/v1/models

Query Parameters

ParameterTypeDescription
typestringFilter by type: image or video

Response Example

200 OK
{
  "data": [
    {
      "id": "prunaai/z-image-turbo",
      "name": "Z-Image Turbo",
      "type": "image",
      "credits_per_generation": 5,
      "description": "Fast image generation",
      "category": "image-generation"
    },
    {
      "id": "minimax/hailuo-2.3-fast",
      "name": "Hailuo 2.3 Fast",
      "type": "video",
      "credits_per_generation": 450,
      "description": "Fast video generation",
      "category": "video-generation"
    }
  ],
  "total": 18
}

Webhooks

Receive real-time notifications when your generations complete or fail. Webhooks use HMAC-SHA256 signatures for security.

Create Webhook

POST /api/v1/webhooks

Request Body

ParameterTypeRequiredDescription
urlstringYesHTTPS URL to receive webhook events
eventsarrayNoEvents to subscribe to (default: all)

Available Events

  • generation.completed - Generation finished successfully
  • generation.failed - Generation failed

Example: Create Webhook

curl
curl -X POST https://aivisualstudio.co/api/v1/webhooks \
  -H "Authorization: Bearer avs_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-app.com/webhooks/photoverse",
    "events": ["generation.completed", "generation.failed"]
  }'

Webhook Payload

Webhook Event
{
  "event": "generation.completed",
  "data": {
    "id": "gen_abc123def456",
    "type": "image",
    "status": "completed",
    "prompt": "A futuristic city at sunset",
    "output_url": "https://cdn.example.com/image.png",
    "created_at": "2025-01-09T12:00:00Z",
    "completed_at": "2025-01-09T12:00:15Z"
  },
  "created_at": "2025-01-09T12:00:15Z"
}

Verifying Webhook Signatures

Every webhook request includes an X-Webhook-Signature header that you should verify to ensure the request came from AI Visual Studio.

Signature Format
X-Webhook-Signature: t=1704801600,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd

Verification Example

curl
import crypto from 'crypto';

function verifyWebhookSignature(payload, signature, secret) {
  const [timestamp, hash] = signature.split(',').map(part => {
    const [key, value] = part.split('=');
    return value;
  });

  // Verify timestamp is recent (within 5 minutes)
  const now = Math.floor(Date.now() / 1000);
  if (Math.abs(now - parseInt(timestamp)) > 300) {
    return false; // Replay attack protection
  }

  const expectedHash = crypto
    .createHmac('sha256', secret)
    .update(`${timestamp}.${JSON.stringify(payload)}`)
    .digest('hex');

  return crypto.timingSafeEqual(
    Buffer.from(hash),
    Buffer.from(expectedHash)
  );
}

// In your webhook handler
app.post('/webhooks/photoverse', (req, res) => {
  const signature = req.headers['x-webhook-signature'];

  if (!verifyWebhookSignature(req.body, signature, WEBHOOK_SECRET)) {
    return res.status(401).send('Invalid signature');
  }

  // Process the webhook
  const { event, data } = req.body;
  console.log('Received event:', event, data);

  res.status(200).send('OK');
});

Other Webhook Endpoints

GET
/api/v1/webhooksList all webhooks
PATCH
/api/v1/webhooks/:idUpdate a webhook
DELETE
/api/v1/webhooks/:idDelete a webhook

API Keys

Manage your API keys programmatically. These endpoints use web session authentication (cookie-based) rather than API key authentication.

Web Session Required

API key management endpoints require you to be logged in via the web interface. They cannot be accessed with an API key.

POST
/api/v1/keysCreate a new API key
GET
/api/v1/keysList all your API keys
DELETE
/api/v1/keys/:idRevoke an API key

Create API Key

ParameterTypeRequiredDescription
namestringYesDisplay name for the API key
scopesarrayNoPermission scopes (default: ["read"])
ip_allowlistarrayNoAllowed IP addresses
expires_atstringNoExpiration date (ISO 8601)

Error Handling

The API uses standard HTTP status codes and returns detailed error information in JSON format.

Error Response Format

Error Response
{
  "error": {
    "code": "insufficient_credits",
    "message": "You need 5 credits but only have 2",
    "details": {
      "required": 5,
      "available": 2
    }
  }
}

Error Codes

CodeHTTP StatusDescription
missing_api_key401No API key provided in request
invalid_api_key401API key is invalid or revoked
expired_api_key401API key has expired
insufficient_scope403API key doesn't have required permissions
ip_not_allowed403Request from unauthorized IP address
insufficient_credits403Not enough credits for this operation
rate_limited429Too many requests, please slow down
invalid_request400Invalid request parameters
not_found404Requested resource not found
internal_error500Unexpected server error