Skip to content

Update Prompt Version

The updatePromptVersion endpoint allows you to update the metadata of a specific version, including the output text and descriptive label. This is useful for making minor edits without creating a new version.

import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({
userId: "your-user-id",
apiKey: "your-api-key",
});
async function updateVersion() {
const promptId = "your-prompt-id";
const versionId = "version-id-to-update";
const updateData = {
output: "Updated prompt text",
label: "Updated label"
};
try {
const response = await promptTK.updatePromptVersion(promptId, versionId, updateData);
console.log("Version updated:", response);
} catch (error) {
console.error("Error updating version:", error);
}
}
updateVersion();

Expected Output:

{
success: true,
message: 'Prompt version updated successfully',
data: {
versionId: 'version-id',
versionNumber: 2,
input: { /* input template */ },
output: 'Updated prompt text',
label: 'Updated label',
updatedAt: 1234567900,
// ... other fields
}
}

The updatePromptVersion function makes a request to the following endpoint:

PUT /v1/prompts/:promptId/version/update
ParameterTypeRequiredDescription
promptIdstringYesThe ID of the prompt (path parameter)
versionIdstringYesThe ID of the version to update
updateDataobjectYesObject containing fields to update
FieldTypeRequiredDescription
outputstringNoUpdated prompt output text
labelstringNoUpdated descriptive label for version
{
"versionId": "string", // required
"updateData": {
"output": "string", // optional
"label": "string" // optional
}
}
HeaderValue
Content-Typeapplication/json
AuthorizationBearer your-api-key
x-user-idyour-user-id

On success (200 OK):

{
"success": true,
"message": "Prompt version updated successfully",
"data": {
"versionId": "version-id",
"versionNumber": 2,
"input": { /* input template */ },
"output": "Updated text",
"label": "Updated label",
"createdAt": 1234567880,
"updatedAt": 1234567900,
"createdBy": "user-id",
"source": "api",
"parentVersionId": "parent-version-id"
}
}

On error, you may receive:

{
"success": false,
"message": "User ID is required"
}

or

{
"success": false,
"message": "Prompt ID, Version ID, and update data are required"
}

or

{
"success": false,
"message": "Failed to update prompt version",
"error": "...error message..."
}

The generated prompt text can be updated for:

  • Minor Corrections: Fix typos or formatting
  • Manual Refinement: Improve AI-generated output
  • Localization: Translate or adapt for different audiences

The descriptive label can be updated for:

  • Better Identification: Add meaningful descriptions
  • Version Tracking: Note what changes were made
  • Organization: Tag versions for easy filtering
  • ❌ Input template (create new version instead)
  • ❌ Version number (automatically managed)
  • ❌ Creation timestamp (historical record)
  • ❌ Parent version ID (lineage is fixed)
// Fix a typo in the output
await promptTK.updatePromptVersion(promptId, versionId, {
output: correctedText
});
// Add descriptive label after testing
await promptTK.updatePromptVersion(promptId, versionId, {
label: "Production-ready - tested with 100 samples"
});
// Manual improvements to AI-generated text
const versions = await promptTK.listPromptVersions(promptId);
const latestVersion = versions.data[0];
const refinedOutput = manuallyRefine(latestVersion.output);
await promptTK.updatePromptVersion(promptId, latestVersion.versionId, {
output: refinedOutput,
label: "Manually refined"
});
// Update both output and label
await promptTK.updatePromptVersion(promptId, versionId, {
output: "Improved prompt text with better formatting",
label: "v2.1 - Formatting improvements"
});
  • 📝 Metadata Only: Updates version metadata, not the input template
  • 🔄 Updates Timestamp: Sets updatedAt to current time
  • 🎯 Active Version: Can update the currently active version
  • 💾 Immediate Effect: If updating active version, changes apply immediately
  • 🚫 No Re-generation: Does not regenerate with AI
  • ✅ Making minor corrections (typos, formatting)
  • ✅ Adding or updating labels
  • ✅ Manual refinements to output text
  • ✅ Changes don’t affect version lineage
  • ✅ Changing input template
  • ✅ Testing different parameters
  • ✅ Significant changes to output
  • ✅ Want to track changes in version history
  • ✅ Need AI regeneration with new inputs
  1. Use Labels Descriptively: Help identify what each version does
  2. Update Non-Active First: Test updates on non-active versions
  3. Document Changes: Use labels to note what was updated
  4. Minor Edits Only: For major changes, create a new version
  5. Preserve History: Don’t update if you want to track changes
import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({
userId: "your-user-id",
apiKey: "your-api-key",
});
async function refineVersion(promptId, versionId) {
// 1. Get current version
const versions = await promptTK.listPromptVersions(promptId);
const version = versions.data.find(v => v.versionId === versionId);
console.log("Original output:", version.output.substring(0, 100));
console.log("Original label:", version.label || "No label");
// 2. Make improvements
const improvedOutput = version.output
.replace(/\n\n+/g, '\n\n') // Fix spacing
.trim(); // Remove extra whitespace
// 3. Update the version
const updated = await promptTK.updatePromptVersion(promptId, versionId, {
output: improvedOutput,
label: `${version.label || 'Version'} - Formatting fixed`
});
console.log("Updated successfully!");
console.log("New label:", updated.data.label);
return updated;
}
async function createAndRefineVersion(promptId, input) {
// 1. Create initial version with AI
const newVersion = await promptTK.createPromptVersion(
promptId,
input,
"api",
"Initial draft"
);
console.log("Created version:", newVersion.data.versionId);
// 2. Review AI output
const aiOutput = newVersion.data.output;
console.log("AI generated:", aiOutput.substring(0, 100));
// 3. Make manual improvements
const refinedOutput = `${aiOutput}\n\nNote: This prompt has been manually refined.`;
// 4. Update with refinements
await promptTK.updatePromptVersion(
promptId,
newVersion.data.versionId,
{
output: refinedOutput,
label: "Initial draft - manually refined"
}
);
console.log("Version refined and ready for testing");
}