Skip to content

Create Prompt Version

The createPromptVersion endpoint allows you to create a new version of an existing prompt. This generates a new AI-powered prompt based on the input template and links it to the parent prompt with version tracking.

import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({
userId: "your-user-id",
apiKey: "your-api-key",
});
const versionInput = {
mainPrompt: "Write a story about a {animal} in the {location}.",
outputType: "plain text",
responseFormat: "plain text",
promptGoal: "Create an engaging narrative",
// ... other optional fields
};
async function createVersion() {
const promptId = "your-prompt-id";
const source = "api"; // optional: 'api', 'ui', 'tool-tab'
const label = "Version with new parameters"; // optional: descriptive label
const parentVersionId = "parent-version-id"; // optional: defaults to active version
try {
const response = await promptTK.createPromptVersion(
promptId,
versionInput,
source,
label,
parentVersionId
);
console.log("Version created:", response);
} catch (error) {
console.error("Error creating version:", error);
}
}
createVersion();

Expected Output:

{
success: true,
message: 'Prompt version created successfully',
data: {
versionId: 'new-version-id',
versionNumber: 2,
input: { /* input template */ },
output: 'Generated prompt text...',
createdAt: 1234567890,
updatedAt: 1234567890,
createdBy: 'user-id',
source: 'api',
label: 'Version with new parameters',
parentVersionId: 'parent-version-id'
}
}

The createPromptVersion function makes a request to the following endpoint:

POST /v1/prompts/:promptId/version/new
ParameterTypeRequiredDescription
promptIdstringYesThe ID of the prompt (path parameter)
inputobjectYesThe prompt input template
sourcestringNoSource of creation: ‘api’, ‘ui’, ‘tool-tab’
labelstringNoDescriptive label for the version
parentVersionIdstringNoParent version ID (defaults to active version)
{
"input": {
"mainPrompt": "string", // required
"endUserDescription": "string", // optional
"promptSenderDescription": "string", // optional
"relationship": "string", // optional
"mustHaves": "string", // optional
"contextRequirements": "string", // optional
"lengthRequirements": "string", // optional
"avoidElements": "string", // optional
"styleAndTone": ["string"], // optional
"examplePrompts": "string", // optional
"outputType": "string", // optional
"responseFormat": "string", // optional
"promptGoal": "string", // optional
"hallucinationControl": "string" // optional
},
"source": "string", // optional
"label": "string", // optional
"parentVersionId": "string" // optional
}

See the Prompt Input documentation for detailed information about input fields.

HeaderValue
Content-Typeapplication/json
AuthorizationBearer your-api-key
x-user-idyour-user-id

On success (200 OK):

{
"success": true,
"message": "Prompt version created successfully",
"data": {
"versionId": "string",
"versionNumber": 2,
"input": { /* input template */ },
"output": "Generated prompt text",
"createdAt": 1234567890,
"updatedAt": 1234567890,
"createdBy": "user-id",
"source": "api",
"label": "Version label",
"parentVersionId": "parent-version-id",
"inputTokens": 100,
"outputTokens": 200,
"ptkInputTokens": 50,
"ptkOutputTokens": 75
}
}

On error, you may receive:

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

or

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

or

{
"success": false,
"message": "Failed to create prompt version",
"error": "...error message..."
}
  • Each prompt starts with version 1
  • New versions increment automatically (1, 2, 3, etc.)
  • Version numbers are unique within a prompt
  • Each version (except version 1) has a parent version
  • If parentVersionId is not specified, the current active version becomes the parent
  • This creates a version tree showing the evolution of your prompt
  • Creating a new version does NOT automatically activate it
  • The previously active version remains active
  • Use Activate Version to switch to the new version
  • Iterative Improvement: Test different variations of your prompt
  • A/B Testing: Compare performance of different prompt formulations
  • Parameter Tuning: Adjust tone, length, or style requirements
  • Experimentation: Try different approaches without losing previous versions
  • Rollback Capability: Keep working versions while testing improvements
  • 🤖 AI Generation: This endpoint uses AI to generate the prompt output based on your input template
  • 💰 Token Usage: Tokens are consumed for AI generation (tracked in response)
  • 🔗 Versioning: Creates a new version linked to the parent prompt
  • 📊 Tracking: Usage data is recorded for analytics
  • 🎯 Active Version: The active version is what gets used in production; new versions must be activated manually
  1. Use Descriptive Labels: Help identify versions later with clear, descriptive labels
  2. Track Parent Versions: Maintain the version tree for better organization
  3. Test Before Activating: Create and review versions before making them active
  4. Document Changes: Use labels to note what changed between versions
  5. Monitor Token Usage: Keep track of token consumption for budgeting
import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({
userId: "your-user-id",
apiKey: "your-api-key",
});
const promptId = "your-prompt-id";
// Test version 1: More formal tone
const formalVersion = await promptTK.createPromptVersion(
promptId,
{
mainPrompt: "Compose a professional email about {topic}.",
styleAndTone: ["formal", "professional"],
lengthRequirements: "2-3 paragraphs"
},
"api",
"Formal tone test"
);
// Test version 2: More casual tone
const casualVersion = await promptTK.createPromptVersion(
promptId,
{
mainPrompt: "Write a friendly message about {topic}.",
styleAndTone: ["casual", "friendly"],
lengthRequirements: "2-3 paragraphs"
},
"api",
"Casual tone test",
formalVersion.data.versionId // Make formal version the parent
);
console.log("Created test versions for A/B testing");