@styley-ts/ts-sdk v0.0.4
Styley TypeScript SDK
π Table of Contents
- Install Node.js & npm
- Setup Project Workspace
- Install TypeScript & SDK Dependencies
- Environment Variables
- Deployments
- Models
- Summary of Available Methods
Install Node.js & npm
Install Using Official Installer (Recommended)
Go to the Node.js official download page:
π https://nodejs.org/
Download the installer for your operating system:
- Windows: Download the
.msi
file. - MacOS: Download the
.pkg
file. - Linux: Use the pre-built binary or use the package manager for your OS.
- Windows: Download the
Run the installer and follow the instructions.
Verify Installation Check if Node.js and npm are installed and running correctly.
node -v # Check Node.js version
npm -v # Check npm version
Expected output:
v20.5.1 # Example node version
8.5.0 # Example npm version
If you see "command not found", double-check that Node.js is installed and is in your PATH.
Setup Project Workspace
- Create a project directory:
mkdir typescript-sdk-project
cd typescript-sdk-project
- Initialize a new npm project (this creates package.json):
npm init -y
This will create a package.json
file with default values.
Install TypeScript & SDK Dependencies
Install TypeScript globally (optional, but useful for running
tsc
command globally):
npm install -g typescript
- Install Styley TypeScript SDK and other required dependencies locally in your project:
npm install --save-dev typescript
npm install --save @styley-ts/ts-sdk
- Initialize TypeScript configuration:
npx tsc --init
This creates a tsconfig.json
file in the root of your project, which configures how TypeScript compiles your code.
To run the TypeScript SDK, youβll need a file with TypeScript code.
Create a file called index.ts
in your project directory.
TypeScript Compatibility
This SDK is compatible with TypeScript versions 4.0 and above. Please ensure that your project uses a compatible TypeScript version to avoid any issues.
Environment Variables
To authenticate API requests, you must set the following environment variables in your system.
export X_STYLEY_KEY=***************************
Deployments
π€ Create Deployment
This method creates a new deployment using the specified model ID, name, and arguments.
import { Styley } from "@styley-ts/ts-sdk";
const styley = new Styley();
async function main() {
const deployment = await styley.deployments.create({
model_id: "fc5525a1-d073-4ee2-95f7-a6b9388aab94",
name: "Virtual Staging Fast",
args: {
image:
"https://cdn.mediamagic.dev/media/c2310708-5b9d-11ef-b10b-30d042e69440.jpg",
remove_existing_furniture: "off",
room_type: "living",
style: "modern",
wait_for_completion: "false",
},
});
console.log("deployment: ", deployment);
}
main().catch(console.error);
With Additional Parameters:
output_format (str, optional): Output format for the result.
- Images:
png
,jpg
,jpeg
,gif
,bmp
,tiff
,webp
,ico
- Videos:
mp4
,webm
,mkv
,mov
,avi
- Images:
output_width (int, optional): Output image width in pixels (positive integer)
- output_height (int, optional): Output image height in pixels (positive integer)
Note: For image resizing, both width and height must be specified together. If only one dimension is provided, the original image size will be maintained.
import { Styley } from "@styley-ts/ts-sdk";
const styley = new Styley();
async function main() {
const deployment = await styley.deployments.create({
model_id: "fc5525a1-d073-4ee2-95f7-a6b9388aab94",
name: "Virtual Staging Fast",
args: {
image:
"https://cdn.mediamagic.dev/media/c2310708-5b9d-11ef-b10b-30d042e69440.jpg",
remove_existing_furniture: "off",
room_type: "living",
style: "modern",
wait_for_completion: "false",
},
output_format: "png",
output_width: 1024,
output_height: 1024,
synchronous: false,
});
console.log("deployment: ", deployment);
}
main().catch(console.error);
π Get Deployment Job
Get the status of a deployment job using its job ID.
import { Styley } from '@styley-ts/ts-sdk';
const styley = new Styley();
async function main() {
//Change the "job_id" placeholder with actual jobID from the deployment response
const jobStatus = await styley.deployments.getJob("<job_id>");
console.log("jobStatus: ", jobStatus);
}
main().catch(console.error);
π List Deployments
Retrieve a list of all deployments.
import { Styley } from '@styley-ts/ts-sdk';
const styley = new Styley();
async function main() {
const deployments = await styley.deployments.list();
console.log("deployments: ", deployments);
}
main().catch(console.error);
Models
π List Models
Retrieve a list of all models available for deployments.
import { Styley } from '@styley-ts/ts-sdk';
const styley = new Styley();
async function main() {
const models = await styley.models.list();
console.log("models: ", models);
}
main().catch(console.error);
π Get Model By ID
Fetch a specific modelβs details using its model ID.
import { Styley } from '@styley-ts/ts-sdk';
const styley = new Styley();
async function main() {
const model = await styley.models.getById("<model_id>");
console.log("model: ", model);
}
main().catch(console.error);
π Get Model By Name
Fetch model details using its name.
import { Styley } from '@styley-ts/ts-sdk';
const styley = new Styley();
async function main() {
const model = await styley.models.getByName("<model-name>");
console.log("model: ", model);
}
main().catch(console.error);
Summary of Available Methods
Class | Method | Description |
---|---|---|
Deployments | create(payload) | Create a new deployment. |
Deployments | list() | List all deployments. |
Deployments | getJob(jobID) | Get the status of a deployment job. |
Models | list() | List all available models. |
Models | getById(id) | Get model details by model ID. |
Models | getByName(name) | Get model details by model name. |