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.
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 streamPOST /api/generate
One endpoint for all workflow types. workflowId routes the job to the correct AI pipeline. Returns immediately.
| Field | Type | Required |
|---|---|---|
| workflowId | string | Yes |
| params | object | Yes |
| providerId | string | No |
{
"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 confirmedprogresspercentage (0–100)successvideoUrl / mediaUrls / lyricserrorError messageendTerminal — 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();
});GET /api/gallery/my
List all past generations for the authenticated account. Cursor-based pagination — pass nextCursor as cursor to get the next page.
| Param | Default |
|---|---|
| limit | 20 (max 100) |
| cursor | — (first page) |
| type | all types |
const res = await fetch(
'https://api.phenomenalai.in/api/gallery/my?limit=20',
{ headers: { 'X-API-Key': 'ph_your_key_here' } }
);
const data = await res.json();
data.gallery.forEach(item => console.log(item.s3_url));
// Load next page
if (data.pagination.hasMore) {
const next = await fetch(
`https://api.phenomenalai.in/api/gallery/my?limit=20&cursor=${data.pagination.nextCursor}`,
{ headers: { 'X-API-Key': 'ph_your_key_here' } }
);
}{
"status": "success",
"gallery": [
{
"id": "507f1f77bcf86cd799439011",
"type": "text-to-image",
"s3_url": "https://storage.phenomenalai.in/generations/.../image.png",
"thumbnail_url": "https://storage.phenomenalai.in/generations/.../thumb.jpg",
"prompt": "a golden retriever on a mountain",
"status": "completed",
"created_at": "2026-06-04T10:30:00.000Z",
"model": "turbo",
"resolution": "1024×1024"
}
],
"pagination": {
"hasMore": true,
"nextCursor": "2026-06-04T10:00:00.000Z",
"limit": 20
}
}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:
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{
"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[
{ "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.
| Endpoint | Description |
|---|---|
| POST /api/developer/keys | Create a new key |
| GET /api/developer/keys | List all your keys |
| DELETE /api/developer/keys/:id | Revoke a key |
| PATCH /api/developer/keys/:id/rotate | Rotate — new key, old deactivated |
| GET /api/developer/scopes | List 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 IDWorkflows
Pass one of these as workflowId in POST /api/generate.
| workflowId | Category | Scope required | Input | Output |
|---|---|---|---|---|
| text-to-video | Video | video:generate | text | video |
| image-to-video | Video | video:generate | text, image | video |
| video-upscale | Video | video:generate | video | video |
| text-to-image | Image | image:generate | text | image |
| image-edit | Image | image:generate | text, image | image |
| reference-image | Image | image:generate | text, image | image |
| blueprint-slot | Image | image:generate | text, image | image |
| text-to-music | Audio | audio:generate | text | audio |
Scopes
Assign scopes when creating an API key. A key can only call endpoints its scopes permit.
video:generateSubmit video generation jobsimage:generateSubmit image generation jobsaudio:generateSubmit audio/music generation jobsgallery:readRead gallery items and stats*Full access to all scopesError Codes
All errors: {"message":"...","code":"SCREAMING_SNAKE"}
| HTTP | Code | When |
|---|---|---|
| 400 | VALIDATION_ERROR | Bad request body |
| 401 | AUTH_REQUIRED | No API key or JWT provided |
| 401 | AUTH_INVALID | Expired or invalid key |
| 402 | INSUFFICIENT_CREDITS | Not enough credits |
| 403 | FEATURE_DISABLED | Workflow disabled |
| 403 | PLAN_RESTRICTION | Quality tier not on plan |
| 403 | SCOPE_DENIED | API key missing required scope |
| 429 | RATE_LIMITED | Per-key rate limit exceeded |
| 503 | NO_PROVIDER | No provider available |
| 500 | INTERNAL_ERROR | Unexpected server error |