Skip to main content
const prompt = await tracia.prompts.get(slug);
Retrieve a single prompt by its slug, including the full content of its current version.

Parameters

ParameterTypeRequiredDescription
slugstringYesThe prompt slug

Response

interface Prompt {
  id: string;
  slug: string;
  name: string;
  description: string | null;
  provider: 'OPENAI' | 'ANTHROPIC' | 'GOOGLE' | null;
  model: string | null;
  temperature: number | null;
  topP: number | null;
  maxOutputTokens: number | null;
  currentVersion: number;
  content: PromptMessage[];
  variables: string[];
  createdAt: string;
  updatedAt: string;
}

interface PromptMessage {
  id: string;
  role: 'system' | 'user' | 'assistant';
  content: string;
}

Examples

Basic Usage

const prompt = await tracia.prompts.get('welcome-email');

console.log(prompt.name);        // "Welcome Email"
console.log(prompt.currentVersion); // 3

Accessing Content

const prompt = await tracia.prompts.get('welcome-email');

prompt.content.forEach(message => {
  console.log(`[${message.role}]: ${message.content}`);
});
// [system]: You are a helpful assistant...
// [user]: Write a welcome email for {{name}}...

Checking Variables

const prompt = await tracia.prompts.get('welcome-email');

console.log('Required variables:', prompt.variables);
// ['name', 'product']

// Validate before running
const myVariables = { name: 'Alice' };
const missing = prompt.variables.filter(v => !(v in myVariables));

if (missing.length > 0) {
  console.error(`Missing variables: ${missing.join(', ')}`);
}

Error Handling

import { TraciaError, TraciaErrorCode } from 'tracia';

try {
  const prompt = await tracia.prompts.get('welcome-email');
} catch (error) {
  if (error instanceof TraciaError) {
    if (error.code === TraciaErrorCode.NOT_FOUND) {
      console.error('Prompt does not exist');
    }
  }
}