API Documentation

Complete reference for the AI402 REST API. Generate assets with simple HTTP requests.

Introduction

The AI402 API is organized around REST. It accepts JSON-encoded request bodies and returns JSON-encoded responses. All responses are compressed for performance.

Base URL

HTTPS
https://ai402.net

Quick Start

BASH / cURL
# Generate an image example
curl -X POST https://ai402.net/v1/image \
  -H "X-API-Key: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "A sunset over mountains"}'

Authentication

All API requests require authentication using an API key. Include your key in the X-API-Key header.

⚠️

Keep your API key secret! Don't expose it in client-side code (browsers) or public repositories.

Header
X-API-Key: ai402_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx

Error Handling

We use standard HTTP status codes. Errors include a descriptive JSON body.

CodeDescription
200Success
400Bad Request — Invalid JSON or parameters
401Unauthorized — Invalid API Key
402Payment Required — Insufficient credits
500Server Error — Please contact support
JSON Error Response
{
  "error": "Insufficient credits",
  "required": 50,
  "available": 10
}

Image Generation

Generate images from text prompts or edit existing images. Cost: 1 credit.

POST /v1/image

Generate an image from a text prompt, optionally with a reference image.

Parameters

NameTypeDescription
promptREQ string Description of the desired image
image binary Reference image for editing (multipart/form-data)

Example Request

JavaScript / Node
const response = await fetch('https://ai402.net/v1/image', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your_api_key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    prompt: 'A futuristic city with flying cars'
  })
});

const data = await response.json();
console.log(data.url);

Video Generation

Generate 8-second videos. Cost: 50 credits.

POST /v1/video

Generate a video from a text prompt. Process takes 1-3 minutes.

Parameters

NameTypeDescription
promptREQ string Cinematic description of motion
ℹ️

Video generation is asynchronous. You can poll the status endpoint or wait for the webhook.

Success Response
{
  "success": true,
  "url": "https://ai402.net/video/...",
  "credits_used": 50
}

Voice Synthesis

Convert text to natural speech. Cost: 0.5 credits.

POST /v1/voice

Parameters

NameTypeDescription
textREQ string Max 300 chars
voice enum 'Aurora', 'Richard', 'Blade', 'Vicky'
high_quality boolean Enable 48kHz audio (slower)