Skip to content

Manage Deployments

Use the Nosana REST API or TypeScript SDK to list, inspect, stop, and archive deployments.

Prerequisites

  • API Key: See the API key guide.
  • Existing deployments: Created via the API, SDK, or dashboard.

All examples assume you have your API key set up. For the SDK, initialize the client:

ts
import { createNosanaClient } from '@nosana/kit';

const client = createNosanaClient({
  api: {
    apiKey: process.env.NOSANA_API_KEY as string,
  },
});

For the API, set your API key:

bash
export NOSANA_API_KEY="nos_xxx_your_api_key"

List Deployments

ts
const deployments = await client.deployments.list();

Get a Deployment

ts
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');

Update Job Definition (Create a Revision)

Create a new revision of the job definition for an existing deployment:

ts
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');

const revision = await deployment.createRevision({
  job_definition: {
    // New job definition fields go here
  },
});

The body should contain a job_definition matching the structure described in the job definition docs.

Update Replica Count

ts
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');
await deployment.updateReplicas(3);

Update Schedule (SCHEDULED Strategy Only)

ts
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');
await deployment.updateSchedule('0 0 * * *'); // daily at midnight

Note: The schedule only applies to deployments using the SCHEDULED strategy.
For cron syntax examples, see Deployment Strategies.

Update Timeout

ts
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');
await deployment.updateTimeout(120); // minutes

Start a Deployment

Start an existing deployment that is in a draft or stopped state:

ts
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');
await deployment.start();

Stop a Deployment

Stop a running deployment:

ts
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');
await deployment.stop();

The response will contain a status (for example "STOPPING") and an updated_at timestamp.

Archive a Deployment

Archive a deployment to remove it from your active list while keeping history:

ts
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');
await deployment.archive();

The response will include status: "ARCHIVED" when successful.

Pipe Multiple Deployment Operations (SDK Only)

The pipe function allows you to chain multiple actions on a deployment in a functional programming style. It can either create a new deployment or operate on an existing one.

ts
// Create and execute multiple actions in sequence
const deployment = await client.deployments.pipe(
  {
    name: 'My Application',
    market: '7AtiXMSH6R1jjBxrcYjehCkkSF7zvYWte63gwEDBcGHq',
    replicas: 3,
    timeout: 300,
    strategy: 'SIMPLE',
    job_definition: {},
  },
  async (deployment) => {
    console.log('Starting deployment');
    await deployment.start();
  },
  async (deployment) => {
    console.log('Updating replicas');
    await deployment.updateReplicas(5);
  },
);

// Or operate on an existing deployment
const deployment = await client.deployments.pipe(
  'existing-deployment-id',
  async (deployment) => {
    await deployment.start();
  },
  async (deployment) => {
    await deployment.stop();
  }
);

This example gets a deployment, updates its replica count and timeout, and then starts it in one composed call.

Full API Reference

For all deployment endpoints and fields, consult the API Swagger reference.