If you haven’t already, please refer to the Template Overview page for an overview of Chat Templates.

Pulling a template using the SDK

Using the Baserun SDK, you can retrieve a template stored in Baserun’s Prompt Registry. This way, your templates don’t need to be committed in your code, and can be updated almost instantly.

Each template can be deployed to different environments, and the SDK will automatically pull the correct version based on the ENVIRONMENT environment variable.

import baserun
import openai

async def answer_question(question: str):
    # Download the template from Baserun based on the name and environment (`ENVIRONMENT` environment variable)
    template = baserun.get_template("question_and_answer")
    # Format the prompt, then send it to OpenAI
    prompt = await baserun.format_prompt(
        parameters={"question": question},

    client = AsyncOpenAI()
    completion = await client.chat.completions.create(
    return completion.choices[0].message.content