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

# Prompt Templates

> Create, update, delete, and use prompt templates with variable substitution.

Prompt templates let you save reusable system prompts with `{{variable}}` placeholders. Pass the template name in a chat request to apply it.

## Create a template

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from meshapi import MeshAPI
    from meshapi import CreateTemplateParams

    client = MeshAPI(base_url="https://api.meshapi.ai", token="rsk_...")

    tmpl = client.templates.create(
        CreateTemplateParams(
            name="my-assistant",
            description="A friendly pirate assistant",
            system="You are a {{role}}. Always reply in exactly one sentence.",
            variables=["role"],
        )
    )
    print(tmpl.id)
    print(tmpl.name)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const tmpl = await client.templates.create({
      name: "my-assistant",
      description: "A friendly pirate assistant",
      system: "You are a {{role}}. Always reply in exactly one sentence.",
      variables: ["role"],
    });
    console.log(tmpl.id);
    console.log(tmpl.name);
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    desc := "A friendly pirate assistant"
    system := "You are a {{role}}. Always reply in exactly one sentence."

    tmpl, err := client.Templates.Create(ctx, meshapi.CreateTemplateParams{
        Name:        "my-assistant",
        Description: &desc,
        System:      &system,
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(tmpl.ID, tmpl.Name)
    ```
  </Tab>
</Tabs>

## List templates

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    templates = client.templates.list()
    for t in templates:
        print(t.id, t.name)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const templates = await client.templates.list();
    templates.forEach(t => console.log(t.id, t.name));
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    all, err := client.Templates.List(ctx)
    for _, t := range all {
        fmt.Println(t.ID, t.Name)
    }
    ```
  </Tab>
</Tabs>

## Get a template

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    got = client.templates.get(tmpl.id)
    print(got.name)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const got = await client.templates.get(tmpl.id);
    console.log(got.name);
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    got, err := client.Templates.Get(ctx, tmpl.ID)
    fmt.Println(got.Name)
    ```
  </Tab>
</Tabs>

## Update a template

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from meshapi import UpdateTemplateParams

    updated = client.templates.update(
        tmpl.id,
        UpdateTemplateParams(description="Updated description"),
    )
    print(updated.description)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const updated = await client.templates.update(tmpl.id, {
      description: "Updated description",
    });
    console.log(updated.description);
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    newDesc := "Updated description"
    updated, err := client.Templates.Update(ctx, tmpl.ID, meshapi.UpdateTemplateParams{
        Description: &newDesc,
    })
    fmt.Println(*updated.Description)
    ```
  </Tab>
</Tabs>

## Delete a template

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    client.templates.delete(tmpl.id)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    await client.templates.delete(tmpl.id);
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    err := client.Templates.Delete(ctx, tmpl.ID)
    ```
  </Tab>
</Tabs>

## Use a template in a chat request

Pass the template name and variable values in the chat request. See [Chat Completions — Using a prompt template](/sdk/chat) for the full example.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from meshapi import ChatCompletionParams, ChatMessage

    resp = client.chat.completions.create(
        ChatCompletionParams(
            model="openai/gpt-4o-mini",
            messages=[ChatMessage(role="user", content="Introduce yourself.")],
            template=tmpl.name,
            variables={"role": "friendly pirate"},
            max_tokens=80,
        )
    )
    print(resp.choices[0].message.content)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const resp = await client.chat.completions.create({
      model: "openai/gpt-4o-mini",
      messages: [{ role: "user", content: "Introduce yourself." }],
      template: tmpl.name,
      variables: { role: "friendly pirate" },
      max_tokens: 80,
    });
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    maxTokens := 80
    resp, err := client.Chat.Completions.Create(ctx, meshapi.ChatCompletionParams{
        Template:  &tmpl.Name,
        Messages:  []meshapi.ChatMessage{{Role: "user", Content: "Introduce yourself."}},
        Variables: map[string]string{"role": "friendly pirate"},
        MaxTokens: &maxTokens,
    })
    ```
  </Tab>
</Tabs>
