-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtext-to-image.js
46 lines (36 loc) · 1.39 KB
/
text-to-image.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const Shotstack = require('shotstack-sdk');
const defaultClient = Shotstack.ApiClient.instance;
const DeveloperKey = defaultClient.authentications['DeveloperKey'];
const api = new Shotstack.CreateApi();
const apiUrlBase = 'https://api.shotstack.io/create/';
let apiUrl = apiUrlBase + 'stage';
if (!process.env.SHOTSTACK_KEY) {
console.log('API Key is required. Set using: export SHOTSTACK_KEY=your_key_here');
process.exit(1);
}
if (process.env.SHOTSTACK_CREATE_HOST) {
apiUrl = process.env.SHOTSTACK_CREATE_HOST;
}
if (process.env.SHOTSTACK_ENV) {
apiUrl = apiUrlBase + process.env.SHOTSTACK_ENV;
}
defaultClient.basePath = apiUrl;
DeveloperKey.apiKey = process.env.SHOTSTACK_KEY;
const textToImage = new Shotstack.ShotstackTextToImageOptions;
textToImage
.setPrompt('A realistic photo of the planet Mars with a black outer space background')
.setWidth(1024)
.setHeight(1024);
const generatedAsset = new Shotstack.ShotstackGeneratedAsset;
generatedAsset
.setOptions(textToImage);
api.postGenerateAsset(generatedAsset).then((asset) => {
const status = asset.data.attributes.status;
const id = asset.data.id
console.log(`Request '${status}' with id: ${id}\n`);
console.log('>> Now check the progress by running:');
console.log(`>> node examples/create-api/status.js ${id}`);
}, (error) => {
console.error('Request failed: ', error);
process.exit(1);
});