0.0.4 β€’ Published 1 month ago

@styley-ts/ts-sdk v0.0.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 month ago

Styley TypeScript SDK

πŸ“š Table of Contents

  1. Install Node.js & npm
  2. Setup Project Workspace
  3. Install TypeScript & SDK Dependencies
  4. Environment Variables
  5. Deployments
  6. Models
  7. Summary of Available Methods

Install Node.js & npm

Install Using Official Installer (Recommended)

  1. Go to the Node.js official download page:

    πŸ‘‰ https://nodejs.org/

  2. 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.
  3. 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

  1. Create a project directory:
mkdir typescript-sdk-project
cd typescript-sdk-project
  1. 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

  1. Install TypeScript globally (optional, but useful for running tsc command globally):

npm install -g typescript
  1. Install Styley TypeScript SDK and other required dependencies locally in your project:
npm install --save-dev typescript
npm install --save @styley-ts/ts-sdk
  1. 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
  • 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

ClassMethodDescription
Deploymentscreate(payload)Create a new deployment.
Deploymentslist()List all deployments.
DeploymentsgetJob(jobID)Get the status of a deployment job.
Modelslist()List all available models.
ModelsgetById(id)Get model details by model ID.
ModelsgetByName(name)Get model details by model name.
0.0.4

1 month ago

0.0.3

3 months ago

0.0.2

3 months ago

0.0.1

3 months ago

0.0.0

3 months ago