> ## 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.

## Registering Templates using the SDK

To register a template, you can use the `register_template` or `aregister_template` method from the `baserun` module. This method takes two arguments:

* `template`: A list of messages in the template
* `template_name`: The name of the template

<CodeGroup>
  ```python python theme={null}
  import baserun
  import openai


  async def answer_question(question: str) -> str:
      # Register a template with your template string (`TEMPLATES` constant in this codebase)
      await baserun.aregister_template(TEMPLATES.get(template_name), template_name)
      # Use the template to format the prompt, then send it to OpenAI
      prompt = await baserun.format_prompt(
          template_name=template_name,
          template_messages=TEMPLATES.get(template_name),
          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";

  const TEMPLATE: { role: "user" | "system"; content: string }[] = [
    { role: "system", content: "you're a helpful assistant" },
    { role: "user", content: "answer this question: {question}" },
  ];

  async function answerQuestion(question: string) {
    // Register a template with your list of messages
    await baserun.registerTemplate(TEMPLATE, "question_and_answer");
    // Use the template to format the prompt, then send it to OpenAI
    const prompt = baserun.formatPrompt(TEMPLATE, { question: question });
    const completion = await openai.chat.completions.create({
      model: "gpt-3.5-turbo",
      messages: prompt,
    });
    return completion.choices[0].message.content;
  }
  ```
</CodeGroup>
