REST APIv1

API Reference

Generate videos, images, and audio programmatically. All the same workflows available on the platform — accessible via HTTP.

Get API Key →api.phenomenalai.in

Authentication

Every request requires your API key in the X-API-Key header. Store it as an environment variable — never hard-code it or expose it client-side.

Create and manage keys from your Developer Portal. Each key has scopes that limit which workflows it can call.

Never expose your key in browser code. Use it server-side only.

const response = await fetch('https://api.phenomenalai.in/api/generate', {
  method: 'POST',
  headers: {
    'X-API-Key': process.env.PHENOMENAL_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ workflowId: 'text-to-image', params: { ... } }),
});

Quick Start

All generation is asynchronous. Submit a job → get a taskId → poll or stream for the result.

1Submit a generation job
2Get a taskId back immediately
3Poll or stream until complete
4Fetch the output URL
const res = await fetch('https://api.phenomenalai.in/api/generate', {
  method: 'POST',
  headers: {
    'X-API-Key': 'ph_your_key_here',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    workflowId: 'text-to-image',
    params: {
      prompt: 'a golden retriever on a mountain at sunrise',
      aspectRatio: '16:9',
      imageSize: '1K',
    },
  }),
});
const { data } = await res.json();
// data.taskId → use to poll or stream

POST /api/generate

One endpoint for all workflow types. workflowId routes the job to the correct AI pipeline. Returns immediately.

FieldTypeRequired
workflowIdstringYes
paramsobjectYes
providerIdstringNo
Response
{
  "success": true,
  "data": {
    "taskId":     "550e8400-e29b-41d4-a716-446655440000",
    "workflowId": "text-to-image",
    "creditCost": 6
  }
}

SSE Streaming

For real-time progress, connect to the Server-Sent Events stream. Use ?apikey= since EventSource cannot send headers.

infoConnection confirmed
progresspercentage (0–100)
successvideoUrl / mediaUrls / lyrics
errorError message
endTerminal — stream closes
// Browser / Node 18+ — EventSource cannot send headers,
// so pass the key as a query param
const stream = new EventSource(
  `https://api.phenomenalai.in/api/progress-stream/${taskId}?apikey=ph_your_key`
);

stream.addEventListener('progress', e => {
  const { percentage } = JSON.parse(e.data);
  console.log(`${percentage}%`);
});

stream.addEventListener('success', e => {
  const { videoUrl, mediaUrls } = JSON.parse(e.data);
  console.log('Done:', videoUrl ?? mediaUrls);
  stream.close();
});

stream.addEventListener('error', e => {
  console.error(JSON.parse(e.data).message);
  stream.close();
});

POST /api/inference/upload-image — Image Upload

Required before using image-to-video, image-edit, or reference-image workflows. Upload your image first, then pass the returned imageUrl in the generation request.

Alternatively, pass any publicly accessible URL directly as imageUrl — no upload needed if your image is already hosted.

Constraints:

Max 30 MB per file
JPEG, PNG, WebP, HEIC, HEIF, TIFF, BMP, GIF, AVIF accepted
Minimum 64×64, maximum 4096×4096 pixels
PNG auto-converted to JPEG unless transparent

Requires JWT auth — API key auth is not supported for this endpoint. Use Authorization: Bearer.

const form = new FormData();
form.append('image', fileBlob, 'photo.jpg'); // File or Blob

const res = await fetch('https://api.phenomenalai.in/api/inference/upload-image', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_JWT_TOKEN' },
  body: form,
});
const { imageUrl } = await res.json();
// imageUrl → pass as imageUrl in the next generation request
Response
{
  "status":     "success",
  "message":    "Image uploaded successfully",
  "imageUrl":   "https://storage.phenomenalai.in/assets/...",
  "imageS3Key": "assets/userId/uuid.jpg",
  "imageId":    "uuid.jpg"
}

GET /api/developer/workflows

Returns all workflows with their required scopes and credit costs. No authentication needed — safe to call publicly.

Use GET /api/generate/workflows with your API key to get only the workflows currently enabled by platform feature flags.

const res = await fetch(
  'https://api.phenomenalai.in/api/generate/workflows',
  { headers: { 'X-API-Key': 'ph_your_key_here' } }
);
const workflows = await res.json();
// Returns only workflows currently enabled by platform feature flags
Response
[
  { "id": "text-to-video",   "name": "Text to Video",   "category": "video", "requiredScope": "video:generate" },
  { "id": "image-to-video",  "name": "Image to Video",  "category": "video", "requiredScope": "video:generate" },
  { "id": "video-upscale",   "name": "Video Upscale",   "category": "video", "requiredScope": "video:generate" },
  { "id": "text-to-image",   "name": "Text to Image",   "category": "image", "requiredScope": "image:generate" },
  { "id": "image-edit",      "name": "Image Edit",      "category": "image", "requiredScope": "image:generate" },
  { "id": "reference-image", "name": "Reference Image", "category": "image", "requiredScope": "image:generate" },
  { "id": "blueprint-slot",  "name": "Blueprint Slot",  "category": "image", "requiredScope": "image:generate" },
  { "id": "text-to-music",   "name": "Text to Music",   "category": "audio", "requiredScope": "audio:generate" }
]

Key Management API

Manage API keys programmatically. All key management endpoints require JWT authentication — API keys cannot manage other API keys.

EndpointDescription
POST /api/developer/keysCreate a new key
GET /api/developer/keysList all your keys
DELETE /api/developer/keys/:idRevoke a key
PATCH /api/developer/keys/:id/rotateRotate — new key, old deactivated
GET /api/developer/scopesList valid scopes (public)
// Create
const res = await fetch('https://api.phenomenalai.in/api/developer/keys', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_JWT_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'Production',
    scopes: ['video:generate', 'image:generate', 'gallery:read'],
    expiresAt: null,
  }),
});
const { key, id, prefix } = await res.json();
// key = "ph_..." — shown ONCE, store it securely

// List
const list = await fetch('https://api.phenomenalai.in/api/developer/keys', {
  headers: { 'Authorization': 'Bearer YOUR_JWT_TOKEN' },
});
const keys = await list.json();

// Rotate
const rot = await fetch(`https://api.phenomenalai.in/api/developer/keys/${keyId}/rotate`, {
  method: 'PATCH',
  headers: { 'Authorization': 'Bearer YOUR_JWT_TOKEN' },
});
const { key: newKey } = await rot.json();

GET /.well-known/jwks.json

Exposes the RS256 public key used to sign all JWTs issued by Phenomenal AI. Use this to verify tokens on your own server — you never need our private key.

Works with any JWKS-compatible JWT library. The key ID is ph-rs256-1.

This endpoint is always public and requires no authentication. The public key is safe to distribute.

// Fetch public key to verify JWT tokens issued by Phenomenal AI
const res = await fetch('https://api.phenomenalai.in/.well-known/jwks.json');
const { keys } = await res.json();
// keys[0] = { kty: 'RSA', alg: 'RS256', use: 'sig', kid: 'ph-rs256-1', n: '...', e: 'AQAB' }

// Verify with any JWT library that supports JWKS
import { createRemoteJWKSet, jwtVerify } from 'jose';

const JWKS = createRemoteJWKSet(
  new URL('https://api.phenomenalai.in/.well-known/jwks.json')
);
const { payload } = await jwtVerify(token, JWKS);
// payload.id = MongoDB account ID

Workflows

Pass one of these as workflowId in POST /api/generate.

workflowIdCategoryScope requiredInputOutput
text-to-videoVideovideo:generatetextvideo
image-to-videoVideovideo:generatetext, imagevideo
video-upscaleVideovideo:generatevideovideo
text-to-imageImageimage:generatetextimage
image-editImageimage:generatetext, imageimage
reference-imageImageimage:generatetext, imageimage
blueprint-slotImageimage:generatetext, imageimage
text-to-musicAudioaudio:generatetextaudio

Scopes

Assign scopes when creating an API key. A key can only call endpoints its scopes permit.

video:generateSubmit video generation jobs
image:generateSubmit image generation jobs
audio:generateSubmit audio/music generation jobs
gallery:readRead gallery items and stats
*Full access to all scopes

Error Codes

All errors: {"message":"...","code":"SCREAMING_SNAKE"}

HTTPCodeWhen
400VALIDATION_ERRORBad request body
401AUTH_REQUIREDNo API key or JWT provided
401AUTH_INVALIDExpired or invalid key
402INSUFFICIENT_CREDITSNot enough credits
403FEATURE_DISABLEDWorkflow disabled
403PLAN_RESTRICTIONQuality tier not on plan
403SCOPE_DENIEDAPI key missing required scope
429RATE_LIMITEDPer-key rate limit exceeded
503NO_PROVIDERNo provider available
500INTERNAL_ERRORUnexpected server error