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:
import { createNosanaClient } from '@nosana/kit';
const client = createNosanaClient({
api: {
apiKey: process.env.NOSANA_API_KEY as string,
},
});For the API, set your API key:
export NOSANA_API_KEY="nos_xxx_your_api_key"List Deployments
const deployments = await client.deployments.list();Get a Deployment
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:
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
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');
await deployment.updateReplicas(3);Update Schedule (SCHEDULED Strategy Only)
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');
await deployment.updateSchedule('0 0 * * *'); // daily at midnightNote: The schedule only applies to deployments using the
SCHEDULEDstrategy.
For cron syntax examples, see Deployment Strategies.
Update Timeout
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');
await deployment.updateTimeout(120); // minutesStart a Deployment
Start an existing deployment that is in a draft or stopped state:
const deployment = await client.deployments.get('YOUR_DEPLOYMENT_ID');
await deployment.start();Stop a Deployment
Stop a running deployment:
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:
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.
// 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.