Complete reference for the AI402 REST API. Generate assets with simple HTTP requests.
The AI402 API is organized around REST. It accepts JSON-encoded request bodies and returns JSON-encoded responses. All responses are compressed for performance.
https://ai402.net
# 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"}'
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.
X-API-Key: ai402_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
We use standard HTTP status codes. Errors include a descriptive JSON body.
| Code | Description |
|---|---|
200 | Success |
400 | Bad Request — Invalid JSON or parameters |
401 | Unauthorized — Invalid API Key |
402 | Payment Required — Insufficient credits |
500 | Server Error — Please contact support |
{
"error": "Insufficient credits",
"required": 50,
"available": 10
}
Generate images from text prompts or edit existing images. Cost: 1 credit.
Generate an image from a text prompt, optionally with a reference image.
| Name | Type | Description |
|---|---|---|
| promptREQ | string | Description of the desired image |
| image | binary | Reference image for editing (multipart/form-data) |
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);
Generate 8-second videos. Cost: 50 credits.
Generate a video from a text prompt. Process takes 1-3 minutes.
| Name | Type | Description |
|---|---|---|
| promptREQ | string | Cinematic description of motion |
Video generation is asynchronous. You can poll the status endpoint or wait for the webhook.
{
"success": true,
"url": "https://ai402.net/video/...",
"credits_used": 50
}
Convert text to natural speech. Cost: 0.5 credits.
| Name | Type | Description |
|---|---|---|
| textREQ | string | Max 300 chars |
| voice | enum | 'Aurora', 'Richard', 'Blade', 'Vicky' |
| high_quality | boolean | Enable 48kHz audio (slower) |