> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.meshapi.ai/api-reference/mesh-api/templates/llms.txt.
> For full documentation content, see https://developers.meshapi.ai/api-reference/mesh-api/templates/llms-full.txt.

# Create a template

POST https://api.meshapi.ai/v1/templates
Content-Type: application/json

Creates a template owned by the authenticated owner.

Template names must be unique within an owner namespace. Global templates
are read-only from this API.


Reference: https://developers.meshapi.ai/api-reference/mesh-api/templates/create-template

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: openapi
  version: 1.0.0
paths:
  /v1/templates:
    post:
      operationId: create-template
      summary: Create a template
      description: >
        Creates a template owned by the authenticated owner.


        Template names must be unique within an owner namespace. Global
        templates

        are read-only from this API.
      tags:
        - subpackage_templates
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Template created successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TemplateSummary'
        '401':
          description: Missing, malformed, or invalid bearer token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '403':
          description: The bearer token is valid but not currently active.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '409':
          description: Resource conflict, usually a duplicate template name.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '422':
          description: The request body failed validation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTemplateRequest'
servers:
  - url: https://api.meshapi.ai
components:
  schemas:
    ChatMessageRole:
      type: string
      enum:
        - system
        - user
        - assistant
        - tool
      title: ChatMessageRole
    TextContentPart:
      type: object
      properties:
        type:
          type: string
          enum:
            - text
        text:
          type: string
      required:
        - type
        - text
      title: TextContentPart
    ImageUrlDetail:
      type: string
      enum:
        - auto
        - low
        - high
      default: auto
      title: ImageUrlDetail
    ImageUrl:
      type: object
      properties:
        url:
          type: string
          description: Remote URL or `data:` URI.
        detail:
          $ref: '#/components/schemas/ImageUrlDetail'
      required:
        - url
      title: ImageUrl
    ImageContentPart:
      type: object
      properties:
        type:
          type: string
          enum:
            - image_url
        image_url:
          $ref: '#/components/schemas/ImageUrl'
      required:
        - type
        - image_url
      title: ImageContentPart
    ContentPart:
      oneOf:
        - $ref: '#/components/schemas/TextContentPart'
        - $ref: '#/components/schemas/ImageContentPart'
      title: ContentPart
    ChatMessageContent1:
      type: array
      items:
        $ref: '#/components/schemas/ContentPart'
      title: ChatMessageContent1
    ChatMessageContent:
      oneOf:
        - type: string
        - $ref: '#/components/schemas/ChatMessageContent1'
      title: ChatMessageContent
    ToolCallFunction:
      type: object
      properties:
        name:
          type: string
        arguments:
          type: string
          description: JSON-encoded argument object.
      required:
        - name
        - arguments
      title: ToolCallFunction
    ToolCall:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
          enum:
            - function
        function:
          $ref: '#/components/schemas/ToolCallFunction'
      required:
        - id
        - type
        - function
      title: ToolCall
    ChatMessage:
      type: object
      properties:
        role:
          $ref: '#/components/schemas/ChatMessageRole'
        content:
          oneOf:
            - $ref: '#/components/schemas/ChatMessageContent'
            - type: 'null'
        name:
          type:
            - string
            - 'null'
        tool_call_id:
          type:
            - string
            - 'null'
        tool_calls:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/ToolCall'
      required:
        - role
      title: ChatMessage
    TemplateDefaultsStop:
      oneOf:
        - type: string
        - type: array
          items:
            type: string
      description: One or more stop sequences that end generation when encountered.
      title: TemplateDefaultsStop
    TemplateDefaults:
      type: object
      properties:
        temperature:
          type:
            - number
            - 'null'
          format: double
          description: >-
            Sampling temperature used for token selection. Lower values make
            output more deterministic; higher values increase randomness and
            variation.
        max_tokens:
          type:
            - integer
            - 'null'
          description: Maximum number of completion tokens to generate.
        top_p:
          type:
            - number
            - 'null'
          format: double
          description: >-
            Nucleus sampling threshold. The model samples from the smallest set
            of tokens whose cumulative probability reaches `top_p`.
        frequency_penalty:
          type:
            - number
            - 'null'
          format: double
          description: >-
            Penalizes tokens that have already appeared in the generated output,
            reducing repeated phrasing.
        presence_penalty:
          type:
            - number
            - 'null'
          format: double
          description: >-
            Penalizes tokens that have already appeared at least once, nudging
            the model toward introducing new topics.
        stop:
          oneOf:
            - $ref: '#/components/schemas/TemplateDefaultsStop'
            - type: 'null'
          description: One or more stop sequences that end generation when encountered.
        seed:
          type:
            - integer
            - 'null'
          description: >-
            Optional seed for best-effort deterministic sampling across repeated
            requests with the same parameters.
      title: TemplateDefaults
    CreateTemplateRequest:
      type: object
      properties:
        name:
          type: string
        description:
          type:
            - string
            - 'null'
        system:
          type:
            - string
            - 'null'
        messages:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/ChatMessage'
        model:
          type:
            - string
            - 'null'
        params:
          oneOf:
            - $ref: '#/components/schemas/TemplateDefaults'
            - type: 'null'
        variables:
          type:
            - array
            - 'null'
          items:
            type: string
      required:
        - name
      title: CreateTemplateRequest
    TemplateSummary:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        owner:
          type:
            - string
            - 'null'
        is_global:
          type: boolean
        description:
          type:
            - string
            - 'null'
        system:
          type:
            - string
            - 'null'
        messages:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/ChatMessage'
        model:
          type:
            - string
            - 'null'
        params:
          oneOf:
            - $ref: '#/components/schemas/TemplateDefaults'
            - type: 'null'
        variables:
          type:
            - array
            - 'null'
          items:
            type: string
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
        - id
        - name
        - is_global
        - created_at
        - updated_at
      title: TemplateSummary
    ErrorBodyCode:
      type: string
      enum:
        - unauthorized
        - forbidden
        - not_found
        - model_not_found
        - validation_error
        - unprocessable_entity
        - rate_limit_exceeded
        - spend_limit_exceeded
        - conflict
        - upstream_error
        - provider_not_available
        - gateway_timeout
      title: ErrorBodyCode
    ValidationErrorDetailLocItems:
      oneOf:
        - type: string
        - type: integer
      title: ValidationErrorDetailLocItems
    ValidationErrorDetail:
      type: object
      properties:
        loc:
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorDetailLocItems'
        msg:
          type: string
        type:
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationErrorDetail
    ProviderError:
      type: object
      properties:
        provider:
          type: string
        status:
          type:
            - integer
            - 'null'
        message:
          type:
            - string
            - 'null'
      title: ProviderError
    ErrorBody:
      type: object
      properties:
        code:
          $ref: '#/components/schemas/ErrorBodyCode'
        message:
          type: string
        param:
          type:
            - string
            - 'null'
        details:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/ValidationErrorDetail'
        provider_error:
          oneOf:
            - $ref: '#/components/schemas/ProviderError'
            - type: 'null'
        retry_after_seconds:
          type:
            - integer
            - 'null'
      required:
        - code
        - message
      title: ErrorBody
    ErrorEnvelope:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/ErrorBody'
        request_id:
          type: string
      required:
        - error
        - request_id
      title: ErrorEnvelope
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

```

## SDK Code Examples

```python Python
import httpx

response = httpx.post(
  "https://api.meshapi.ai/v1/templates",
  headers={"Authorization": "Bearer <dashboard-jwt-or-rsk-key>"},
  json={
    "name": "support-reply",
    "description": "Structured support reply template.",
    "system": "You are a helpful support assistant for {{company}}.",
    "variables": ["company"],
    "model": "openai/gpt-4o-mini",
    "params": {"temperature": 0.2, "max_tokens": 300},
  },
)
response.raise_for_status()
print(response.json()["id"])

```

```python Python (SDK)
from meshapi import MeshAPI, CreateTemplateParams

client = MeshAPI(
  base_url="https://api.meshapi.ai",
  token="<dashboard-jwt-or-rsk-key>",
)

template = client.templates.create(
  CreateTemplateParams(
    name="support-reply",
    description="Structured support reply template.",
    system="You are a helpful support assistant for {{company}}.",
    variables=["company"],
    model="openai/gpt-4o-mini",
    params={"temperature": 0.2, "max_tokens": 300},
  )
)

print(template.id)

```

```typescript TypeScript (SDK)
import { MeshAPI } from "meshapi-node-sdk";

const client = new MeshAPI({
  baseUrl: "https://api.meshapi.ai",
  token: "<dashboard-jwt-or-rsk-key>",
});

const template = await client.templates.create({
  name: "support-reply",
  description: "Structured support reply template.",
  system: "You are a helpful support assistant for {{company}}.",
  variables: ["company"],
  model: "openai/gpt-4o-mini",
  params: { temperature: 0.2, max_tokens: 300 },
});

console.log(template.id);

```

```go Created template
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.meshapi.ai/v1/templates"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Created template
require 'uri'
require 'net/http'

url = URI("https://api.meshapi.ai/v1/templates")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'

response = http.request(request)
puts response.read_body
```

```java Created template
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.meshapi.ai/v1/templates")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .asString();
```

```php Created template
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.meshapi.ai/v1/templates', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Created template
using RestSharp;

var client = new RestClient("https://api.meshapi.ai/v1/templates");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
```

```swift Created template
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.meshapi.ai/v1/templates")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

```python Python
import httpx

response = httpx.post(
  "https://api.meshapi.ai/v1/templates",
  headers={"Authorization": "Bearer <dashboard-jwt-or-rsk-key>"},
  json={
    "name": "support-reply",
    "description": "Structured support reply template.",
    "system": "You are a helpful support assistant for {{company}}.",
    "variables": ["company"],
    "model": "openai/gpt-4o-mini",
    "params": {"temperature": 0.2, "max_tokens": 300},
  },
)
response.raise_for_status()
print(response.json()["id"])

```

```python Python (SDK)
from meshapi import MeshAPI, CreateTemplateParams

client = MeshAPI(
  base_url="https://api.meshapi.ai",
  token="<dashboard-jwt-or-rsk-key>",
)

template = client.templates.create(
  CreateTemplateParams(
    name="support-reply",
    description="Structured support reply template.",
    system="You are a helpful support assistant for {{company}}.",
    variables=["company"],
    model="openai/gpt-4o-mini",
    params={"temperature": 0.2, "max_tokens": 300},
  )
)

print(template.id)

```

```typescript TypeScript (SDK)
import { MeshAPI } from "meshapi-node-sdk";

const client = new MeshAPI({
  baseUrl: "https://api.meshapi.ai",
  token: "<dashboard-jwt-or-rsk-key>",
});

const template = await client.templates.create({
  name: "support-reply",
  description: "Structured support reply template.",
  system: "You are a helpful support assistant for {{company}}.",
  variables: ["company"],
  model: "openai/gpt-4o-mini",
  params: { temperature: 0.2, max_tokens: 300 },
});

console.log(template.id);

```

```go Support reply template
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.meshapi.ai/v1/templates"

	payload := strings.NewReader("{\n  \"name\": \"support-reply\",\n  \"description\": \"Structured support reply template.\",\n  \"system\": \"You are a helpful support assistant for {{company}}.\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Respond with empathy and clear next steps.\"\n    }\n  ],\n  \"model\": \"openai/gpt-4o-mini\",\n  \"params\": {\n    \"temperature\": 0.2,\n    \"max_tokens\": 300\n  },\n  \"variables\": [\n    \"company\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Support reply template
require 'uri'
require 'net/http'

url = URI("https://api.meshapi.ai/v1/templates")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"support-reply\",\n  \"description\": \"Structured support reply template.\",\n  \"system\": \"You are a helpful support assistant for {{company}}.\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Respond with empathy and clear next steps.\"\n    }\n  ],\n  \"model\": \"openai/gpt-4o-mini\",\n  \"params\": {\n    \"temperature\": 0.2,\n    \"max_tokens\": 300\n  },\n  \"variables\": [\n    \"company\"\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java Support reply template
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.meshapi.ai/v1/templates")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"support-reply\",\n  \"description\": \"Structured support reply template.\",\n  \"system\": \"You are a helpful support assistant for {{company}}.\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Respond with empathy and clear next steps.\"\n    }\n  ],\n  \"model\": \"openai/gpt-4o-mini\",\n  \"params\": {\n    \"temperature\": 0.2,\n    \"max_tokens\": 300\n  },\n  \"variables\": [\n    \"company\"\n  ]\n}")
  .asString();
```

```php Support reply template
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.meshapi.ai/v1/templates', [
  'body' => '{
  "name": "support-reply",
  "description": "Structured support reply template.",
  "system": "You are a helpful support assistant for {{company}}.",
  "messages": [
    {
      "role": "user",
      "content": "Respond with empathy and clear next steps."
    }
  ],
  "model": "openai/gpt-4o-mini",
  "params": {
    "temperature": 0.2,
    "max_tokens": 300
  },
  "variables": [
    "company"
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Support reply template
using RestSharp;

var client = new RestClient("https://api.meshapi.ai/v1/templates");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"support-reply\",\n  \"description\": \"Structured support reply template.\",\n  \"system\": \"You are a helpful support assistant for {{company}}.\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Respond with empathy and clear next steps.\"\n    }\n  ],\n  \"model\": \"openai/gpt-4o-mini\",\n  \"params\": {\n    \"temperature\": 0.2,\n    \"max_tokens\": 300\n  },\n  \"variables\": [\n    \"company\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Support reply template
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "support-reply",
  "description": "Structured support reply template.",
  "system": "You are a helpful support assistant for {{company}}.",
  "messages": [
    [
      "role": "user",
      "content": "Respond with empathy and clear next steps."
    ]
  ],
  "model": "openai/gpt-4o-mini",
  "params": [
    "temperature": 0.2,
    "max_tokens": 300
  ],
  "variables": ["company"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.meshapi.ai/v1/templates")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```