@mynthio/sdk 0.0.40 → 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/convex/index.d.ts +39 -100
- package/dist/convex/index.js +41 -2
- package/dist/handler.d.ts +28 -0
- package/dist/handler.js +121 -0
- package/dist/index.d.ts +674 -360
- package/dist/index.js +1469 -2
- package/dist/next/index.d.ts +14 -24
- package/dist/next/index.js +25 -2
- package/dist/tanstack-start/index.d.ts +18 -23
- package/dist/tanstack-start/index.js +11 -2
- package/dist/types.d.ts +610 -660
- package/package.json +16 -21
- package/dist/client.d.ts +0 -41
- package/dist/client.d.ts.map +0 -1
- package/dist/constants.d.ts +0 -95
- package/dist/constants.d.ts.map +0 -1
- package/dist/convex/index.d.ts.map +0 -1
- package/dist/convex/utils.d.ts +0 -2
- package/dist/convex/utils.d.ts.map +0 -1
- package/dist/image-alt-result.d.ts +0 -19
- package/dist/image-alt-result.d.ts.map +0 -1
- package/dist/image-generation-result.d.ts +0 -58
- package/dist/image-generation-result.d.ts.map +0 -1
- package/dist/image-rate-result.d.ts +0 -21
- package/dist/image-rate-result.d.ts.map +0 -1
- package/dist/image-remove-background-result.d.ts +0 -24
- package/dist/image-remove-background-result.d.ts.map +0 -1
- package/dist/image-review-result.d.ts +0 -28
- package/dist/image-review-result.d.ts.map +0 -1
- package/dist/index-apss16tr.js +0 -3
- package/dist/index-ty295921.js +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/next/index.d.ts.map +0 -1
- package/dist/tanstack-start/index.d.ts.map +0 -1
- package/dist/task-async.d.ts +0 -95
- package/dist/task-async.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/uploads.d.ts +0 -31
- package/dist/uploads.d.ts.map +0 -1
- package/dist/video-generation-result.d.ts +0 -46
- package/dist/video-generation-result.d.ts.map +0 -1
- package/dist/webhooks/utils.d.ts +0 -5
- package/dist/webhooks/utils.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,1469 @@
|
|
|
1
|
-
|
|
2
|
-
var R="https://api.mynth.io",H="MYNTH_API_KEY",g="MYNTH_DESTINATION",_="/image/generate",M="/image/upload",q="/image/rate",m="/image/alt",y="/image/review",k="/image/remove-background",h="/video/generate",E="/video/generate/estimate",T="/models";var I=(J)=>`/tasks/${J}`;var c=(J)=>`/tasks/${J}/status`,ZJ=[{id:"auto",label:"Auto",capabilities:[]},{id:"alibaba/qwen-image-2.0",label:"Qwen Image 2.0",capabilities:["inputs","native_enhance_prompt"]},{id:"alibaba/qwen-image-2.0-pro",label:"Qwen Image 2.0 Pro",capabilities:["inputs","native_enhance_prompt"]},{id:"alibaba/qwen-image-3.0",label:"Qwen Image 3.0",capabilities:["inputs","native_enhance_prompt"]},{id:"alibaba/qwen-image-3.0-pro",label:"Qwen Image 3.0 Pro",capabilities:["inputs","native_enhance_prompt"]},{id:"bytedance/seedream-5.0-lite",label:"Seedream 5.0 Lite",capabilities:["inputs"]},{id:"bytedance/seedream-pro",label:"Seedream Pro",capabilities:["inputs"]},{id:"black-forest-labs/flux.1-dev",label:"FLUX.1 Dev",capabilities:[]},{id:"black-forest-labs/flux-1-schnell",label:"FLUX.1 Schnell",capabilities:[]},{id:"tongyi-mai/z-image",label:"Z Image",capabilities:["inputs"]},{id:"tongyi-mai/z-image-turbo",label:"Z Image Turbo",capabilities:[]},{id:"black-forest-labs/flux.2-dev",label:"FLUX.2 Dev",capabilities:["inputs"]},{id:"black-forest-labs/flux.2-pro",label:"FLUX.2 Pro",capabilities:["inputs"]},{id:"black-forest-labs/flux.2-flex",label:"FLUX.2 Flex",capabilities:["inputs"]},{id:"black-forest-labs/flux.2-max",label:"FLUX.2 Max",capabilities:["inputs"]},{id:"black-forest-labs/flux.2-klein-4b",label:"FLUX.2 Klein 4B",capabilities:["inputs"]},{id:"bria/fibo-edit-1.5",label:"FIBO Edit 1.5",capabilities:["inputs"]},{id:"bria/fibo-generate-1.5",label:"FIBO Generate 1.5",capabilities:[]},{id:"circlestone-labs/anima",label:"Anima",capabilities:["inputs"]},{id:"john6666/bismuth-illustrious-mix",label:"Bismuth Illustrious Mix",capabilities:["negative_prompt"]},{id:"maxfeifei8/one-obsession",label:"One obsession",capabilities:["negative_prompt"]},{id:"klingai/kling-image-3.0",label:"Kling IMAGE 3.0",capabilities:["inputs"]},{id:"klingai/kling-image-o3",label:"Kling IMAGE O3",capabilities:["inputs","4k"]},{id:"krea/krea-2-turbo",label:"Krea 2 Turbo",capabilities:["inputs"]},{id:"krea/krea-2-medium",label:"Krea 2 Medium",capabilities:["inputs"]},{id:"krea/krea-2-large",label:"Krea 2 Large",capabilities:["inputs"]},{id:"luma/uni-1",label:"Luma UNI-1",capabilities:["inputs"]},{id:"luma/uni-1-max",label:"Luma UNI-1 Max",capabilities:["inputs"]},{id:"meta/muse-image",label:"Muse Image",capabilities:["inputs"]},{id:"microsoft/mai-image-2.6",label:"MAI Image 2.6",capabilities:["inputs"]},{id:"microsoft/mai-image-2.6-flash",label:"MAI Image 2.6 Flash",capabilities:["inputs"]},{id:"minimax/h3",label:"MiniMax H3",capabilities:["inputs"]},{id:"purplesmartai/pony-diffusion-v6-xl",label:"Pony Diffusion V6 XL",capabilities:["negative_prompt"]},{id:"recraft/recraft-v4",label:"Recraft V4",capabilities:[]},{id:"recraft/recraft-v4-pro",label:"Recraft V4 Pro",capabilities:[]},{id:"reve/reve",label:"Reve",capabilities:["inputs"]},{id:"reve/reve-remix",label:"Reve Remix",capabilities:["inputs"]},{id:"sourceful/riverflow-2.0-pro",label:"Riverflow 2.0 Pro",capabilities:["inputs","4k","native_enhance_prompt"]},{id:"google/gemini-3.1-flash-lite-image",label:"Nano Banana 2 Lite",capabilities:["inputs","native_enhance_prompt"]},{id:"google/gemini-3.1-flash-image",label:"Nano Banana 2",capabilities:["inputs","4k","native_enhance_prompt"]},{id:"google/gemini-3-pro-image-preview",label:"Nano Banana Pro",capabilities:["inputs","4k","native_enhance_prompt"]},{id:"imagineart/imagineart-1.5-pro",label:"ImagineArt 1.5 Pro",capabilities:["4k"]},{id:"imagineart/imagineart-2.0",label:"ImagineArt 2.0",capabilities:["inputs"]},{id:"openai/gpt-image-2",label:"GPT Image 2",capabilities:["inputs"]},{id:"openai/gpt-image-2.5-flare",label:"GPT Image 2.5 Flare",capabilities:["inputs"]},{id:"openai/gpt-image-2.5-sunburst",label:"GPT Image 2.5 Sunburst",capabilities:["inputs"]},{id:"wan/wan2.6-image",label:"Wan 2.6 Image",capabilities:[]},{id:"wan/wan2.7-image",label:"Wan 2.7 Image",capabilities:["inputs"]},{id:"wan/wan2.7-image-pro",label:"Wan 2.7 Image Pro",capabilities:["inputs","4k"]},{id:"xai/grok-imagine-image",label:"Grok Imagine Image",capabilities:["inputs"]},{id:"xai/grok-imagine-image-2.0",label:"Grok Imagine Image 2.0",capabilities:["inputs"]},{id:"xai/grok-imagine-image-quality",label:"Grok Imagine Image Quality",capabilities:["inputs"]}],A={timeoutMs:3600000,fastDurationMs:0,intervalMs:1e4},$J=[{id:"bytedance/seedance-2.0-mini",label:"Seedance 2.0 Mini",resolutions:["480p","720p"],defaultResolution:"720p",duration:{default:5,min:4,max:15},audio:!0,inputs:["first_frame","last_frame"],maxInputs:2},{id:"google/gemini-omni-flash-1.1",label:"Gemini Omni Flash 1.1",resolutions:["720p","1080p","4k"],defaultResolution:"720p",duration:{default:8,min:3,max:10},audio:!0,inputs:["first_frame","last_frame"],maxInputs:2},{id:"prunaai/p-video",label:"P-Video",resolutions:["720p","1080p"],defaultResolution:"720p",duration:{default:5,min:1,max:10},audio:!0,inputs:["first_frame"],maxInputs:1}];class N extends Error{status;code;constructor(J,Q,Z){super(J);this.name="MynthAPIError",this.status=Q,this.code=Z}}function l(J,Q){let Z=J,W=Z.error||Z.message||`Request failed with status ${Q}`;return new N(W,Q,Z.code)}class w{apiKey;baseUrl;constructor(J){this.apiKey=J.apiKey,this.baseUrl=J.baseUrl?J.baseUrl.endsWith("/")?J.baseUrl.slice(0,-1):J.baseUrl:R}getAuthHeaders(J){if(J?.auth===!1)return{};let Q=J?.accessToken??this.apiKey;return Q?{Authorization:`Bearer ${Q}`}:{}}getUrl(J){return`${this.baseUrl}${J}`}async post(J,Q){let Z=typeof FormData<"u"&&Q instanceof FormData,W=await fetch(this.getUrl(J),{method:"POST",headers:{...Z?{}:{"Content-Type":"application/json"},...this.getAuthHeaders()},body:Z?Q:JSON.stringify(Q)}),X=await W.json();if(!W.ok)throw l(X,W.status);return X}async get(J,{headers:Q,accessToken:Z,auth:W}={}){let X=await fetch(this.getUrl(J),{headers:{...this.getAuthHeaders({accessToken:Z,auth:W}),...Q}});return{data:await X.json(),status:X.status,ok:X.ok}}async getOrThrow(J,Q={}){let Z=await this.get(J,Q);if(!Z.ok)throw l(Z.data,Z.status);return Z.data}}class C{taskId;cost;alt;constructor(J){this.taskId=J.taskId,this.cost=J.cost,this.alt=J.alt}static fromTaskData(J){if(J.status!=="completed"||J.result===null)throw Error(`Image alt task ${J.id} is not completed`);if(J.cost===null)throw Error(`Image alt task ${J.id} is missing cost`);return new C({taskId:J.id,cost:J.cost,alt:J.result.alt})}}class V{data;constructor(J){this.data=J}get id(){return this.data.id}get status(){return this.data.status}get result(){return this.data.result}get isCompleted(){return this.data.status==="completed"}get isFailed(){return this.data.status==="failed"}get urls(){return this.data.result?.images.filter((J)=>J.status==="success").map((J)=>J.url).filter((J)=>J!==null)??[]}getImages(J={}){if(J.includeFailed)return this.data.result?.images??[];return this.data.result?.images.filter((Q)=>Q.status==="success")??[]}getMetadata(){return this.data.request?.metadata}}class K{taskId;cost;level;constructor(J){this.taskId=J.taskId,this.cost=J.cost,this.level=J.level}static fromTaskData(J){if(J.status!=="completed"||J.result===null)throw Error(`Image rate task ${J.id} is not completed`);if(J.cost===null)throw Error(`Image rate task ${J.id} is missing cost`);return new K({taskId:J.id,cost:J.cost,level:J.result.level})}}class S{taskId;cost;image;metadata;constructor(J){this.taskId=J.taskId,this.cost=J.cost,this.image=J.image,this.metadata=J.metadata}static fromTaskData(J){if(J.status!=="completed"||J.result===null)throw Error(`Image remove background task ${J.id} is not completed`);if(J.cost===null)throw Error(`Image remove background task ${J.id} is missing cost`);return new S({taskId:J.id,cost:J.cost,image:J.result.image,metadata:J.request.metadata})}}class U{taskId;cost;score;summary;findings;strengths;constructor(J){this.taskId=J.taskId,this.cost=J.cost,this.score=J.score,this.summary=J.summary,this.findings=J.findings,this.strengths=J.strengths}static fromTaskData(J){if(J.status!=="completed"||J.result===null)throw Error(`Image review task ${J.id} is not completed`);if(J.cost===null)throw Error(`Image review task ${J.id} is missing cost`);return new U({taskId:J.id,cost:J.cost,...J.result})}}var d=1800000,WJ=12000,XJ=2500,jJ=5000,p=20;class f extends Error{constructor(J,Q=d){super(`Task ${J} polling timed out after ${Q}ms`);this.name="TaskAsyncTimeoutError"}}class F extends Error{constructor(J){super(`Unauthorized access to task ${J}`);this.name="TaskAsyncUnauthorizedError"}}class O extends Error{constructor(J,Q){super(`Failed to fetch status for task ${J} after multiple retries`);this.name="TaskAsyncFetchError",this.cause=Q}}class D extends Error{constructor(J,Q,Z){let W=Q?` (status ${Q})`:"";super(`Failed to fetch task ${J}${W}`);this.name="TaskAsyncTaskFetchError",this.cause=Z}}class P extends Error{constructor(J){super(`Task ${J} failed`);this.name="TaskAsyncTaskFailedError"}}class z{id;client;_access;resultFactory;polling;_completionPromise=null;constructor(J,Q){this.id=J,this.client=Q.client,this._access={publicAccessToken:Q.pat},this.resultFactory=Q.resultFactory,this.polling={timeoutMs:Q.polling?.timeoutMs??d,fastDurationMs:Q.polling?.fastDurationMs??WJ,fastIntervalMs:Q.polling?.fastIntervalMs??XJ,intervalMs:Q.polling?.intervalMs??jJ}}get access(){return this._access}toString(){return this.id}async wait(){if(!this._completionPromise)this._completionPromise=this.pollUntilCompleted();return this._completionPromise}async pollUntilCompleted(){let{timeoutMs:J,fastDurationMs:Q,fastIntervalMs:Z,intervalMs:W}=this.polling,X=Date.now(),$=0,j=!1,Y;while(!0){let b=Date.now()-X;if(b>=J)throw new f(this.id,J);let x=await this.fetchStatus(j);if(x.ok)if(x.status==="completed"){let B=await this.fetchTask();if(B.ok)return this.resultFactory(B.data);if(B.unauthorized)throw new F(this.id);if($++,!B.retryable||$>=p)throw new D(this.id,B.status,B.error)}else if(x.status==="failed")throw new P(this.id);else $=0;else{if((x.unauthorized||x.notFound)&&this._access.publicAccessToken&&!j){j=!0;continue}if(x.unauthorized)throw new F(this.id);if(x.retryable){if($++,Y=x.error,$>=p)throw new O(this.id,Y)}}let a=b<Q?Z:W,e=Math.random()*500,t=a+e,JJ=J-b,QJ=Math.min(t,JJ);await this.sleep(QJ)}}async fetchStatus(J){let Q=J||!this._access.publicAccessToken?void 0:this._access.publicAccessToken;try{let Z=await this.client.get(c(this.id),{accessToken:Q});if(Z.ok)return{ok:!0,status:Z.data.data.status};if(Z.status===401||Z.status===403)return{ok:!1,unauthorized:!0,retryable:!1};if(Z.status===404)return{ok:!1,unauthorized:!1,retryable:!0,notFound:!0};if(Z.status>=500)return{ok:!1,unauthorized:!1,retryable:!0};return{ok:!1,unauthorized:!1,retryable:!1}}catch(Z){return{ok:!1,unauthorized:!1,retryable:!0,error:Z instanceof Error?Z:Error(String(Z))}}}async fetchTask(){try{let J=await this.client.get(I(this.id));if(J.ok)return{ok:!0,data:J.data.data};if(J.status===401||J.status===403)return{ok:!1,unauthorized:!0,retryable:!1};if(J.status===404||J.status>=500)return{ok:!1,unauthorized:!1,retryable:!0,status:J.status};return{ok:!1,unauthorized:!1,retryable:!1,status:J.status}}catch(J){return{ok:!1,unauthorized:!1,retryable:!0,error:J instanceof Error?J:Error(String(J))}}}sleep(J){return new Promise((Q)=>setTimeout(Q,J))}}var xJ="images",zJ="image";function u(J){return typeof Blob<"u"&&J instanceof Blob}async function G(J,Q){let Z=new FormData,W=Array.isArray(Q)?Q:[Q];for(let $ of W)Z.append(xJ,$,typeof File<"u"&&$ instanceof File?$.name:zJ);return(await J.post(M,Z)).data}async function L(J,Q){if(!Q?.length)return;let Z=Q.flatMap(($)=>{if(u($))return[$];if(typeof $!=="string"&&$.source.type==="file")return[$.source.file];return[]}),W=Z.length?(await G(J,Z)).urls:[],X=0;return Q.map(($)=>{if(typeof $==="string")return $;if(u($))return W[X++];if($.source.type==="file")return{type:"image",as:$.as,source:{type:"url",url:W[X++]}};return{type:"image",as:$.as,source:$.source}})}class v{data;constructor(J){this.data=J}get id(){return this.data.id}get status(){return this.data.status}get result(){return this.data.result}get isCompleted(){return this.data.status==="completed"}get isFailed(){return this.data.status==="failed"}get urls(){return this.getVideos().map((J)=>J.url)}getVideos(J={}){if(J.includeFailed)return this.data.result?.videos??[];return this.data.result?.videos.filter((Q)=>Q.status==="success")??[]}getMetadata(){return this.data.request?.metadata}}function i(){if(typeof process<"u"&&process.env)return process.env[H];return}function YJ(){if(typeof process<"u"&&process.env)return process.env[g];return}class n{client;defaultDestination;constructor(J={}){let Q=J.apiKey??i();if(!Q)throw Error(`Mynth API key is required. Either pass it as an option or set the ${H} environment variable.`);this.defaultDestination=J.destination??YJ(),this.client=new w({apiKey:Q,baseUrl:J.baseUrl})}async generate(J){return(await this.createGenerationTask(J)).wait()}async upload(J){return G(this.client,J)}async generateAsync(J){return this.createGenerationTask(J)}async createGenerationTask(J){let Q=await L(this.client,J.inputs),W=(await this.client.post(_,{...J,inputs:Q,destination:J.destination??this.defaultDestination})).data;return new z(W.taskId,{client:this.client,pat:W.access?.publicAccessToken,resultFactory:($)=>new V($)})}async rate(J){return(await this.createRateTask(J)).wait()}async rateAsync(J){return this.createRateTask(J)}async resolveUrlOrFile(J){if(J.file!==void 0){let{urls:Q}=await this.upload(J.file),Z=Q[0];if(!Z)throw Error("Image upload returned no URL");return Z}return J.url}async createRateTask(J){let Q=await this.resolveUrlOrFile(J),{file:Z,url:W,...X}=J,j=(await this.client.post(q,{...X,url:Q})).data;return new z(j.taskId,{client:this.client,resultFactory:(b)=>K.fromTaskData(b)})}async alt(J){return(await this.createAltTask(J)).wait()}async altAsync(J){return this.createAltTask(J)}async createAltTask(J){let Q=await this.resolveUrlOrFile(J),W=(await this.client.post(m,{url:Q})).data;return new z(W.taskId,{client:this.client,resultFactory:($)=>C.fromTaskData($)})}async review(J){return(await this.createReviewTask(J)).wait()}async reviewAsync(J){return this.createReviewTask(J)}async createReviewTask(J){let Q=await this.resolveUrlOrFile(J),{file:Z,url:W,...X}=J,j=(await this.client.post(y,{...X,url:Q})).data;return new z(j.taskId,{client:this.client,resultFactory:(Y)=>U.fromTaskData(Y)})}async removeBackground(J){return(await this.createRemoveBackgroundTask(J)).wait()}async removeBackgroundAsync(J){return this.createRemoveBackgroundTask(J)}async createRemoveBackgroundTask(J){let Q=await this.resolveUrlOrFile(J),{file:Z,url:W,...X}=J,j=(await this.client.post(k,{...X,url:Q,destination:J.destination??this.defaultDestination})).data;return new z(j.taskId,{client:this.client,pat:j.access?.publicAccessToken,resultFactory:(Y)=>S.fromTaskData(Y)})}}class o{client;constructor(J={}){let Q=J.apiKey??i();if(!Q)throw Error(`Mynth API key is required. Either pass it as an option or set the ${H} environment variable.`);this.client=new w({apiKey:Q,baseUrl:J.baseUrl})}async generate(J){return(await this.createGenerationTask(J)).wait()}async generateAsync(J){return this.createGenerationTask(J)}async upload(J){return G(this.client,J)}async estimate(J){return(await this.client.post(E,await this.toRequestBody(J))).data}async toRequestBody(J){let Q=await L(this.client,J.inputs);return{...J,inputs:Q}}async createGenerationTask(J){let Z=(await this.client.post(h,await this.toRequestBody(J))).data;return new z(Z.taskId,{client:this.client,pat:Z.access?.publicAccessToken,polling:A,resultFactory:(W)=>new v(W)})}}class r{client;constructor(J={}){this.client=new w({baseUrl:J.baseUrl})}async list(){return(await this.client.getOrThrow(T,{auth:!1})).data}}class s{models;options;imageClient;videoClient;constructor(J={}){this.options=J,this.models=new r({baseUrl:J.baseUrl})}get image(){return this.imageClient??=new n(this.options),this.imageClient}get video(){return this.videoClient??=new o(this.options),this.videoClient}}var kJ=s;export{kJ as default,v as VideoGenerationResult,F as TaskAsyncUnauthorizedError,f as TaskAsyncTimeoutError,D as TaskAsyncTaskFetchError,P as TaskAsyncTaskFailedError,O as TaskAsyncFetchError,z as TaskAsync,o as MynthVideo,r as MynthModels,n as MynthImage,N as MynthAPIError,s as Mynth,U as ImageReviewResult,S as ImageRemoveBackgroundResult,K as ImageRateResult,V as ImageGenerationResult,C as ImageAltResult,$J as AVAILABLE_VIDEO_MODELS,ZJ as AVAILABLE_MODELS};
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
/** Base URL for the Mynth API */
|
|
3
|
+
const API_URL = "https://api.mynth.io";
|
|
4
|
+
/** Environment variable name for the API key */
|
|
5
|
+
const API_KEY_ENV_VAR = "MYNTH_API_KEY";
|
|
6
|
+
/** Environment variable name for the default destination (by name/slug) */
|
|
7
|
+
const DESTINATION_ENV_VAR = "MYNTH_DESTINATION";
|
|
8
|
+
const GENERATE_IMAGE_PATH = "/image/generate";
|
|
9
|
+
const UPLOAD_IMAGE_PATH = "/image/upload";
|
|
10
|
+
const RATE_IMAGE_PATH = "/image/rate";
|
|
11
|
+
const ALT_IMAGE_PATH = "/image/alt";
|
|
12
|
+
const REVIEW_IMAGE_PATH = "/image/review";
|
|
13
|
+
const REMOVE_BACKGROUND_IMAGE_PATH = "/image/remove-background";
|
|
14
|
+
const GENERATE_VIDEO_PATH = "/video/generate";
|
|
15
|
+
const ESTIMATE_VIDEO_PATH = "/video/generate/estimate";
|
|
16
|
+
const MODELS_PATH = "/models";
|
|
17
|
+
const TASK_PATH = "/tasks";
|
|
18
|
+
const TASK_DETAILS_PATH = (id) => `${TASK_PATH}/${id}`;
|
|
19
|
+
const TASK_STATUS_PATH = (id) => `${TASK_PATH}/${id}/status`;
|
|
20
|
+
/**
|
|
21
|
+
* List of all available image generation models with their capabilities.
|
|
22
|
+
* Use this to build model selectors or validate model IDs.
|
|
23
|
+
*/
|
|
24
|
+
const AVAILABLE_MODELS = [
|
|
25
|
+
{
|
|
26
|
+
id: "auto",
|
|
27
|
+
label: "Auto",
|
|
28
|
+
capabilities: []
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "alibaba/qwen-image-2.0",
|
|
32
|
+
label: "Qwen Image 2.0",
|
|
33
|
+
capabilities: ["inputs", "native_enhance_prompt"]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "alibaba/qwen-image-2.0-pro",
|
|
37
|
+
label: "Qwen Image 2.0 Pro",
|
|
38
|
+
capabilities: ["inputs", "native_enhance_prompt"]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "alibaba/qwen-image-3.0",
|
|
42
|
+
label: "Qwen Image 3.0",
|
|
43
|
+
capabilities: ["inputs", "native_enhance_prompt"]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "alibaba/qwen-image-3.0-pro",
|
|
47
|
+
label: "Qwen Image 3.0 Pro",
|
|
48
|
+
capabilities: ["inputs", "native_enhance_prompt"]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: "bytedance/seedream-5.0-lite",
|
|
52
|
+
label: "Seedream 5.0 Lite",
|
|
53
|
+
capabilities: ["inputs"]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: "bytedance/seedream-pro",
|
|
57
|
+
label: "Seedream Pro",
|
|
58
|
+
capabilities: ["inputs"]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "black-forest-labs/flux.1-dev",
|
|
62
|
+
label: "FLUX.1 Dev",
|
|
63
|
+
capabilities: []
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: "black-forest-labs/flux-1-schnell",
|
|
67
|
+
label: "FLUX.1 Schnell",
|
|
68
|
+
capabilities: []
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: "tongyi-mai/z-image",
|
|
72
|
+
label: "Z Image",
|
|
73
|
+
capabilities: ["inputs"]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "tongyi-mai/z-image-turbo",
|
|
77
|
+
label: "Z Image Turbo",
|
|
78
|
+
capabilities: []
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "black-forest-labs/flux.2-dev",
|
|
82
|
+
label: "FLUX.2 Dev",
|
|
83
|
+
capabilities: ["inputs"]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "black-forest-labs/flux.2-pro",
|
|
87
|
+
label: "FLUX.2 Pro",
|
|
88
|
+
capabilities: ["inputs"]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: "black-forest-labs/flux.2-flex",
|
|
92
|
+
label: "FLUX.2 Flex",
|
|
93
|
+
capabilities: ["inputs"]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "black-forest-labs/flux.2-max",
|
|
97
|
+
label: "FLUX.2 Max",
|
|
98
|
+
capabilities: ["inputs"]
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: "black-forest-labs/flux.2-klein-4b",
|
|
102
|
+
label: "FLUX.2 Klein 4B",
|
|
103
|
+
capabilities: ["inputs"]
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "bria/fibo-edit-1.5",
|
|
107
|
+
label: "FIBO Edit 1.5",
|
|
108
|
+
capabilities: ["inputs"]
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: "bria/fibo-generate-1.5",
|
|
112
|
+
label: "FIBO Generate 1.5",
|
|
113
|
+
capabilities: []
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: "circlestone-labs/anima",
|
|
117
|
+
label: "Anima",
|
|
118
|
+
capabilities: ["inputs"]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: "john6666/bismuth-illustrious-mix",
|
|
122
|
+
label: "Bismuth Illustrious Mix",
|
|
123
|
+
capabilities: ["negative_prompt"]
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: "maxfeifei8/one-obsession",
|
|
127
|
+
label: "One obsession",
|
|
128
|
+
capabilities: ["negative_prompt"]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: "klingai/kling-image-3.0",
|
|
132
|
+
label: "Kling IMAGE 3.0",
|
|
133
|
+
capabilities: ["inputs"]
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: "klingai/kling-image-o3",
|
|
137
|
+
label: "Kling IMAGE O3",
|
|
138
|
+
capabilities: ["inputs", "4k"]
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: "krea/krea-2-turbo",
|
|
142
|
+
label: "Krea 2 Turbo",
|
|
143
|
+
capabilities: ["inputs"]
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: "krea/krea-2-medium",
|
|
147
|
+
label: "Krea 2 Medium",
|
|
148
|
+
capabilities: ["inputs"]
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: "krea/krea-2-large",
|
|
152
|
+
label: "Krea 2 Large",
|
|
153
|
+
capabilities: ["inputs"]
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: "luma/uni-1",
|
|
157
|
+
label: "Luma UNI-1",
|
|
158
|
+
capabilities: ["inputs"]
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
id: "luma/uni-1-max",
|
|
162
|
+
label: "Luma UNI-1 Max",
|
|
163
|
+
capabilities: ["inputs"]
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
id: "meta/muse-image",
|
|
167
|
+
label: "Muse Image",
|
|
168
|
+
capabilities: ["inputs"]
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
id: "microsoft/mai-image-2.6",
|
|
172
|
+
label: "MAI Image 2.6",
|
|
173
|
+
capabilities: ["inputs"]
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
id: "microsoft/mai-image-2.6-flash",
|
|
177
|
+
label: "MAI Image 2.6 Flash",
|
|
178
|
+
capabilities: ["inputs"]
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
id: "minimax/h3",
|
|
182
|
+
label: "MiniMax H3",
|
|
183
|
+
capabilities: ["inputs"]
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
id: "purplesmartai/pony-diffusion-v6-xl",
|
|
187
|
+
label: "Pony Diffusion V6 XL",
|
|
188
|
+
capabilities: ["negative_prompt"]
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: "recraft/recraft-v4",
|
|
192
|
+
label: "Recraft V4",
|
|
193
|
+
capabilities: []
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
id: "recraft/recraft-v4-pro",
|
|
197
|
+
label: "Recraft V4 Pro",
|
|
198
|
+
capabilities: []
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: "reve/reve",
|
|
202
|
+
label: "Reve",
|
|
203
|
+
capabilities: ["inputs"]
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
id: "reve/reve-remix",
|
|
207
|
+
label: "Reve Remix",
|
|
208
|
+
capabilities: ["inputs"]
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: "sourceful/riverflow-2.0-pro",
|
|
212
|
+
label: "Riverflow 2.0 Pro",
|
|
213
|
+
capabilities: [
|
|
214
|
+
"inputs",
|
|
215
|
+
"4k",
|
|
216
|
+
"native_enhance_prompt"
|
|
217
|
+
]
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
id: "google/gemini-3.1-flash-lite-image",
|
|
221
|
+
label: "Nano Banana 2 Lite",
|
|
222
|
+
capabilities: ["inputs", "native_enhance_prompt"]
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
id: "google/gemini-3.1-flash-image",
|
|
226
|
+
label: "Nano Banana 2",
|
|
227
|
+
capabilities: [
|
|
228
|
+
"inputs",
|
|
229
|
+
"4k",
|
|
230
|
+
"native_enhance_prompt"
|
|
231
|
+
]
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
id: "google/gemini-3-pro-image-preview",
|
|
235
|
+
label: "Nano Banana Pro",
|
|
236
|
+
capabilities: [
|
|
237
|
+
"inputs",
|
|
238
|
+
"4k",
|
|
239
|
+
"native_enhance_prompt"
|
|
240
|
+
]
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: "imagineart/imagineart-1.5-pro",
|
|
244
|
+
label: "ImagineArt 1.5 Pro",
|
|
245
|
+
capabilities: ["4k"]
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
id: "imagineart/imagineart-2.0",
|
|
249
|
+
label: "ImagineArt 2.0",
|
|
250
|
+
capabilities: ["inputs"]
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
id: "openai/gpt-image-2",
|
|
254
|
+
label: "GPT Image 2",
|
|
255
|
+
capabilities: ["inputs"]
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
id: "openai/gpt-image-2.5-flare",
|
|
259
|
+
label: "GPT Image 2.5 Flare",
|
|
260
|
+
capabilities: ["inputs"]
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: "openai/gpt-image-2.5-sunburst",
|
|
264
|
+
label: "GPT Image 2.5 Sunburst",
|
|
265
|
+
capabilities: ["inputs"]
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: "wan/wan2.6-image",
|
|
269
|
+
label: "Wan 2.6 Image",
|
|
270
|
+
capabilities: []
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
id: "wan/wan2.7-image",
|
|
274
|
+
label: "Wan 2.7 Image",
|
|
275
|
+
capabilities: ["inputs"]
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
id: "wan/wan2.7-image-pro",
|
|
279
|
+
label: "Wan 2.7 Image Pro",
|
|
280
|
+
capabilities: ["inputs", "4k"]
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
id: "xai/grok-imagine-image",
|
|
284
|
+
label: "Grok Imagine Image",
|
|
285
|
+
capabilities: ["inputs"]
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
id: "xai/grok-imagine-image-2.0",
|
|
289
|
+
label: "Grok Imagine Image 2.0",
|
|
290
|
+
capabilities: ["inputs"]
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
id: "xai/grok-imagine-image-quality",
|
|
294
|
+
label: "Grok Imagine Image Quality",
|
|
295
|
+
capabilities: ["inputs"]
|
|
296
|
+
}
|
|
297
|
+
];
|
|
298
|
+
/**
|
|
299
|
+
* Polling profile for video tasks.
|
|
300
|
+
*
|
|
301
|
+
* Video generation runs for minutes rather than seconds, so there is no fast
|
|
302
|
+
* opening phase to spend requests on, the steady interval is longer, and the
|
|
303
|
+
* wait budget is an hour instead of the 30 minutes image tasks get.
|
|
304
|
+
*/
|
|
305
|
+
const VIDEO_POLLING = {
|
|
306
|
+
timeoutMs: 36e5,
|
|
307
|
+
fastDurationMs: 0,
|
|
308
|
+
intervalMs: 1e4
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* List of all available video generation models with their capabilities.
|
|
312
|
+
* Unlike images, video generation has no `auto` model: pick one explicitly.
|
|
313
|
+
*/
|
|
314
|
+
const AVAILABLE_VIDEO_MODELS = [
|
|
315
|
+
{
|
|
316
|
+
id: "bytedance/seedance-2.0-mini",
|
|
317
|
+
label: "Seedance 2.0 Mini",
|
|
318
|
+
resolutions: ["480p", "720p"],
|
|
319
|
+
defaultResolution: "720p",
|
|
320
|
+
duration: {
|
|
321
|
+
default: 5,
|
|
322
|
+
min: 4,
|
|
323
|
+
max: 15
|
|
324
|
+
},
|
|
325
|
+
audio: true,
|
|
326
|
+
inputs: ["first_frame", "last_frame"],
|
|
327
|
+
maxInputs: 2
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
id: "google/gemini-omni-flash-1.1",
|
|
331
|
+
label: "Gemini Omni Flash 1.1",
|
|
332
|
+
resolutions: [
|
|
333
|
+
"720p",
|
|
334
|
+
"1080p",
|
|
335
|
+
"4k"
|
|
336
|
+
],
|
|
337
|
+
defaultResolution: "720p",
|
|
338
|
+
duration: {
|
|
339
|
+
default: 8,
|
|
340
|
+
min: 3,
|
|
341
|
+
max: 10
|
|
342
|
+
},
|
|
343
|
+
audio: true,
|
|
344
|
+
inputs: ["first_frame", "last_frame"],
|
|
345
|
+
maxInputs: 2
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
id: "prunaai/p-video",
|
|
349
|
+
label: "P-Video",
|
|
350
|
+
resolutions: ["720p", "1080p"],
|
|
351
|
+
defaultResolution: "720p",
|
|
352
|
+
duration: {
|
|
353
|
+
default: 5,
|
|
354
|
+
min: 1,
|
|
355
|
+
max: 10
|
|
356
|
+
},
|
|
357
|
+
audio: true,
|
|
358
|
+
inputs: ["first_frame"],
|
|
359
|
+
maxInputs: 1
|
|
360
|
+
}
|
|
361
|
+
];
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region src/client.ts
|
|
364
|
+
/**
|
|
365
|
+
* Error thrown when an API request fails.
|
|
366
|
+
*/
|
|
367
|
+
var MynthAPIError = class extends Error {
|
|
368
|
+
/** HTTP status code of the failed request */
|
|
369
|
+
status;
|
|
370
|
+
/** Error code from the API response, if available */
|
|
371
|
+
code;
|
|
372
|
+
constructor(message, status, code) {
|
|
373
|
+
super(message);
|
|
374
|
+
this.name = "MynthAPIError";
|
|
375
|
+
this.status = status;
|
|
376
|
+
this.code = code;
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
function createApiError(data, status) {
|
|
380
|
+
const errorResponse = data;
|
|
381
|
+
return new MynthAPIError(errorResponse.error || errorResponse.message || `Request failed with status ${status}`, status, errorResponse.code);
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Internal HTTP client for making API requests.
|
|
385
|
+
* @internal
|
|
386
|
+
*/
|
|
387
|
+
var MynthClient = class {
|
|
388
|
+
apiKey;
|
|
389
|
+
baseUrl;
|
|
390
|
+
constructor(options) {
|
|
391
|
+
this.apiKey = options.apiKey;
|
|
392
|
+
this.baseUrl = options.baseUrl ? options.baseUrl.endsWith("/") ? options.baseUrl.slice(0, -1) : options.baseUrl : API_URL;
|
|
393
|
+
}
|
|
394
|
+
getAuthHeaders(override) {
|
|
395
|
+
if (override?.auth === false) return {};
|
|
396
|
+
const token = override?.accessToken ?? this.apiKey;
|
|
397
|
+
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
398
|
+
}
|
|
399
|
+
getUrl(path) {
|
|
400
|
+
return `${this.baseUrl}${path}`;
|
|
401
|
+
}
|
|
402
|
+
async post(path, data) {
|
|
403
|
+
const isFormData = typeof FormData !== "undefined" && data instanceof FormData;
|
|
404
|
+
const response = await fetch(this.getUrl(path), {
|
|
405
|
+
method: "POST",
|
|
406
|
+
headers: {
|
|
407
|
+
...isFormData ? {} : { "Content-Type": "application/json" },
|
|
408
|
+
...this.getAuthHeaders()
|
|
409
|
+
},
|
|
410
|
+
body: isFormData ? data : JSON.stringify(data)
|
|
411
|
+
});
|
|
412
|
+
const json = await response.json();
|
|
413
|
+
if (!response.ok) throw createApiError(json, response.status);
|
|
414
|
+
return json;
|
|
415
|
+
}
|
|
416
|
+
async get(path, { headers, accessToken, auth } = {}) {
|
|
417
|
+
const response = await fetch(this.getUrl(path), { headers: {
|
|
418
|
+
...this.getAuthHeaders({
|
|
419
|
+
accessToken,
|
|
420
|
+
auth
|
|
421
|
+
}),
|
|
422
|
+
...headers
|
|
423
|
+
} });
|
|
424
|
+
return {
|
|
425
|
+
data: await response.json(),
|
|
426
|
+
status: response.status,
|
|
427
|
+
ok: response.ok
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
async getOrThrow(path, options = {}) {
|
|
431
|
+
const response = await this.get(path, options);
|
|
432
|
+
if (!response.ok) throw createApiError(response.data, response.status);
|
|
433
|
+
return response.data;
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/image-alt-result.ts
|
|
438
|
+
/**
|
|
439
|
+
* Represents the result of a completed image alt text task.
|
|
440
|
+
*/
|
|
441
|
+
var ImageAltResult = class ImageAltResult {
|
|
442
|
+
/** The task ID created for this alt text request */
|
|
443
|
+
taskId;
|
|
444
|
+
/** Cost charged for the completed task */
|
|
445
|
+
cost;
|
|
446
|
+
/** Generated alt text */
|
|
447
|
+
alt;
|
|
448
|
+
constructor(data) {
|
|
449
|
+
this.taskId = data.taskId;
|
|
450
|
+
this.cost = data.cost;
|
|
451
|
+
this.alt = data.alt;
|
|
452
|
+
}
|
|
453
|
+
static fromTaskData(data) {
|
|
454
|
+
if (data.status !== "completed" || data.result === null) throw new Error(`Image alt task ${data.id} is not completed`);
|
|
455
|
+
if (data.cost === null) throw new Error(`Image alt task ${data.id} is missing cost`);
|
|
456
|
+
return new ImageAltResult({
|
|
457
|
+
taskId: data.id,
|
|
458
|
+
cost: data.cost,
|
|
459
|
+
alt: data.result.alt
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
//#endregion
|
|
464
|
+
//#region src/image-generation-result.ts
|
|
465
|
+
/**
|
|
466
|
+
* Represents a completed image generation task.
|
|
467
|
+
*
|
|
468
|
+
* @template MetadataT - Type of the metadata attached to the request
|
|
469
|
+
* @template RatingT - Type of the rating response
|
|
470
|
+
*/
|
|
471
|
+
var ImageGenerationResult = class {
|
|
472
|
+
/** Raw task data from the API */
|
|
473
|
+
data;
|
|
474
|
+
constructor(data) {
|
|
475
|
+
this.data = data;
|
|
476
|
+
}
|
|
477
|
+
/** Unique identifier for this task */
|
|
478
|
+
get id() {
|
|
479
|
+
return this.data.id;
|
|
480
|
+
}
|
|
481
|
+
/** Current status of the task */
|
|
482
|
+
get status() {
|
|
483
|
+
return this.data.status;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* The generation result containing images, cost, and model info.
|
|
487
|
+
* Returns `null` if the task hasn't completed yet.
|
|
488
|
+
*/
|
|
489
|
+
get result() {
|
|
490
|
+
return this.data.result;
|
|
491
|
+
}
|
|
492
|
+
/** Whether the task completed successfully */
|
|
493
|
+
get isCompleted() {
|
|
494
|
+
return this.data.status === "completed";
|
|
495
|
+
}
|
|
496
|
+
/** Whether the task failed */
|
|
497
|
+
get isFailed() {
|
|
498
|
+
return this.data.status === "failed";
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Get all successfully generated image URLs.
|
|
502
|
+
* Convenience method that extracts just the URLs from successful images.
|
|
503
|
+
* Images delivered only to a user destination may have a `null` url and are omitted here;
|
|
504
|
+
* use `getImages()` and read `mynth_url` to access the CDN URL directly.
|
|
505
|
+
*/
|
|
506
|
+
get urls() {
|
|
507
|
+
return this.data.result?.images.filter((img) => img.status === "success").map((img) => img.url).filter((url) => url !== null) ?? [];
|
|
508
|
+
}
|
|
509
|
+
getImages(options = {}) {
|
|
510
|
+
if (options.includeFailed) return this.data.result?.images ?? [];
|
|
511
|
+
return this.data.result?.images.filter((image) => image.status === "success") ?? [];
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Get the metadata that was attached to the generation request.
|
|
515
|
+
*/
|
|
516
|
+
getMetadata() {
|
|
517
|
+
return this.data.request?.metadata;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
//#endregion
|
|
521
|
+
//#region src/image-rate-result.ts
|
|
522
|
+
/**
|
|
523
|
+
* Represents the result of a completed image content rating task.
|
|
524
|
+
*
|
|
525
|
+
* @template LevelT - Union of possible rating level strings (e.g. `"sfw" | "nsfw"`)
|
|
526
|
+
*/
|
|
527
|
+
var ImageRateResult = class ImageRateResult {
|
|
528
|
+
/** The task ID created for this rating request */
|
|
529
|
+
taskId;
|
|
530
|
+
/** Cost charged for the completed task */
|
|
531
|
+
cost;
|
|
532
|
+
/** Assigned rating level */
|
|
533
|
+
level;
|
|
534
|
+
constructor(data) {
|
|
535
|
+
this.taskId = data.taskId;
|
|
536
|
+
this.cost = data.cost;
|
|
537
|
+
this.level = data.level;
|
|
538
|
+
}
|
|
539
|
+
static fromTaskData(data) {
|
|
540
|
+
if (data.status !== "completed" || data.result === null) throw new Error(`Image rate task ${data.id} is not completed`);
|
|
541
|
+
if (data.cost === null) throw new Error(`Image rate task ${data.id} is missing cost`);
|
|
542
|
+
return new ImageRateResult({
|
|
543
|
+
taskId: data.id,
|
|
544
|
+
cost: data.cost,
|
|
545
|
+
level: data.result.level
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
//#endregion
|
|
550
|
+
//#region src/image-remove-background-result.ts
|
|
551
|
+
/**
|
|
552
|
+
* Represents the result of a completed image background removal task.
|
|
553
|
+
*
|
|
554
|
+
* @template MetadataT - Type of the metadata attached to the request
|
|
555
|
+
*/
|
|
556
|
+
var ImageRemoveBackgroundResult = class ImageRemoveBackgroundResult {
|
|
557
|
+
/** The task ID created for this request */
|
|
558
|
+
taskId;
|
|
559
|
+
/** Cost charged for the completed task */
|
|
560
|
+
cost;
|
|
561
|
+
/** The image with its background removed */
|
|
562
|
+
image;
|
|
563
|
+
/** Metadata attached to the request */
|
|
564
|
+
metadata;
|
|
565
|
+
constructor(data) {
|
|
566
|
+
this.taskId = data.taskId;
|
|
567
|
+
this.cost = data.cost;
|
|
568
|
+
this.image = data.image;
|
|
569
|
+
this.metadata = data.metadata;
|
|
570
|
+
}
|
|
571
|
+
static fromTaskData(data) {
|
|
572
|
+
if (data.status !== "completed" || data.result === null) throw new Error(`Image remove background task ${data.id} is not completed`);
|
|
573
|
+
if (data.cost === null) throw new Error(`Image remove background task ${data.id} is missing cost`);
|
|
574
|
+
return new ImageRemoveBackgroundResult({
|
|
575
|
+
taskId: data.id,
|
|
576
|
+
cost: data.cost,
|
|
577
|
+
image: data.result.image,
|
|
578
|
+
metadata: data.request.metadata
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
//#endregion
|
|
583
|
+
//#region src/image-review-result.ts
|
|
584
|
+
/**
|
|
585
|
+
* Represents the result of a completed image quality review task.
|
|
586
|
+
*/
|
|
587
|
+
var ImageReviewResult = class ImageReviewResult {
|
|
588
|
+
/** The task ID created for this review request */
|
|
589
|
+
taskId;
|
|
590
|
+
/** Cost charged for the completed task */
|
|
591
|
+
cost;
|
|
592
|
+
/** Median reviewer score from 1 to 4. Higher is better. */
|
|
593
|
+
score;
|
|
594
|
+
/** Review summary */
|
|
595
|
+
summary;
|
|
596
|
+
/** Defects found by the reviewer panel */
|
|
597
|
+
findings;
|
|
598
|
+
/** Strengths identified by the reviewer panel */
|
|
599
|
+
strengths;
|
|
600
|
+
constructor(data) {
|
|
601
|
+
this.taskId = data.taskId;
|
|
602
|
+
this.cost = data.cost;
|
|
603
|
+
this.score = data.score;
|
|
604
|
+
this.summary = data.summary;
|
|
605
|
+
this.findings = data.findings;
|
|
606
|
+
this.strengths = data.strengths;
|
|
607
|
+
}
|
|
608
|
+
static fromTaskData(data) {
|
|
609
|
+
if (data.status !== "completed" || data.result === null) throw new Error(`Image review task ${data.id} is not completed`);
|
|
610
|
+
if (data.cost === null) throw new Error(`Image review task ${data.id} is missing cost`);
|
|
611
|
+
return new ImageReviewResult({
|
|
612
|
+
taskId: data.id,
|
|
613
|
+
cost: data.cost,
|
|
614
|
+
...data.result
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
//#endregion
|
|
619
|
+
//#region src/task-async.ts
|
|
620
|
+
const POLLING_TIMEOUT_MS = 18e5;
|
|
621
|
+
const FAST_POLLING_DURATION_MS = 12e3;
|
|
622
|
+
const FAST_POLLING_INTERVAL_MS = 2500;
|
|
623
|
+
const SLOW_POLLING_INTERVAL_MS = 5e3;
|
|
624
|
+
const MAX_RETRY_COUNT = 20;
|
|
625
|
+
/**
|
|
626
|
+
* Error thrown when task polling exceeds the maximum timeout duration.
|
|
627
|
+
*/
|
|
628
|
+
var TaskAsyncTimeoutError = class extends Error {
|
|
629
|
+
constructor(taskId, timeoutMs = POLLING_TIMEOUT_MS) {
|
|
630
|
+
super(`Task ${taskId} polling timed out after ${timeoutMs}ms`);
|
|
631
|
+
this.name = "TaskAsyncTimeoutError";
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
/**
|
|
635
|
+
* Error thrown when access to a task is denied (invalid API key or PAT).
|
|
636
|
+
*/
|
|
637
|
+
var TaskAsyncUnauthorizedError = class extends Error {
|
|
638
|
+
constructor(taskId) {
|
|
639
|
+
super(`Unauthorized access to task ${taskId}`);
|
|
640
|
+
this.name = "TaskAsyncUnauthorizedError";
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
/**
|
|
644
|
+
* Error thrown when fetching task status fails after multiple retries.
|
|
645
|
+
*/
|
|
646
|
+
var TaskAsyncFetchError = class extends Error {
|
|
647
|
+
constructor(taskId, cause) {
|
|
648
|
+
super(`Failed to fetch status for task ${taskId} after multiple retries`);
|
|
649
|
+
this.name = "TaskAsyncFetchError";
|
|
650
|
+
this.cause = cause;
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
/**
|
|
654
|
+
* Error thrown when fetching full task data fails.
|
|
655
|
+
*/
|
|
656
|
+
var TaskAsyncTaskFetchError = class extends Error {
|
|
657
|
+
constructor(taskId, status, cause) {
|
|
658
|
+
const suffix = status ? ` (status ${status})` : "";
|
|
659
|
+
super(`Failed to fetch task ${taskId}${suffix}`);
|
|
660
|
+
this.name = "TaskAsyncTaskFetchError";
|
|
661
|
+
this.cause = cause;
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
/**
|
|
665
|
+
* Error thrown when a task fails before completion.
|
|
666
|
+
*/
|
|
667
|
+
var TaskAsyncTaskFailedError = class extends Error {
|
|
668
|
+
constructor(taskId) {
|
|
669
|
+
super(`Task ${taskId} failed`);
|
|
670
|
+
this.name = "TaskAsyncTaskFailedError";
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
/**
|
|
674
|
+
* Represents an async task that can be polled for completion.
|
|
675
|
+
* Use `wait()` to poll until completion and get the typed result.
|
|
676
|
+
*
|
|
677
|
+
* @template ResultT - The result type returned once the task completes
|
|
678
|
+
*/
|
|
679
|
+
var TaskAsync = class {
|
|
680
|
+
/** The unique identifier for this task */
|
|
681
|
+
id;
|
|
682
|
+
client;
|
|
683
|
+
_access;
|
|
684
|
+
resultFactory;
|
|
685
|
+
polling;
|
|
686
|
+
_completionPromise = null;
|
|
687
|
+
constructor(id, options) {
|
|
688
|
+
this.id = id;
|
|
689
|
+
this.client = options.client;
|
|
690
|
+
this._access = { publicAccessToken: options.pat };
|
|
691
|
+
this.resultFactory = options.resultFactory;
|
|
692
|
+
this.polling = {
|
|
693
|
+
timeoutMs: options.polling?.timeoutMs ?? POLLING_TIMEOUT_MS,
|
|
694
|
+
fastDurationMs: options.polling?.fastDurationMs ?? FAST_POLLING_DURATION_MS,
|
|
695
|
+
fastIntervalMs: options.polling?.fastIntervalMs ?? FAST_POLLING_INTERVAL_MS,
|
|
696
|
+
intervalMs: options.polling?.intervalMs ?? SLOW_POLLING_INTERVAL_MS
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Public access information for client-side polling.
|
|
701
|
+
* Contains the public access token if one was generated.
|
|
702
|
+
*/
|
|
703
|
+
get access() {
|
|
704
|
+
return this._access;
|
|
705
|
+
}
|
|
706
|
+
toString() {
|
|
707
|
+
return this.id;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Polls the task until completion and returns the typed result.
|
|
711
|
+
* Multiple calls to this method return the same promise.
|
|
712
|
+
*
|
|
713
|
+
* @throws {TaskAsyncTimeoutError} If polling exceeds the timeout
|
|
714
|
+
* @throws {TaskAsyncUnauthorizedError} If access is denied
|
|
715
|
+
* @throws {TaskAsyncFetchError} If fetching status fails repeatedly
|
|
716
|
+
* @throws {TaskAsyncTaskFetchError} If fetching the completed task fails
|
|
717
|
+
* @throws {TaskAsyncTaskFailedError} If the task fails before completion
|
|
718
|
+
*/
|
|
719
|
+
async wait() {
|
|
720
|
+
if (!this._completionPromise) this._completionPromise = this.pollUntilCompleted();
|
|
721
|
+
return this._completionPromise;
|
|
722
|
+
}
|
|
723
|
+
async pollUntilCompleted() {
|
|
724
|
+
const { timeoutMs, fastDurationMs, fastIntervalMs, intervalMs } = this.polling;
|
|
725
|
+
const startTime = Date.now();
|
|
726
|
+
let retryCount = 0;
|
|
727
|
+
let useApiKeyFallback = false;
|
|
728
|
+
let lastError;
|
|
729
|
+
while (true) {
|
|
730
|
+
const elapsed = Date.now() - startTime;
|
|
731
|
+
if (elapsed >= timeoutMs) throw new TaskAsyncTimeoutError(this.id, timeoutMs);
|
|
732
|
+
const result = await this.fetchStatus(useApiKeyFallback);
|
|
733
|
+
if (result.ok) {
|
|
734
|
+
if (result.status === "completed") {
|
|
735
|
+
const fetched = await this.fetchTask();
|
|
736
|
+
if (fetched.ok) return this.resultFactory(fetched.data);
|
|
737
|
+
if (fetched.unauthorized) throw new TaskAsyncUnauthorizedError(this.id);
|
|
738
|
+
retryCount++;
|
|
739
|
+
if (!fetched.retryable || retryCount >= MAX_RETRY_COUNT) throw new TaskAsyncTaskFetchError(this.id, fetched.status, fetched.error);
|
|
740
|
+
} else if (result.status === "failed") throw new TaskAsyncTaskFailedError(this.id);
|
|
741
|
+
else retryCount = 0;
|
|
742
|
+
} else {
|
|
743
|
+
if ((result.unauthorized || result.notFound) && this._access.publicAccessToken && !useApiKeyFallback) {
|
|
744
|
+
useApiKeyFallback = true;
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
if (result.unauthorized) throw new TaskAsyncUnauthorizedError(this.id);
|
|
748
|
+
if (result.retryable) {
|
|
749
|
+
retryCount++;
|
|
750
|
+
lastError = result.error;
|
|
751
|
+
if (retryCount >= MAX_RETRY_COUNT) throw new TaskAsyncFetchError(this.id, lastError);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
const interval = (elapsed < fastDurationMs ? fastIntervalMs : intervalMs) + Math.random() * 500;
|
|
755
|
+
const remainingTime = timeoutMs - elapsed;
|
|
756
|
+
const waitTime = Math.min(interval, remainingTime);
|
|
757
|
+
await this.sleep(waitTime);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
async fetchStatus(useApiKey) {
|
|
761
|
+
const accessToken = useApiKey || !this._access.publicAccessToken ? void 0 : this._access.publicAccessToken;
|
|
762
|
+
try {
|
|
763
|
+
const response = await this.client.get(TASK_STATUS_PATH(this.id), { accessToken });
|
|
764
|
+
if (response.ok) return {
|
|
765
|
+
ok: true,
|
|
766
|
+
status: response.data.data.status
|
|
767
|
+
};
|
|
768
|
+
if (response.status === 401 || response.status === 403) return {
|
|
769
|
+
ok: false,
|
|
770
|
+
unauthorized: true,
|
|
771
|
+
retryable: false
|
|
772
|
+
};
|
|
773
|
+
if (response.status === 404) return {
|
|
774
|
+
ok: false,
|
|
775
|
+
unauthorized: false,
|
|
776
|
+
retryable: true,
|
|
777
|
+
notFound: true
|
|
778
|
+
};
|
|
779
|
+
if (response.status >= 500) return {
|
|
780
|
+
ok: false,
|
|
781
|
+
unauthorized: false,
|
|
782
|
+
retryable: true
|
|
783
|
+
};
|
|
784
|
+
return {
|
|
785
|
+
ok: false,
|
|
786
|
+
unauthorized: false,
|
|
787
|
+
retryable: false
|
|
788
|
+
};
|
|
789
|
+
} catch (error) {
|
|
790
|
+
return {
|
|
791
|
+
ok: false,
|
|
792
|
+
unauthorized: false,
|
|
793
|
+
retryable: true,
|
|
794
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
async fetchTask() {
|
|
799
|
+
try {
|
|
800
|
+
const response = await this.client.get(TASK_DETAILS_PATH(this.id));
|
|
801
|
+
if (response.ok) return {
|
|
802
|
+
ok: true,
|
|
803
|
+
data: response.data.data
|
|
804
|
+
};
|
|
805
|
+
if (response.status === 401 || response.status === 403) return {
|
|
806
|
+
ok: false,
|
|
807
|
+
unauthorized: true,
|
|
808
|
+
retryable: false
|
|
809
|
+
};
|
|
810
|
+
if (response.status === 404 || response.status >= 500) return {
|
|
811
|
+
ok: false,
|
|
812
|
+
unauthorized: false,
|
|
813
|
+
retryable: true,
|
|
814
|
+
status: response.status
|
|
815
|
+
};
|
|
816
|
+
return {
|
|
817
|
+
ok: false,
|
|
818
|
+
unauthorized: false,
|
|
819
|
+
retryable: false,
|
|
820
|
+
status: response.status
|
|
821
|
+
};
|
|
822
|
+
} catch (error) {
|
|
823
|
+
return {
|
|
824
|
+
ok: false,
|
|
825
|
+
unauthorized: false,
|
|
826
|
+
retryable: true,
|
|
827
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
sleep(ms) {
|
|
832
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
//#endregion
|
|
836
|
+
//#region src/uploads.ts
|
|
837
|
+
const UPLOAD_FIELD_NAME = "images";
|
|
838
|
+
const UPLOAD_FILENAME = "image";
|
|
839
|
+
function isUploadInput(value) {
|
|
840
|
+
return typeof Blob !== "undefined" && value instanceof Blob;
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Upload images to Mynth temporary input storage.
|
|
844
|
+
* Image and video generation share this endpoint: video inputs are images.
|
|
845
|
+
*/
|
|
846
|
+
async function uploadImages(client, input) {
|
|
847
|
+
const form = new FormData();
|
|
848
|
+
const inputs = Array.isArray(input) ? input : [input];
|
|
849
|
+
for (const upload of inputs) form.append(UPLOAD_FIELD_NAME, upload, typeof File !== "undefined" && upload instanceof File ? upload.name : UPLOAD_FILENAME);
|
|
850
|
+
return (await client.post(UPLOAD_IMAGE_PATH, form)).data;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Turn caller inputs into wire inputs, uploading any local files first.
|
|
854
|
+
* All files go up in a single request, and the returned URLs are slotted back
|
|
855
|
+
* into their original positions so input order (and role) is preserved.
|
|
856
|
+
*/
|
|
857
|
+
async function resolveInputs(client, inputs) {
|
|
858
|
+
if (!inputs?.length) return;
|
|
859
|
+
const files = inputs.flatMap((input) => {
|
|
860
|
+
if (isUploadInput(input)) return [input];
|
|
861
|
+
if (typeof input !== "string" && input.source.type === "file") return [input.source.file];
|
|
862
|
+
return [];
|
|
863
|
+
});
|
|
864
|
+
const urls = files.length ? (await uploadImages(client, files)).urls : [];
|
|
865
|
+
let i = 0;
|
|
866
|
+
return inputs.map((input) => {
|
|
867
|
+
if (typeof input === "string") return input;
|
|
868
|
+
if (isUploadInput(input)) return urls[i++];
|
|
869
|
+
const source = input.source.type === "file" ? {
|
|
870
|
+
type: "url",
|
|
871
|
+
url: urls[i++]
|
|
872
|
+
} : input.source;
|
|
873
|
+
return input.as === void 0 ? {
|
|
874
|
+
type: "image",
|
|
875
|
+
source
|
|
876
|
+
} : {
|
|
877
|
+
type: "image",
|
|
878
|
+
as: input.as,
|
|
879
|
+
source
|
|
880
|
+
};
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
//#endregion
|
|
884
|
+
//#region src/video-generation-result.ts
|
|
885
|
+
/**
|
|
886
|
+
* Represents a completed video generation task.
|
|
887
|
+
*
|
|
888
|
+
* @template MetadataT - Type of the metadata attached to the request
|
|
889
|
+
*/
|
|
890
|
+
var VideoGenerationResult = class {
|
|
891
|
+
/** Raw task data from the API */
|
|
892
|
+
data;
|
|
893
|
+
constructor(data) {
|
|
894
|
+
this.data = data;
|
|
895
|
+
}
|
|
896
|
+
/** Unique identifier for this task */
|
|
897
|
+
get id() {
|
|
898
|
+
return this.data.id;
|
|
899
|
+
}
|
|
900
|
+
/** Current status of the task */
|
|
901
|
+
get status() {
|
|
902
|
+
return this.data.status;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* The generation result containing videos and model info.
|
|
906
|
+
* Returns `null` if the task hasn't completed yet.
|
|
907
|
+
*/
|
|
908
|
+
get result() {
|
|
909
|
+
return this.data.result;
|
|
910
|
+
}
|
|
911
|
+
/** Whether the task completed successfully */
|
|
912
|
+
get isCompleted() {
|
|
913
|
+
return this.data.status === "completed";
|
|
914
|
+
}
|
|
915
|
+
/** Whether the task failed */
|
|
916
|
+
get isFailed() {
|
|
917
|
+
return this.data.status === "failed";
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Get all successfully generated video URLs.
|
|
921
|
+
* Convenience method that extracts just the URLs from successful videos.
|
|
922
|
+
*/
|
|
923
|
+
get urls() {
|
|
924
|
+
return this.getVideos().map((video) => video.url);
|
|
925
|
+
}
|
|
926
|
+
getVideos(options = {}) {
|
|
927
|
+
if (options.includeFailed) return this.data.result?.videos ?? [];
|
|
928
|
+
return this.data.result?.videos.filter((video) => video.status === "success") ?? [];
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Get the metadata that was attached to the generation request.
|
|
932
|
+
*/
|
|
933
|
+
getMetadata() {
|
|
934
|
+
return this.data.request?.metadata;
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region src/index.ts
|
|
939
|
+
/**
|
|
940
|
+
* Attempts to read the API key from environment variables.
|
|
941
|
+
* Works in Node.js, Bun, Deno, and edge runtimes that support process.env.
|
|
942
|
+
*/
|
|
943
|
+
function getApiKeyFromEnv() {
|
|
944
|
+
if (typeof process !== "undefined" && process.env) return process.env[API_KEY_ENV_VAR];
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Attempts to read the default destination from environment variables.
|
|
948
|
+
* Works in Node.js, Bun, Deno, and edge runtimes that support process.env.
|
|
949
|
+
*/
|
|
950
|
+
function getDestinationFromEnv() {
|
|
951
|
+
if (typeof process !== "undefined" && process.env) return process.env[DESTINATION_ENV_VAR];
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Client for interacting with the Mynth image generation and analysis APIs.
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
957
|
+
* ```typescript
|
|
958
|
+
* // Using environment variable (MYNTH_API_KEY)
|
|
959
|
+
* const image = new MynthImage();
|
|
960
|
+
*
|
|
961
|
+
* // Or with explicit API key
|
|
962
|
+
* const image = new MynthImage({ apiKey: "mak_..." });
|
|
963
|
+
*
|
|
964
|
+
* // Generate an image
|
|
965
|
+
* const result = await image.generate({
|
|
966
|
+
* prompt: "A beautiful sunset over mountains",
|
|
967
|
+
* model: "black-forest-labs/flux.1-dev",
|
|
968
|
+
* });
|
|
969
|
+
*
|
|
970
|
+
* console.log(result.urls); // ["https://..."]
|
|
971
|
+
* ```
|
|
972
|
+
*/
|
|
973
|
+
var MynthImage = class {
|
|
974
|
+
client;
|
|
975
|
+
defaultDestination;
|
|
976
|
+
/**
|
|
977
|
+
* Creates a new MynthImage client instance.
|
|
978
|
+
*
|
|
979
|
+
* @param options - Configuration options
|
|
980
|
+
* @param options.apiKey - Your API key (defaults to MYNTH_API_KEY env var)
|
|
981
|
+
* @param options.baseUrl - Custom API base URL
|
|
982
|
+
* @param options.destination - Default destination name (defaults to MYNTH_DESTINATION env var)
|
|
983
|
+
* @throws {Error} If no API key is provided and MYNTH_API_KEY is not set
|
|
984
|
+
*/
|
|
985
|
+
constructor(options = {}) {
|
|
986
|
+
const apiKey = options.apiKey ?? getApiKeyFromEnv();
|
|
987
|
+
if (!apiKey) throw new Error(`Mynth API key is required. Either pass it as an option or set the ${API_KEY_ENV_VAR} environment variable.`);
|
|
988
|
+
this.defaultDestination = options.destination ?? getDestinationFromEnv();
|
|
989
|
+
this.client = new MynthClient({
|
|
990
|
+
apiKey,
|
|
991
|
+
baseUrl: options.baseUrl
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Generate images from a text prompt.
|
|
996
|
+
*
|
|
997
|
+
* @param request - Image generation request parameters
|
|
998
|
+
* @returns A completed ImageGenerationResult with the generation results
|
|
999
|
+
*
|
|
1000
|
+
* @example
|
|
1001
|
+
* ```typescript
|
|
1002
|
+
* const result = await image.generate({
|
|
1003
|
+
* prompt: "A serene lake at dawn",
|
|
1004
|
+
* model: "black-forest-labs/flux.1-dev",
|
|
1005
|
+
* });
|
|
1006
|
+
* console.log(result.urls);
|
|
1007
|
+
* ```
|
|
1008
|
+
*/
|
|
1009
|
+
async generate(request) {
|
|
1010
|
+
return (await this.createGenerationTask(request)).wait();
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Upload one or more images to Mynth temporary input storage.
|
|
1014
|
+
*
|
|
1015
|
+
* Accepts File/Blob or an array of File/Blob inputs.
|
|
1016
|
+
*
|
|
1017
|
+
* @param input - Image input or inputs to upload
|
|
1018
|
+
* @returns Uploaded image URLs that can be passed to generation `inputs`
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```typescript
|
|
1022
|
+
* const { urls } = await image.upload(file);
|
|
1023
|
+
* await image.generate({ prompt: "Use this reference", inputs: urls });
|
|
1024
|
+
* ```
|
|
1025
|
+
*/
|
|
1026
|
+
async upload(input) {
|
|
1027
|
+
return uploadImages(this.client, input);
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Start image generation without waiting for completion.
|
|
1031
|
+
*
|
|
1032
|
+
* @param request - Image generation request parameters
|
|
1033
|
+
* @returns A TaskAsync that can be polled for completion via `.wait()`
|
|
1034
|
+
*
|
|
1035
|
+
* @example
|
|
1036
|
+
* ```typescript
|
|
1037
|
+
* const taskAsync = await image.generateAsync({
|
|
1038
|
+
* prompt: "A futuristic cityscape",
|
|
1039
|
+
* });
|
|
1040
|
+
*
|
|
1041
|
+
* return { id: taskAsync.id, access: taskAsync.access };
|
|
1042
|
+
* ```
|
|
1043
|
+
*/
|
|
1044
|
+
async generateAsync(request) {
|
|
1045
|
+
return this.createGenerationTask(request);
|
|
1046
|
+
}
|
|
1047
|
+
async createGenerationTask(request) {
|
|
1048
|
+
const inputs = await resolveInputs(this.client, request.inputs);
|
|
1049
|
+
const data = (await this.client.post(GENERATE_IMAGE_PATH, {
|
|
1050
|
+
...request,
|
|
1051
|
+
inputs,
|
|
1052
|
+
destination: request.destination ?? this.defaultDestination
|
|
1053
|
+
})).data;
|
|
1054
|
+
return new TaskAsync(data.taskId, {
|
|
1055
|
+
client: this.client,
|
|
1056
|
+
pat: data.access?.publicAccessToken,
|
|
1057
|
+
resultFactory: (data) => new ImageGenerationResult(data)
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Rate the content of a single image.
|
|
1062
|
+
*
|
|
1063
|
+
* Uses AI classification to assign a rating level. Mode defaults to
|
|
1064
|
+
* `"nsfw_sfw"` (`"sfw"` / `"nsfw"`); pass custom `levels` to define your own scale.
|
|
1065
|
+
*
|
|
1066
|
+
* @param request - Image URL or local file, and optional rating mode
|
|
1067
|
+
* @returns An ImageRateResult with the assigned level
|
|
1068
|
+
*
|
|
1069
|
+
* @example
|
|
1070
|
+
* ```typescript
|
|
1071
|
+
* // Default sfw/nsfw (mode optional)
|
|
1072
|
+
* const result = await image.rate({ url: "https://..." });
|
|
1073
|
+
* console.log(result.level); // "sfw" | "nsfw"
|
|
1074
|
+
*
|
|
1075
|
+
* // Custom levels
|
|
1076
|
+
* const result = await image.rate({
|
|
1077
|
+
* url: "https://...",
|
|
1078
|
+
* mode: "custom",
|
|
1079
|
+
* levels: [
|
|
1080
|
+
* { value: "safe", description: "No explicit content" },
|
|
1081
|
+
* { value: "mature", description: "Adult themes, no nudity" },
|
|
1082
|
+
* { value: "explicit", description: "Contains nudity or graphic content" },
|
|
1083
|
+
* ] as const,
|
|
1084
|
+
* });
|
|
1085
|
+
* console.log(result.level); // "safe" | "mature" | "explicit"
|
|
1086
|
+
* ```
|
|
1087
|
+
*/
|
|
1088
|
+
async rate(request) {
|
|
1089
|
+
return (await this.createRateTask(request)).wait();
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Start image content rating without waiting for completion.
|
|
1093
|
+
*
|
|
1094
|
+
* @param request - Image URL or local file, and optional rating mode
|
|
1095
|
+
* @returns A TaskAsync that can be polled for completion via `.wait()`
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* ```typescript
|
|
1099
|
+
* const taskAsync = await image.rateAsync({ url: "https://..." });
|
|
1100
|
+
*
|
|
1101
|
+
* const result = await taskAsync.wait();
|
|
1102
|
+
* console.log(result.level);
|
|
1103
|
+
* ```
|
|
1104
|
+
*/
|
|
1105
|
+
async rateAsync(request) {
|
|
1106
|
+
return this.createRateTask(request);
|
|
1107
|
+
}
|
|
1108
|
+
async resolveUrlOrFile(request) {
|
|
1109
|
+
if (request.file !== void 0) {
|
|
1110
|
+
const { urls } = await this.upload(request.file);
|
|
1111
|
+
const url = urls[0];
|
|
1112
|
+
if (!url) throw new Error("Image upload returned no URL");
|
|
1113
|
+
return url;
|
|
1114
|
+
}
|
|
1115
|
+
return request.url;
|
|
1116
|
+
}
|
|
1117
|
+
async createRateTask(request) {
|
|
1118
|
+
const url = await this.resolveUrlOrFile(request);
|
|
1119
|
+
const { file: _, url: __, ...rest } = request;
|
|
1120
|
+
const data = (await this.client.post(RATE_IMAGE_PATH, {
|
|
1121
|
+
...rest,
|
|
1122
|
+
url
|
|
1123
|
+
})).data;
|
|
1124
|
+
return new TaskAsync(data.taskId, {
|
|
1125
|
+
client: this.client,
|
|
1126
|
+
resultFactory: (taskData) => ImageRateResult.fromTaskData(taskData)
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Generate alt text for a single image.
|
|
1131
|
+
*
|
|
1132
|
+
* Uses AI image analysis to produce short alt text for the image.
|
|
1133
|
+
*
|
|
1134
|
+
* @param request - Image URL or local file
|
|
1135
|
+
* @returns An ImageAltResult with the generated alt text
|
|
1136
|
+
*
|
|
1137
|
+
* @example
|
|
1138
|
+
* ```typescript
|
|
1139
|
+
* const result = await image.alt({ url: "https://..." });
|
|
1140
|
+
* console.log(result.alt);
|
|
1141
|
+
* ```
|
|
1142
|
+
*/
|
|
1143
|
+
async alt(request) {
|
|
1144
|
+
return (await this.createAltTask(request)).wait();
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Start image alt text generation without waiting for completion.
|
|
1148
|
+
*
|
|
1149
|
+
* @param request - Image URL or local file
|
|
1150
|
+
* @returns A TaskAsync that can be polled for completion via `.wait()`
|
|
1151
|
+
*
|
|
1152
|
+
* @example
|
|
1153
|
+
* ```typescript
|
|
1154
|
+
* const taskAsync = await image.altAsync({ url: "https://..." });
|
|
1155
|
+
*
|
|
1156
|
+
* const result = await taskAsync.wait();
|
|
1157
|
+
* console.log(result.alt);
|
|
1158
|
+
* ```
|
|
1159
|
+
*/
|
|
1160
|
+
async altAsync(request) {
|
|
1161
|
+
return this.createAltTask(request);
|
|
1162
|
+
}
|
|
1163
|
+
async createAltTask(request) {
|
|
1164
|
+
const url = await this.resolveUrlOrFile(request);
|
|
1165
|
+
const data = (await this.client.post(ALT_IMAGE_PATH, { url })).data;
|
|
1166
|
+
return new TaskAsync(data.taskId, {
|
|
1167
|
+
client: this.client,
|
|
1168
|
+
resultFactory: (taskData) => ImageAltResult.fromTaskData(taskData)
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Review a single image with a multi-model quality panel.
|
|
1173
|
+
*
|
|
1174
|
+
* @param request - Image URL or local file, and optional review effort
|
|
1175
|
+
* @returns An ImageReviewResult with the score, summary, findings, and strengths
|
|
1176
|
+
*
|
|
1177
|
+
* @example
|
|
1178
|
+
* ```typescript
|
|
1179
|
+
* const result = await image.review({ url: "https://..." });
|
|
1180
|
+
* console.log(result.score); // 1–4, higher is better
|
|
1181
|
+
* console.log(result.findings);
|
|
1182
|
+
* ```
|
|
1183
|
+
*/
|
|
1184
|
+
async review(request) {
|
|
1185
|
+
return (await this.createReviewTask(request)).wait();
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Start an image quality review without waiting for completion.
|
|
1189
|
+
*
|
|
1190
|
+
* @param request - Image URL or local file, and optional review effort
|
|
1191
|
+
* @returns A TaskAsync that can be polled for completion via `.wait()`
|
|
1192
|
+
*/
|
|
1193
|
+
async reviewAsync(request) {
|
|
1194
|
+
return this.createReviewTask(request);
|
|
1195
|
+
}
|
|
1196
|
+
async createReviewTask(request) {
|
|
1197
|
+
const url = await this.resolveUrlOrFile(request);
|
|
1198
|
+
const { file: _, url: __, ...rest } = request;
|
|
1199
|
+
const data = (await this.client.post(REVIEW_IMAGE_PATH, {
|
|
1200
|
+
...rest,
|
|
1201
|
+
url
|
|
1202
|
+
})).data;
|
|
1203
|
+
return new TaskAsync(data.taskId, {
|
|
1204
|
+
client: this.client,
|
|
1205
|
+
resultFactory: (taskData) => ImageReviewResult.fromTaskData(taskData)
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Remove the background from a single image.
|
|
1210
|
+
*
|
|
1211
|
+
* Mynth picks the model. The result keeps the provider's format unless
|
|
1212
|
+
* `output.format` asks for `png` or `webp`.
|
|
1213
|
+
*
|
|
1214
|
+
* @param request - Image URL or local file, plus optional output, destination, webhook, and metadata
|
|
1215
|
+
* @returns An ImageRemoveBackgroundResult with the transparent image
|
|
1216
|
+
*
|
|
1217
|
+
* @example
|
|
1218
|
+
* ```typescript
|
|
1219
|
+
* const result = await image.removeBackground({ url: "https://..." });
|
|
1220
|
+
* console.log(result.image.url);
|
|
1221
|
+
* ```
|
|
1222
|
+
*/
|
|
1223
|
+
async removeBackground(request) {
|
|
1224
|
+
return (await this.createRemoveBackgroundTask(request)).wait();
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Start background removal without waiting for completion.
|
|
1228
|
+
*
|
|
1229
|
+
* @param request - Image URL or local file, plus optional output, destination, webhook, and metadata
|
|
1230
|
+
* @returns A TaskAsync that can be polled for completion via `.wait()`
|
|
1231
|
+
*
|
|
1232
|
+
* @example
|
|
1233
|
+
* ```typescript
|
|
1234
|
+
* const taskAsync = await image.removeBackgroundAsync({ url: "https://..." });
|
|
1235
|
+
*
|
|
1236
|
+
* return { id: taskAsync.id, access: taskAsync.access };
|
|
1237
|
+
* ```
|
|
1238
|
+
*/
|
|
1239
|
+
async removeBackgroundAsync(request) {
|
|
1240
|
+
return this.createRemoveBackgroundTask(request);
|
|
1241
|
+
}
|
|
1242
|
+
async createRemoveBackgroundTask(request) {
|
|
1243
|
+
const url = await this.resolveUrlOrFile(request);
|
|
1244
|
+
const { file: _, url: __, ...rest } = request;
|
|
1245
|
+
const data = (await this.client.post(REMOVE_BACKGROUND_IMAGE_PATH, {
|
|
1246
|
+
...rest,
|
|
1247
|
+
url,
|
|
1248
|
+
destination: request.destination ?? this.defaultDestination
|
|
1249
|
+
})).data;
|
|
1250
|
+
return new TaskAsync(data.taskId, {
|
|
1251
|
+
client: this.client,
|
|
1252
|
+
pat: data.access?.publicAccessToken,
|
|
1253
|
+
resultFactory: (taskData) => ImageRemoveBackgroundResult.fromTaskData(taskData)
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
/**
|
|
1258
|
+
* Client for interacting with the Mynth video generation API.
|
|
1259
|
+
*
|
|
1260
|
+
* Mirrors {@link MynthImage}: `generate()` waits, `generateAsync()` hands you a
|
|
1261
|
+
* pollable task, and local files passed in `inputs` are uploaded for you.
|
|
1262
|
+
* Video tasks run for minutes, so waits use a longer, slower polling profile.
|
|
1263
|
+
*
|
|
1264
|
+
* @example
|
|
1265
|
+
* ```typescript
|
|
1266
|
+
* const video = new MynthVideo({ apiKey: "mak_..." });
|
|
1267
|
+
*
|
|
1268
|
+
* const result = await video.generate({
|
|
1269
|
+
* model: "google/gemini-omni-flash-1.1",
|
|
1270
|
+
* prompt: "A cat surfing a wave at sunset",
|
|
1271
|
+
* duration: 8,
|
|
1272
|
+
* resolution: "1080p",
|
|
1273
|
+
* });
|
|
1274
|
+
*
|
|
1275
|
+
* console.log(result.urls); // ["https://..."]
|
|
1276
|
+
* ```
|
|
1277
|
+
*/
|
|
1278
|
+
var MynthVideo = class {
|
|
1279
|
+
client;
|
|
1280
|
+
/**
|
|
1281
|
+
* Creates a new MynthVideo client instance.
|
|
1282
|
+
*
|
|
1283
|
+
* @param options - Configuration options
|
|
1284
|
+
* @param options.apiKey - Your API key (defaults to MYNTH_API_KEY env var)
|
|
1285
|
+
* @param options.baseUrl - Custom API base URL
|
|
1286
|
+
* @throws {Error} If no API key is provided and MYNTH_API_KEY is not set
|
|
1287
|
+
*/
|
|
1288
|
+
constructor(options = {}) {
|
|
1289
|
+
const apiKey = options.apiKey ?? getApiKeyFromEnv();
|
|
1290
|
+
if (!apiKey) throw new Error(`Mynth API key is required. Either pass it as an option or set the ${API_KEY_ENV_VAR} environment variable.`);
|
|
1291
|
+
this.client = new MynthClient({
|
|
1292
|
+
apiKey,
|
|
1293
|
+
baseUrl: options.baseUrl
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Generate a video from a text prompt, optionally guided by input images.
|
|
1298
|
+
*
|
|
1299
|
+
* Waits for the task to complete. Video generation is slow: this poll can
|
|
1300
|
+
* legitimately run for many minutes. Use `generateAsync()` (or a webhook)
|
|
1301
|
+
* when you cannot hold a request open that long.
|
|
1302
|
+
*
|
|
1303
|
+
* @param request - Video generation request parameters
|
|
1304
|
+
* @returns A completed VideoGenerationResult
|
|
1305
|
+
*
|
|
1306
|
+
* @example
|
|
1307
|
+
* ```typescript
|
|
1308
|
+
* const result = await video.generate({
|
|
1309
|
+
* model: "bytedance/seedance-2.0-mini",
|
|
1310
|
+
* prompt: "A drone shot over a misty forest at dawn",
|
|
1311
|
+
* });
|
|
1312
|
+
* console.log(result.urls);
|
|
1313
|
+
* ```
|
|
1314
|
+
*/
|
|
1315
|
+
async generate(request) {
|
|
1316
|
+
return (await this.createGenerationTask(request)).wait();
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Start video generation without waiting for completion.
|
|
1320
|
+
*
|
|
1321
|
+
* The preferred entry point for server code: hand `taskAsync.id` and
|
|
1322
|
+
* `taskAsync.access.publicAccessToken` to the browser, or register a webhook,
|
|
1323
|
+
* instead of holding a connection open for the length of a render.
|
|
1324
|
+
*
|
|
1325
|
+
* @param request - Video generation request parameters
|
|
1326
|
+
* @returns A TaskAsync that can be polled for completion via `.wait()`
|
|
1327
|
+
*
|
|
1328
|
+
* @example
|
|
1329
|
+
* ```typescript
|
|
1330
|
+
* const taskAsync = await video.generateAsync({
|
|
1331
|
+
* model: "prunaai/p-video",
|
|
1332
|
+
* prompt: "A neon city street in the rain",
|
|
1333
|
+
* });
|
|
1334
|
+
*
|
|
1335
|
+
* return { id: taskAsync.id, access: taskAsync.access };
|
|
1336
|
+
* ```
|
|
1337
|
+
*/
|
|
1338
|
+
async generateAsync(request) {
|
|
1339
|
+
return this.createGenerationTask(request);
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Upload one or more images to Mynth temporary input storage.
|
|
1343
|
+
*
|
|
1344
|
+
* Video inputs are images, so this is the same storage `image.upload()` uses.
|
|
1345
|
+
* Passing files straight to `generate()` uploads them for you; call this
|
|
1346
|
+
* directly only when you want to reuse the URLs across several requests.
|
|
1347
|
+
*
|
|
1348
|
+
* @param input - Image input or inputs to upload
|
|
1349
|
+
* @returns Uploaded image URLs that can be passed to generation `inputs`
|
|
1350
|
+
*/
|
|
1351
|
+
async upload(input) {
|
|
1352
|
+
return uploadImages(this.client, input);
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Price a video generation request without generating anything.
|
|
1356
|
+
*
|
|
1357
|
+
* The request is validated exactly as `generate()` would validate it, so an
|
|
1358
|
+
* unsupported duration, resolution or input combination throws here too —
|
|
1359
|
+
* making this a cheap pre-flight check as well as a cost lookup. Because
|
|
1360
|
+
* video pins a concrete model, the returned estimate is exact.
|
|
1361
|
+
*
|
|
1362
|
+
* @param request - The same request you would pass to `generate()`
|
|
1363
|
+
* @returns The estimated cost in USD
|
|
1364
|
+
*
|
|
1365
|
+
* @example
|
|
1366
|
+
* ```typescript
|
|
1367
|
+
* const { estimatedCost } = await video.estimate({
|
|
1368
|
+
* model: "google/gemini-omni-flash-1.1",
|
|
1369
|
+
* prompt: "A timelapse of clouds over a canyon",
|
|
1370
|
+
* duration: 10,
|
|
1371
|
+
* resolution: "4k",
|
|
1372
|
+
* });
|
|
1373
|
+
* ```
|
|
1374
|
+
*/
|
|
1375
|
+
async estimate(request) {
|
|
1376
|
+
return (await this.client.post(ESTIMATE_VIDEO_PATH, await this.toRequestBody(request))).data;
|
|
1377
|
+
}
|
|
1378
|
+
async toRequestBody(request) {
|
|
1379
|
+
const { inputs: clientInputs, ...rest } = request;
|
|
1380
|
+
const inputs = await resolveInputs(this.client, clientInputs);
|
|
1381
|
+
return inputs ? {
|
|
1382
|
+
...rest,
|
|
1383
|
+
inputs
|
|
1384
|
+
} : rest;
|
|
1385
|
+
}
|
|
1386
|
+
async createGenerationTask(request) {
|
|
1387
|
+
const data = (await this.client.post(GENERATE_VIDEO_PATH, await this.toRequestBody(request))).data;
|
|
1388
|
+
return new TaskAsync(data.taskId, {
|
|
1389
|
+
client: this.client,
|
|
1390
|
+
pat: data.access?.publicAccessToken,
|
|
1391
|
+
polling: VIDEO_POLLING,
|
|
1392
|
+
resultFactory: (taskData) => new VideoGenerationResult(taskData)
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
/**
|
|
1397
|
+
* Client for interacting with the public Mynth model catalog.
|
|
1398
|
+
*/
|
|
1399
|
+
var MynthModels = class {
|
|
1400
|
+
client;
|
|
1401
|
+
/**
|
|
1402
|
+
* Creates a new MynthModels client instance.
|
|
1403
|
+
*
|
|
1404
|
+
* @param options - Configuration options
|
|
1405
|
+
* @param options.baseUrl - Custom API base URL
|
|
1406
|
+
*/
|
|
1407
|
+
constructor(options = {}) {
|
|
1408
|
+
this.client = new MynthClient({ baseUrl: options.baseUrl });
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* List available image generation models.
|
|
1412
|
+
*
|
|
1413
|
+
* This endpoint is public and does not require a Mynth API key.
|
|
1414
|
+
*
|
|
1415
|
+
* @returns Available image and video models with display names, served modes, and pricing
|
|
1416
|
+
*
|
|
1417
|
+
* @example
|
|
1418
|
+
* ```typescript
|
|
1419
|
+
* const models = await mynth.models.list();
|
|
1420
|
+
* console.log(models[0]?.id);
|
|
1421
|
+
* ```
|
|
1422
|
+
*/
|
|
1423
|
+
async list() {
|
|
1424
|
+
return (await this.client.getOrThrow(MODELS_PATH, { auth: false })).data;
|
|
1425
|
+
}
|
|
1426
|
+
};
|
|
1427
|
+
/**
|
|
1428
|
+
* Bundled Mynth client providing access to all media type clients.
|
|
1429
|
+
*
|
|
1430
|
+
* @example
|
|
1431
|
+
* ```typescript
|
|
1432
|
+
* const mynth = new Mynth({ apiKey: "mak_..." });
|
|
1433
|
+
*
|
|
1434
|
+
* // Generate an image
|
|
1435
|
+
* const result = await mynth.image.generate({
|
|
1436
|
+
* prompt: "A beautiful sunset over mountains",
|
|
1437
|
+
* });
|
|
1438
|
+
* ```
|
|
1439
|
+
*/
|
|
1440
|
+
var Mynth = class {
|
|
1441
|
+
/** Public model catalog client */
|
|
1442
|
+
models;
|
|
1443
|
+
options;
|
|
1444
|
+
imageClient;
|
|
1445
|
+
videoClient;
|
|
1446
|
+
/**
|
|
1447
|
+
* Creates a new Mynth client instance.
|
|
1448
|
+
*
|
|
1449
|
+
* @param options - Configuration options
|
|
1450
|
+
* @param options.apiKey - Your API key (defaults to MYNTH_API_KEY env var)
|
|
1451
|
+
* @param options.baseUrl - Custom API base URL
|
|
1452
|
+
*/
|
|
1453
|
+
constructor(options = {}) {
|
|
1454
|
+
this.options = options;
|
|
1455
|
+
this.models = new MynthModels({ baseUrl: options.baseUrl });
|
|
1456
|
+
}
|
|
1457
|
+
/** Image generation and analysis client */
|
|
1458
|
+
get image() {
|
|
1459
|
+
this.imageClient ??= new MynthImage(this.options);
|
|
1460
|
+
return this.imageClient;
|
|
1461
|
+
}
|
|
1462
|
+
/** Video generation client */
|
|
1463
|
+
get video() {
|
|
1464
|
+
this.videoClient ??= new MynthVideo(this.options);
|
|
1465
|
+
return this.videoClient;
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
//#endregion
|
|
1469
|
+
export { AVAILABLE_MODELS, AVAILABLE_VIDEO_MODELS, ImageAltResult, ImageGenerationResult, ImageRateResult, ImageRemoveBackgroundResult, ImageReviewResult, Mynth, Mynth as default, MynthAPIError, MynthImage, MynthModels, MynthVideo, TaskAsync, TaskAsyncFetchError, TaskAsyncTaskFailedError, TaskAsyncTaskFetchError, TaskAsyncTimeoutError, TaskAsyncUnauthorizedError, VideoGenerationResult };
|