> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baserun.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates

If you haven't already, please refer to the [Template Overview](/templates/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.

<CodeGroup>
  ```python python theme={null}
  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(
          template_name=template.name,
          template_messages=template.active_version.template_messages,
          parameters={"question": question},
      )

      client = AsyncOpenAI()
      completion = await client.chat.completions.create(
          model="gpt-3.5-turbo",
          messages=prompt,
      )
      return completion.choices[0].message.content
  ```

  ```typescript typescript theme={null}
  import OpenAI from "openai";
  import {baserun} from "baserun";

  async function answerQuestion(question: string) {
    // Automatically downloads the template from Baserun based on the name and
    // environment (`ENVIRONMENT` environment variable) and formats the prompt
    const prompt = await baserun.formatPromptFromTemplateName(
      "question_and_answer", {question: question}
    )
    // Send it to OpenAI
    const openai = new OpenAI();
    const completion = await openai.chat.completions.create({
      model: "gpt-3.5-turbo",
      messages: prompt,
    });
    return completion.choices[0].message.content;
  }
  ```
</CodeGroup>
