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

# Create Template

> Create a new extraction template with a JSON schema.

## Authentication & Scope

Requires the `templates-write` ability.

## Request

```http theme={null}
POST /extractions/templates HTTP/1.1
Host: api.raydocs.com
Authorization: Bearer <token>
Content-Type: application/json

{
  "name": "Invoice Extraction",
  "description": "Extract key fields from invoices",
  "workspace_id": 1,
  "schema_json": {
    "config": {
      "reasoning_enabled": true
    },
    "groups": {
      "invoice_details": {
        "search_query": "invoice number, date, amount",
        "fields": {
          "invoice_number": {
            "type": "string",
            "extraction_prompt": "Extract the invoice number"
          },
          "total_amount": {
            "type": "number",
            "extraction_prompt": "Extract the total amount"
          }
        }
      }
    }
  },
  "settings": {
    "parsing": {
      "contextual_embedding": false
    }
  }
}
```

### Body Parameters

| Parameter      | Type    | Required | Description                     |
| -------------- | ------- | -------- | ------------------------------- |
| `name`         | string  | Yes      | Template name                   |
| `description`  | string  | No       | Template description            |
| `workspace_id` | integer | Yes      | Workspace to create in          |
| `schema_json`  | object  | No       | Extraction schema definition    |
| `settings`     | object  | No       | Parsing and processing settings |

<Tip>
  See the [Extraction Schema Guide](/guides/extraction-schema) for detailed schema documentation.
</Tip>

## Response

`201 Created` – The newly created template.

```json theme={null}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Invoice Extraction",
  "description": "Extract key fields from invoices",
  "schema_json": { ... },
  "settings": { ... },
  "workspace_id": 1,
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:30:00Z"
}
```


## OpenAPI

````yaml post /extractions/templates
openapi: 3.0.1
info:
  title: Raydocs API
  description: REST API for document extraction with AI-powered data parsing
  version: 1.0.0
servers:
  - url: https://api.raydocs.com
security:
  - bearerAuth: []
tags:
  - name: Workspaces
    description: Create and manage workspaces.
  - name: Workspace Users
    description: Manage users within a workspace.
  - name: Extraction Templates
    description: Define extraction schemas and settings.
  - name: Extraction Sessions
    description: Manage extraction jobs and documents.
  - name: Batch Operations
    description: Bulk operations on sessions.
  - name: Documents
    description: Upload and manage source documents.
  - name: Workflows
    description: Discover workflow runs and read their public outputs.
  - name: Results
    description: Access extraction results.
paths:
  /extractions/templates:
    post:
      tags:
        - Extraction Templates
      summary: Create Template
      description: Create a new extraction template. Requires `templates-write`.
      operationId: createTemplate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - workspace_id
              properties:
                name:
                  type: string
                  example: Invoice Extraction
                description:
                  type: string
                workspace_id:
                  type: integer
                schema_json:
                  $ref: '#/components/schemas/ExtractionSchema'
                settings:
                  type: object
                  properties:
                    parsing:
                      type: object
                      properties:
                        contextual_embedding:
                          type: boolean
                          default: false
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExtractionTemplate'
        '403':
          description: Forbidden
components:
  schemas:
    ExtractionSchema:
      type: object
      description: JSON schema defining extraction fields and groups
      properties:
        config:
          type: object
          properties:
            reasoning_enabled:
              type: boolean
            system_message:
              type: string
        definitions:
          type: object
          additionalProperties: true
        groups:
          type: object
          additionalProperties:
            type: object
            properties:
              search_query:
                type: string
              extraction_prompt:
                type: string
              fields:
                type: object
                additionalProperties: true
    ExtractionTemplate:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
        name:
          type: string
        description:
          type: string
        schema_json:
          $ref: '#/components/schemas/ExtractionSchema'
        settings:
          type: object
          properties:
            parsing:
              type: object
              properties:
                contextual_embedding:
                  type: boolean
        workspace_id:
          type: integer
        created_at:
          type: string
          format: date-time
          readOnly: true
        updated_at:
          type: string
          format: date-time
          readOnly: true
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Personal Access Token created from the Raydocs dashboard.

        Include in the Authorization header: `Bearer <your_token>`

        See [API Keys](/api-reference/api-keys) for token creation and
        management.

````