# Create Template

Source: https://recoupable.dev/docs/api-reference/templates/create

Create a template

## POST /api/agents/templates

Full OpenAPI specification: https://recoupable.dev/docs/spec/templates.json

## Authentication

This operation requires one of the security alternatives in the specification below. Security scheme definitions are included where present in the published specification.

[Authentication guide](https://recoupable.dev/docs/authentication)

## Operation and referenced schemas

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Recoup API - Templates",
    "description": "API documentation for managing reusable templates on the Recoup platform. Templates capture a prompt, description, and tags that can be shared with other accounts or kept private.",
    "license": {
      "name": "MIT"
    },
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.recoupable.dev"
    }
  ],
  "security": [
    {
      "apiKeyAuth": []
    },
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/api/agents/templates": {
      "post": {
        "summary": "Create a template",
        "description": "Create a new template owned by the authenticated account. When `is_private` is true, the optional `share_emails` array grants explicit read access to the listed accounts; for public templates the field is ignored.",
        "security": [
          {
            "apiKeyAuth": []
          },
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "description": "Template fields",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTemplateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Template created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request - validation failed or required fields missing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CreateTemplateRequest": {
        "type": "object",
        "required": [
          "title",
          "description",
          "prompt",
          "tags",
          "is_private"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 3,
            "maxLength": 50,
            "description": "Short human-readable title for the template"
          },
          "description": {
            "type": "string",
            "minLength": 10,
            "maxLength": 200,
            "description": "Description of what the template does"
          },
          "prompt": {
            "type": "string",
            "minLength": 20,
            "maxLength": 10000,
            "description": "The agent prompt body"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Free-form tags used to categorize the template. Pass an empty array if there are no tags."
          },
          "is_private": {
            "type": "boolean",
            "description": "When true, the template is restricted to the creator and the accounts listed in `share_emails`"
          },
          "share_emails": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "email"
            },
            "description": "Emails to grant access to. Only applied when `is_private` is true. Defaults to an empty array when omitted."
          }
        }
      },
      "TemplateResponse": {
        "type": "object",
        "required": [
          "status",
          "template"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "success"
            ],
            "description": "Status of the request"
          },
          "template": {
            "$ref": "#/components/schemas/Template"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "status",
          "error"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "error"
            ],
            "description": "Status of the request"
          },
          "error": {
            "type": "string",
            "description": "Human-readable error message"
          },
          "missing_fields": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Names of required fields that were missing from the request, when applicable"
          }
        }
      },
      "Template": {
        "type": "object",
        "required": [
          "id",
          "title",
          "description",
          "prompt",
          "tags",
          "creator",
          "is_private",
          "is_favourite",
          "favorites_count",
          "shared_emails",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Unique identifier of the template"
          },
          "title": {
            "type": "string",
            "description": "Short human-readable title for the template (3-50 characters)"
          },
          "description": {
            "type": "string",
            "description": "Description of what the template does (10-200 characters)"
          },
          "prompt": {
            "type": "string",
            "description": "The agent prompt body (20-10000 characters)"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Free-form tags used to categorize the template. Empty array when there are no tags."
          },
          "creator": {
            "$ref": "#/components/schemas/TemplateCreator"
          },
          "is_private": {
            "type": "boolean",
            "description": "Whether the template is restricted to the creator and explicitly shared accounts"
          },
          "is_favourite": {
            "type": "boolean",
            "description": "Whether the authenticated account has favorited this template"
          },
          "favorites_count": {
            "type": "integer",
            "description": "Total number of accounts that have favorited this template"
          },
          "shared_emails": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "email"
            },
            "description": "Emails the template has been shared with. Only populated for private templates the authenticated account owns; empty for public templates and for private templates shared with the caller."
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp of when the template was created"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "ISO 8601 timestamp of when the template was last updated"
          }
        }
      },
      "TemplateCreator": {
        "type": [
          "object",
          "null"
        ],
        "description": "The account that created the template. May be null when the creator account is unavailable.",
        "required": [
          "id",
          "name",
          "image",
          "is_admin"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Unique identifier of the creator account"
          },
          "name": {
            "type": [
              "string",
              "null"
            ],
            "description": "Display name of the creator account"
          },
          "image": {
            "type": [
              "string",
              "null"
            ],
            "description": "Profile image URL of the creator account"
          },
          "is_admin": {
            "type": "boolean",
            "description": "Whether the creator is a Recoup admin (their account email is on the platform admin allow-list)"
          }
        }
      }
    },
    "securitySchemes": {
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Your Recoup API key. [Learn more](/quickstart#api-keys)."
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  }
}
```
