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/updateRequest Parameters
Section titled “Request Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
promptId | string | Yes | The ID of the prompt (path parameter) |
versionId | string | Yes | The ID of the version to update |
updateData | object | Yes | Object containing fields to update |
Update Data Fields
Section titled “Update Data Fields”| Field | Type | Required | Description |
|---|---|---|---|
output | string | No | Updated prompt output text |
label | string | No | Updated descriptive label for version |
Request Body
Section titled “Request Body”{ "versionId": "string", // required "updateData": { "output": "string", // optional "label": "string" // optional }}Headers
Section titled “Headers”| Header | Value |
|---|---|
Content-Type | application/json |
Authorization | Bearer your-api-key |
x-user-id | your-user-id |
Response
Section titled “Response”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..."}What Can Be Updated
Section titled “What Can Be Updated”Output Text
Section titled “Output Text”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
What Cannot Be Updated
Section titled “What Cannot Be Updated”- ❌ Input template (create new version instead)
- ❌ Version number (automatically managed)
- ❌ Creation timestamp (historical record)
- ❌ Parent version ID (lineage is fixed)
Use Cases
Section titled “Use Cases”Fix Minor Issues
Section titled “Fix Minor Issues”// Fix a typo in the outputawait promptTK.updatePromptVersion(promptId, versionId, { output: correctedText});Update Label for Clarity
Section titled “Update Label for Clarity”// Add descriptive label after testingawait promptTK.updatePromptVersion(promptId, versionId, { label: "Production-ready - tested with 100 samples"});Refine AI Output
Section titled “Refine AI Output”// Manual improvements to AI-generated textconst 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 Fields
Section titled “Update Both Fields”// Update both output and labelawait promptTK.updatePromptVersion(promptId, versionId, { output: "Improved prompt text with better formatting", label: "v2.1 - Formatting improvements"});Important Notes
Section titled “Important Notes”- 📝 Metadata Only: Updates version metadata, not the input template
- 🔄 Updates Timestamp: Sets
updatedAtto 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
When to Update vs. Create New Version
Section titled “When to Update vs. Create New Version”Update Existing Version When:
Section titled “Update Existing Version When:”- ✅ Making minor corrections (typos, formatting)
- ✅ Adding or updating labels
- ✅ Manual refinements to output text
- ✅ Changes don’t affect version lineage
Create New Version When:
Section titled “Create New Version When:”- ✅ Changing input template
- ✅ Testing different parameters
- ✅ Significant changes to output
- ✅ Want to track changes in version history
- ✅ Need AI regeneration with new inputs
Best Practices
Section titled “Best Practices”- Use Labels Descriptively: Help identify what each version does
- Update Non-Active First: Test updates on non-active versions
- Document Changes: Use labels to note what was updated
- Minor Edits Only: For major changes, create a new version
- Preserve History: Don’t update if you want to track changes
Complete Example
Section titled “Complete Example”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;}Workflow with Version Update
Section titled “Workflow with Version Update”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");}Related Endpoints
Section titled “Related Endpoints”- Create Prompt Version - Create a new version
- List Prompt Versions - View all versions
- Activate Version - Set version as active
- Delete Version - Remove a version
- Update Prompt - Update the active version’s output