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, andbuild()compiles it into request parameters that you pass to your own LLM client.
summarizer prompt:
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:
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.
Load a prompt
UseloadPrompt() (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.Use within a trace
When calling prompts from instrumented code, they automatically nest within your parent trace:Handle tool calls
When a prompt includes tools, the response contains tool calls that your code must handle:Add extra messages
Themessages 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
Setstream: true to receive responses incrementally:
Manage from the CLI
Use thebt CLI to browse and test prompts without opening the UI.
Browse prompts:
bt functions invoke to call a prompt and see its output directly from the terminal:
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.Next steps
- Version prompts to pin versions and assign them to environments.
- Stream responses to return incremental output from prompts and functions.
- Deploy functions to deploy tools and workflows alongside prompts.
- Monitor deployments to track prompt performance in production.