Core Methods

Complete reference for LaikaTest SDK methods

getPrompt()

Retrieve a prompt template by name.

const prompt = await client.getPrompt('my-prompt-name');// Compile the prompt with variablesconst compiledPrompt = prompt.compile({  username: 'Alice',  role: 'developer'});// With optionsconst prompt = await client.getPrompt('my-prompt-name', {  versionId: '10',        // or 'v10'  bypassCache: true       // Skip cache for this request});

Parameters:

  • promptName (string) - The name of the prompt template
  • options (optional):
    • versionId / version_id - Specific version to fetch (numeric or 'v' prefixed)
    • bypassCache / bypass_cache - Skip cache for this request

getExperimentPrompt()

Evaluate an experiment and retrieve the assigned prompt variant. The returned prompt includes embedded experiment metadata for tracking and score submission.

TypeScript
const prompt = await client.getExperimentPrompt(  'experiment-name',  {    user_id: 'user123',    session_id: 'session456',    custom_param: 'value'  });// Compile the prompt with variablesconst compiledPrompt = prompt.compile({ username: 'Alice' });// Submit scores using the prompt object (metadata is embedded)await client.pushScore(prompt, {  scores: [{ name: 'rating', type: 'int', value: 5 }],  userId: 'user123'});

Parameters:

  • experimentName (string) - The experiment identifier
  • variables (object) - Context variables for experiment evaluation

Returns: A Prompt instance with experiment metadata embedded.

pushScore()

Submit performance metrics and scores for experiment tracking and analytics. Pass the prompt object from getExperimentPrompt() to automatically include experiment metadata.

TypeScript
// Get experiment promptconst prompt = await client.getExperimentPrompt('my-experiment', {  userId: 'user123'});// Submit scores with prompt object (recommended)await client.pushScore(prompt, {  scores: [    { name: 'rating', type: 'int', value: 5 },    { name: 'helpful', type: 'bool', value: true },    { name: 'comment', type: 'string', value: 'Great response!' }  ],  sessionId: 'session-456',  // At least one of sessionId or userId required  userId: 'user-123'});

Parameters:

  • prompt (Prompt object, required) - The prompt object returned from getExperimentPrompt()
  • options (object, required):
    • scores (array, required) - Array of score objects:
      • name - Metric name (e.g., 'rating', 'helpful')
      • type - Data type: 'int', 'bool', or 'string'
      • value - Metric value matching the specified type
    • sessionId (string, conditional) - Session identifier for grouping interactions. At least one of sessionId or userId must be provided.
    • userId (string, conditional) - User identifier for tracking individual users. At least one of sessionId or userId must be provided.

Auto-generated fields: The SDK automatically generates sdkEventId (unique event identifier) and clientVersion (SDK version). The source is automatically set to 'sdk'.

prompt.compile()

Compile a prompt template with variable substitution. Returns the compiled content as a string.

const prompt = await client.getPrompt('greeting');const compiled = prompt.compile({  name: 'Alice',  role: 'developer'});console.log(compiled); // Compiled prompt string

client.destroy()

Clean up resources and close connections.

try {  const prompt = await client.getPrompt('my-prompt');  // Use prompt...} finally {  client.destroy();}

Next Steps