Skip to main content
Prompts created in Braintrust can be called directly from your application code. Reference a prompt by its slug, and changes you make in the UI take effect immediately without redeploying your application.

Two ways to run a prompt

Your application can run a prompt in one of two ways, which differ in where the model call happens and what you get back:
  • Invoke it on Braintrust. invoke() runs the prompt against its configured model and returns the model’s response. Braintrust makes the model call and logs it.
  • Load it and run it yourself. loadPrompt() fetches the prompt’s configuration, and build() compiles it into request parameters that you pass to your own LLM client.
The return values make the difference concrete. For the same summarizer prompt:
Invoke a prompt when you want Braintrust to run and log the call for you. Load a prompt when you need to make the model call yourself, either to use a provider client you already have configured or to inspect or change the messages before sending them.

Invoke a prompt

invoke() runs a prompt on Braintrust using its configured model and parameters, and returns the model’s response. Call it by slug:
The input parameter values map to template variables in your prompt. For example, {{text}} in your prompt gets replaced with the text value from input. Invoking prompts this way:
  • Automatically logs inputs and outputs.
  • Tracks which prompt version was used.
  • Enables A/B testing different prompt versions.
  • Lets you update prompts without code changes.
The Ruby SDK doesn’t support server-side invocation. Instead, load a prompt and build it locally, then call your own LLM client. See Load a prompt.
To pin a specific version or load the version assigned to an environment, see Version prompts.

Load a prompt

Use loadPrompt() (TypeScript), load_prompt() (Python), or client.LoadPrompt() (Go) to fetch a prompt’s configuration, then call build() on the result to compile its template into request parameters for your own LLM client:
build() returns the compiled messages, model, and parameters without calling the model, so you can pass them straight to a client or inspect them first. The TypeScript and Python functions cache the loaded prompt in memory and on disk, so repeated loads skip the network round trip and fall back to the last cached copy if Braintrust is unreachable. The Go client.LoadPrompt() method fetches the prompt on every call. Unlike invoke(), loading a prompt doesn’t log anything on its own. Braintrust records the call only if the client you pass the messages to is instrumented, which is why the examples above wrap the client with wrapOpenAI()/wrap_openai(). See Trace LLM calls for the instrumentation options in each language.
In Ruby, identify the project by name (project:) or by UUID (project_id:). Providing neither raises an ArgumentError. After loading, prompt.version returns the resolved version’s transaction ID, which you can pass to Braintrust::Prompt.load(version:) to re-pin the exact same version later.
For the full Go prompt surface, including inline prompt.Definition prompts and built.AnnotateSpan for trace linkage, see the Go API reference.

Use within a trace

When calling prompts from instrumented code, they automatically nest within your parent trace:
This creates a hierarchical trace where the prompt execution appears as a child span of your function.

Handle tool calls

When a prompt includes tools, the response contains tool calls that your code must handle:
See Add tools to attach tools to a prompt, and Deploy functions for details on deploying tools alongside prompts.

Add extra messages

The messages parameter appends messages after the prompt’s own messages, letting you continue a conversation while reusing the prompt’s model and configuration. The example below invokes the assistant prompt, then invokes it again with the model’s first answer and a follow-up question so it can reconsider its response:

Stream responses

Set stream: true to receive responses incrementally:
Streaming works automatically through the Gateway and logs the complete response to Braintrust. For the Server-Sent Events format and streaming through the Gateway or wrapped clients, see Stream responses.

Manage from the CLI

Use the bt CLI to browse and test prompts without opening the UI. Browse prompts:
Test a prompt: Use bt functions invoke to call a prompt and see its output directly from the terminal:
See bt prompts for the full command surface, including assigning a prompt version to an environment.

Use the REST API

Call prompts directly via HTTP.
In the examples below, organizations on the EU data plane should replace api.braintrust.dev with api-eu.braintrust.dev.
The REST API supports all the same parameters as the SDK, including versioning, environments, and streaming.

Next steps