Activate Prompt Version
The activatePromptVersion endpoint allows you to set a specific version as the active version of a prompt. The active version is what gets used in production and determines the current prompt output.
import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({ userId: "your-user-id", apiKey: "your-api-key",});
async function activateVersion() { const promptId = "your-prompt-id"; const versionId = "version-id-to-activate";
try { const response = await promptTK.activatePromptVersion(promptId, versionId); console.log("Version activated:", response); } catch (error) { console.error("Error activating version:", error); }}
activateVersion();Expected Output:
{ success: true, message: 'Prompt version activated successfully', data: { recordId: 'prompt-id', promptName: 'My Prompt', projectId: 'project-id', ownerId: 'user-id', createdAt: 1234567880, updatedAt: 1234567900, activeVersionId: 'version-id-to-activate', latestVersionNumber: 3 }}The activatePromptVersion function makes a request to the following endpoint:
POST /v1/prompts/:promptId/version/activateRequest 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 activate |
Request Body
Section titled “Request Body”{ "versionId": "string" // required}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 activated successfully", "data": { "recordId": "prompt-id", "promptName": "My Prompt", "projectId": "project-id", "ownerId": "user-id", "createdAt": 1234567880, "updatedAt": 1234567900, "activeVersionId": "version-id", "latestVersionNumber": 3 }}On error, you may receive:
{ "success": false, "message": "User ID is required"}or
{ "success": false, "message": "Prompt ID and Version ID are required"}or
{ "success": false, "message": "Failed to activate prompt version", "error": "...error message..."}What Activation Does
Section titled “What Activation Does”When you activate a version:
- Sets Active Version: Updates the prompt’s
activeVersionIdfield - Updates Timestamp: Sets the prompt’s
updatedAtto current time - Production Use: The active version is what applications use
- Rollback: Can activate previous versions to rollback changes
Use Cases
Section titled “Use Cases”Switch to Latest Version
Section titled “Switch to Latest Version”const versions = await promptTK.listPromptVersions(promptId);const latestVersion = versions.data[0]; // Versions are in descending orderawait promptTK.activatePromptVersion(promptId, latestVersion.versionId);console.log("Switched to latest version");Rollback to Previous Version
Section titled “Rollback to Previous Version”const versions = await promptTK.listPromptVersions(promptId);const previousVersion = versions.data[1]; // Second newestawait promptTK.activatePromptVersion(promptId, previousVersion.versionId);console.log("Rolled back to previous version");A/B Testing Workflow
Section titled “A/B Testing Workflow”// Create two test versionsconst versionA = await promptTK.createPromptVersion(promptId, inputA, "api", "Version A");const versionB = await promptTK.createPromptVersion(promptId, inputB, "api", "Version B");
// Test version Aawait promptTK.activatePromptVersion(promptId, versionA.data.versionId);// ... run tests with version A
// Switch to version Bawait promptTK.activatePromptVersion(promptId, versionB.data.versionId);// ... run tests with version B
// Activate the winnerawait promptTK.activatePromptVersion(promptId, winningVersionId);Safe Deployment
Section titled “Safe Deployment”// Activate new versionconst newVersionId = "new-version-id";const oldVersionId = prompt.activeVersionId; // Save current active
try { await promptTK.activatePromptVersion(promptId, newVersionId); console.log("New version activated");
// Monitor for issues... // If problems detected, rollback: // await promptTK.activatePromptVersion(promptId, oldVersionId);} catch (error) { console.error("Activation failed, staying on current version");}Important Notes
Section titled “Important Notes”- 🎯 One Active Version: Only one version can be active at a time
- 🔄 Instant Switch: Activation happens immediately
- 📝 No Data Loss: Previous active version remains available
- 🔙 Easy Rollback: Can activate any previous version anytime
- 🚀 Production Ready: Active version is used by all systems
Best Practices
Section titled “Best Practices”- Test Before Activating: Review version output before making it active
- Document Changes: Use version labels to track what each version does
- Save Current Active: Store current activeVersionId before switching
- Monitor After Activation: Watch for issues after activating new versions
- Use Version Labels: Identify versions by meaningful labels, not just numbers
Workflow Example
Section titled “Workflow Example”Complete workflow for creating and activating a new version:
import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({ userId: "your-user-id", apiKey: "your-api-key",});
async function deployNewVersion(promptId, newInput) { // 1. Get current state const prompt = await promptTK.fetchPromptById(promptId); const currentActiveId = prompt.data.activeVersionId;
console.log(`Current active version: ${currentActiveId}`);
// 2. Create new version const newVersion = await promptTK.createPromptVersion( promptId, newInput, "api", "Production v2.0" );
console.log(`New version created: ${newVersion.data.versionId}`);
// 3. Review the new version const versions = await promptTK.listPromptVersions(promptId); const createdVersion = versions.data.find(v => v.versionId === newVersion.data.versionId);
console.log("New version output preview:", createdVersion.output.substring(0, 100));
// 4. Activate the new version await promptTK.activatePromptVersion(promptId, newVersion.data.versionId);
console.log("✅ New version is now active!"); console.log(`Previous version ${currentActiveId} is still available for rollback`);
return { newVersionId: newVersion.data.versionId, previousVersionId: currentActiveId };}Related Endpoints
Section titled “Related Endpoints”- Create Prompt Version - Create a new version to activate
- List Prompt Versions - View all versions before activating
- Update Version - Modify version before activating
- Get Prompt by ID - Check current active version