SDK Reference

Complete reference for LaikaTest SDKs

Packages: @laikatest/js-client (JavaScript/TypeScript), laikatest-client (Python)
Features: Zero dependencies, intelligent caching, full type support

Python SDK Support: The Python SDK currently supports get_prompt(), prompt.compile(), and client.destroy() methods. Full experiment and score evaluation features are coming soon.

Security Warning: Never expose your API keys in client-side code or commit them to public repositories. Always store sensitive credentials in environment variables.

Getting Your API Token

Generating API Tokens

  1. Go to Dashboard → Settings → API Keys
  2. Click Create New API Key
  3. Give your key a descriptive name
  4. Select the project to associate with the key
  5. Copy the generated token (displayed only once)

Important: API tokens are shown only once. Store them securely immediately.

Environment Variables

Store your API key in environment variables for security:

Bash
# .envLAIKATEST_API_KEY=your_api_token_here

Base URL

Bash
https://api.laikatest.com

Authentication Methods

LaikaTest supports two authentication methods:

  • API Tokens: For external integrations and programmatic access (used by SDK)
  • JWT Tokens: For dashboard and session-based authentication

Access Control

Dashboard-Only (JWT Required)
  • • Project creation and modifications
  • • Prompt creation and deletion
  • • Organization and team management
  • • Billing and account settings
Programmatic Access (API Token via SDK)
  • • Fetch prompts
  • • Evaluate experiments
  • • Submit experiment scores

Installation

npm install @laikatest/js-client

Client Initialization

Basic Setup

import { LaikaTest } from '@laikatest/js-client';const client = new LaikaTest(apiKey);

With Configuration Options

const client = new LaikaTest(apiKey, {  baseUrl: 'https://api.laikatest.com',  timeout: 10000,      // Request timeout in milliseconds  cacheTTL: 1800000,   // Cache time-to-live (30 minutes)  cacheEnabled: true   // Enable/disable caching});

Core Methods

getPRomt()

Retrieve a prompt template by name.

const prompt = await client.getPRomt('my-prompt-name');// Compile the prompt with variablesconst compiledPrompt = prompt.compile({  username: 'Alice',  role: 'developer'});// With optionsconst prompt = await client.getPRomt('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.

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.getPRomt('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.getPRomt('my-prompt');  // Use prompt...} finally {  client.destroy();}

Error Handling

The SDK provides specialized error classes for different failure scenarios:

TypeScript
import {  LaikaTest,  ValidationError,  AuthenticationError,  NetworkError,  LaikaServiceError} from '@laikatest/js-client';try {  const prompt = await client.getPRomt('my-prompt');} catch (error) {  if (error instanceof AuthenticationError) {    console.error('Invalid API key');  } else if (error instanceof NetworkError) {    console.error('Network request failed');  } else if (error instanceof LaikaServiceError) {    console.error('Service error:', error.message);  }}

Error Types

  • ValidationError: Invalid input parameters
  • AuthenticationError: Invalid or missing API key
  • NetworkError: Network request failures
  • LaikaServiceError: Server-side errors

Best Practices

  • Store API keys securely: Use environment variables, never hardcode keys
  • Reuse client instances: Create one client instance and reuse it across requests
  • Implement error handling: Always wrap SDK calls in try-catch blocks
  • Use caching wisely: Keep caching enabled for better performance, bypass only when necessary
  • Clean up resources: Call destroy() when done, especially in serverless environments

Complete Example

import { LaikaTest } from '@laikatest/js-client';const client = new LaikaTest(process.env.LAIKATEST_API_KEY, {  timeout: 5000,  cacheTTL: 600000  // 10 minutes});try {  // Fetch prompt  const prompt = await client.getPRomt('customer-greeting');  // Compile with variables  const message = prompt.compile({    customerName: 'John Doe',    accountType: 'premium'  });  console.log(message);} catch (error) {  console.error('Failed to fetch prompt:', error);} finally {  client.destroy();}