Skip to main content

Delete Model

Removes a specific AI model from your local Ollama server to free up disk space. This is useful for managing storage and removing models you no longer need.

warning

This action is permanent and cannot be undone. The model will need to be pulled again if you want to use it later.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Client ID - The Client ID from the Connect node. Optional if Host URL is provided.
  • Model - The name of the model to delete (e.g., llama3, mistral:latest, codellama:7b).

Output

  • Result - A status message indicating whether the deletion was successful or failed.

Options

  • Host URL - Ollama server URL (optional). Use this instead of Client ID for direct connection. Example: http://localhost:11434

How It Works

The Delete Model node:

  1. Connects to the Ollama server (via Client ID or Host URL)
  2. Sends a delete request for the specified model
  3. Ollama removes the model files from disk
  4. Returns a success or failure message

Usage Examples

Example 1: Delete Single Model

Inputs:
- Model: "mistral:latest"

Output:
- Result: "Model deleted successfully"

Example 2: Clean Up Old Models

// First, list all models
// After List Models node
const models = msg.models;

// Find models older than 30 days
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);

const oldModels = models.filter(m => {
return new Date(m.modified_at) < thirtyDaysAgo;
});

// Delete each old model
for (const model of oldModels) {
// Use Delete Model node for each
msg.modelToDelete = model.name;
}

Example 3: Delete Duplicate Model Versions

// After List Models node
const models = msg.models;

// Group models by base name
const modelGroups = {};
models.forEach(m => {
const baseName = m.name.split(':')[0];
if (!modelGroups[baseName]) {
modelGroups[baseName] = [];
}
modelGroups[baseName].push(m);
});

// Keep only the latest version of each model
for (const baseName in modelGroups) {
const versions = modelGroups[baseName];
if (versions.length > 1) {
// Sort by modification date
versions.sort((a, b) =>
new Date(b.modified_at) - new Date(a.modified_at)
);

// Delete all except the first (latest)
for (let i = 1; i < versions.length; i++) {
msg.modelToDelete = versions[i].name;
// Use Delete Model node here
}
}
}

Example 4: Free Up Space by Deleting Large Models

// After List Models node
const models = msg.models;

// Find models larger than 10GB
const largeModels = models.filter(m => {
const sizeGB = m.size / (1024 ** 3);
return sizeGB > 10;
});

// Sort by size (largest first)
largeModels.sort((a, b) => b.size - a.size);

// Delete the largest ones
msg.modelsToDelete = largeModels.slice(0, 3); // Delete top 3 largest

Example 5: Conditional Deletion with Error Handling

Flow:
1. List Models
2. JS Node: Check if model exists
3. Delete Model (with Continue On Error = true)
4. JS Node: Check result

In JS Node after Delete:
if (msg.result.includes("successfully")) {
console.log("Model deleted:", msg.modelToDelete);
} else {
console.log("Failed to delete:", msg.result);
}

Requirements

  • Ollama service must be running
  • The specified model must exist locally
  • Valid Client ID from Connect node OR Host URL provided
  • Sufficient permissions to delete files

Common Use Cases

  • Freeing up disk space when storage is limited
  • Removing outdated model versions
  • Cleaning up test or experimental models
  • Managing model inventory in multi-user environments
  • Automating model lifecycle management
  • Preparing system for new model downloads
  • Removing duplicate model versions

Tips

Before Deleting

Always verify the model name before deletion:

// List models first
const models = msg.models;
const modelExists = models.find(m => m.name === msg.targetModel);

if (modelExists) {
console.log(`Found model: ${modelExists.name}`);
console.log(`Size: ${(modelExists.size / (1024 ** 3)).toFixed(2)} GB`);
// Proceed with deletion
} else {
console.log("Model not found, skipping deletion");
}

Disk Space Calculation

Calculate space that will be freed:

const models = msg.models;
const modelToDelete = models.find(m => m.name === msg.targetModel);

if (modelToDelete) {
const spaceGB = (modelToDelete.size / (1024 ** 3)).toFixed(2);
console.log(`Will free up ${spaceGB} GB`);
}

Safe Deletion Pattern

Use a confirmation step in production:

// Step 1: Identify models to delete
msg.pendingDeletion = ['old-model:v1', 'test-model'];

// Step 2: Review (manual or automated check)
// Step 3: Execute deletion only after confirmation
if (msg.deletionConfirmed) {
// Proceed with Delete Model nodes
}

Batch Deletion

When deleting multiple models, add delays:

const modelsToDelete = ['model1', 'model2', 'model3'];

for (let i = 0; i < modelsToDelete.length; i++) {
msg.modelToDelete = modelsToDelete[i];
// Delete Model node here
// Add 1 second delay between deletions
}

Error Handling

Common errors you might encounter:

  • "Failed to delete model" - Model doesn't exist or is in use
  • Model not found - The specified model name is incorrect or already deleted
  • Permission denied - Insufficient permissions to delete model files
  • Model in use - Model is currently being used by another process

Handling Errors Gracefully

// After Delete Model node with Continue On Error = true
if (msg.result.includes("Failed")) {
// Log the error but continue
console.error(`Could not delete ${msg.modelToDelete}: ${msg.result}`);
msg.deletionErrors = msg.deletionErrors || [];
msg.deletionErrors.push({
model: msg.modelToDelete,
error: msg.result
});
} else {
msg.deletedModels = msg.deletedModels || [];
msg.deletedModels.push(msg.modelToDelete);
}

Best Practices

  1. Always list models first - Verify what exists before deletion
  2. Calculate space savings - Know how much disk space you'll free
  3. Keep at least one model - Don't delete all models if you need Ollama functionality
  4. Use specific tags - Delete model:v1 instead of just model to avoid ambiguity
  5. Log deletions - Keep track of what was deleted and when
  6. Test in development - Verify your deletion logic before running in production
  7. Have a recovery plan - Know which models you can re-download if needed

Recovery

If you accidentally delete a model, you can re-download it:

Use Pull Model node with the model name to re-download
Example: Model = "llama3:latest"

Automation Example: Weekly Cleanup

// Weekly model cleanup automation
// Step 1: List all models
const models = msg.models;
const sevenDaysAgo = new Date();
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);

// Step 2: Identify candidates for deletion
const unusedModels = models.filter(m => {
// Models not modified in 7 days
const isOld = new Date(m.modified_at) < sevenDaysAgo;
// Exclude critical models
const isNotCritical = !['llama3:latest', 'mistral:latest'].includes(m.name);
return isOld && isNotCritical;
});

// Step 3: Calculate space to free
const totalSpace = unusedModels.reduce((sum, m) => sum + m.size, 0);
const spaceGB = (totalSpace / (1024 ** 3)).toFixed(2);

console.log(`Will free ${spaceGB} GB by deleting ${unusedModels.length} models`);

// Step 4: Delete each model
msg.modelsToDelete = unusedModels.map(m => m.name);