TypeScript Prompt SDK Reference


Below are the arguments that can be passed when initializing the prompt manager:

idtrueThe ID of the prompt.
version.majortrueMust be pinned to a specific major version.
version.minortrueCan be one of: a specific minor version, the string "latest", or a weighted list. If a weighted list, the minor version will be chosen randomly at runtime for each exec call according to the weights.
apiKeyfalseAUTOBLOCKS_API_KEY environment variableYour Autoblocks API key.
refreshIntervalfalse{ seconds: 10 }How often to refresh the latest prompt. Only relevant if the minor version is set to "latest" or "latest" is used in the weighted list.
refreshTimeoutfalse{ seconds: 30 }How long to wait for the latest prompt to refresh before timing out. A refresh timeout will not throw an uncaught error. An error will be logged and the background refresh process will continue to run at its configured interval.
initTimeoutfalse{ seconds: 30 }How long to wait for the prompt manager to be ready (when calling init()) before timing out.
import { AutoblocksPromptManager } from '@autoblocks/client/prompts';

const mgr = new AutoblocksPromptManager({
  id: 'text-summarization',
  version: {
    major: '1',
    minor: '0',


Starts a prompt execution context by creating a new PromptExecutionContext instance.

const response = await mgr.exec(async ({ prompt }) => {


An instance of this class is created every time a new execution context is started with the exec function. It contains a frozen copy of the prompt manager's in-memory prompt at the time exec was called. This ensures the prompt is stable for the duration of an execution, even if the in-memory prompt on the manager instance is refreshed mid-execution.


An object with the prompt's parameters.

const response = await mgr.exec(async ({ prompt }) => {
  const params: ChatCompletionCreateParamsNonStreaming = {
    model: prompt.params.model,
    temperature: prompt.params.temperature,


The render function accepts a template ID and parameters and returns the rendered template as a string.

templatetrueThe ID of the template to render.
paramstrueThe parameters to pass to the template. These values are used to replace the template parameters wrapped in double curly braces.
const response = await mgr.exec(async ({ prompt }) => {
  // Use `prompt.render` to render a template
      template: 'util/language',
      params: {
        // Replaces "{{ language }}" with "Spanish"
        language: 'Spanish',
  // Logs "Always respond in Spanish."


This function returns tracking information for current prompt execution context. It is meant to be sent as the promptTracking property on an LLM response event.

tracer.sendEvent('ai.response', {
  properties: {
  promptTracking: prompt.track(),