> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://onepin.ai/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://onepin.ai/docs/_mcp/server.

# List Templates

GET https://api.onepin.ai/api/v1/templates

Browse the public template gallery across all workspaces.

Returns only templates that have an active published snapshot (`is_public=true`,
`published_definition` set, not unpublished). Results come from any workspace —
the gallery is intentionally cross-workspace so callers can discover shared
starting points regardless of their own workspace membership.

Does not require `X-Workspace-Id`, so callers without a workspace (e.g. during
onboarding) can still browse. The response reflects the published snapshot for
each row, not any unpublished draft edits.

Dual-auth: Bearer JWT or API key (scope `templates:read`).

Reference: https://onepin.ai/docs/reference/api-reference/templates/list

## Authentication

- `Authorization` header (bearer token, required) — Clerk JWT token
- `Authorization` header (bearer token, required) — Onepin live API key (`op_live_...`). Test and public keys are reserved in Phase 1.

## Servers

- `https://api.onepin.ai` (prod, default)
- `https://dev-api.onepin.ai` (dev)

## Request

### Query parameters

- `category` (list of enum, optional, nullable) — Filter by category. Repeat the parameter for OR logic, e.g. `?category=media&category=creative`.
  - Allowed values: `media`, `creative`, `business`, `education`, `wellness`
- `search` (string, optional, nullable) — Full-text search over template name and description.
- `sort` (enum, optional, default: recent) — Sort order: `recent` (last published), `popular` (most cloned), or `name` (alphabetical).
  - Allowed values: `popular`, `recent`, `name`
- `offset` (integer, optional, default: 0) — Zero-based offset for page navigation.
- `limit` (integer, optional, default: 20) — Maximum number of templates to return (1–100).
- `favorites_only` (boolean, optional, default: false)

## Response

### 200

Successful Response

- `data` (list of TemplateOut, required)
- `meta` (Meta, required)
- `pagination` (PaginationMeta, required)

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### TemplateOut

Response shape. `workspace_id` is intentionally omitted so the gallery endpoint (which returns rows from any workspace) does not leak tenant ownership IDs across tenants. `created_by` is retained as author provenance for public/starter rows. `definition` is the serialized `WorkflowDefinition` JSONB (same shape as `Workflow.definition`) — a template is a reusable workflow snapshot.

- `id` (string, required) — Case-sensitive 8-character base62 template identifier.
- `name` (string, required) — Display name of the template.
- `definition` (WorkflowDefinition-Output, required) — Full workflow definition (graph + execution config). Use this directly as the `definition` body when creating a workflow from scratch, or clone via `POST /templates/{id}/clone`.
- `is_starter` (boolean, required) — `true` for platform-curated starter templates. Starter templates cannot be updated or deleted.
- `is_public` (boolean, required) — `true` when this template has an active published snapshot visible in the gallery.
- `uses_count` (integer, required) — Number of times this template has been cloned into a workflow.
- `created_at` (datetime, required)
- `updated_at` (datetime, required) — Last-modified timestamp. For gallery rows this reflects the most recent publish; for own-workspace rows it reflects the most recent draft save.
- `description` (string, optional, nullable) — Optional human-readable description.
- `category` (enum, optional, nullable) — Gallery category tag, if set.
  - Allowed values: `media`, `creative`, `business`, `education`, `wellness`
- `is_favorite` (boolean, optional, default: false) — `true` when the authenticated caller has favorited this template.
- `created_by` (string, optional, nullable) — User ID of the template author.

### Meta

- `request_id` (string, required)
- `timestamp` (datetime, required)

### PaginationMeta

- `limit` (integer, required)
- `next` (string, optional, nullable)
- `prev` (string, optional, nullable)

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `input` (any, optional)
- `ctx` (ValidationErrorCtx, optional)

### WorkflowDefinition-Output

- `graph` (GraphDefinition-Output, optional)
- `execution` (ExecutionDefinition, optional)

### ValidationErrorLocItems

### ValidationErrorCtx

### GraphDefinition-Output

- `nodes` (list of GraphNode, optional)
- `edges` (list of GraphEdge, optional)

### ExecutionDefinition

- `steps` (list of string, optional)
- `params` (map from string to any, optional)

### GraphNode

- `id` (string, required)
- `type` (enum, required)
  - Allowed values: `source_script`, `operator_translator`, `operator_normalizer`, `operator_generator`, `operator_phoneme_injector`, `sink_preview`, `validator_error_rate`, `validator_naturalness`, `validator_noise`, `validator_pronunciation`, `operator_pronunciation_corrector`
- `position` (NodePosition, required)
- `name` (string, optional, nullable)
- `config` (map from string to any, optional)
- `config_version` (integer, optional, default: 1)

### GraphEdge

- `id` (string, required)
- `source` (string, required)
- `sourcePort` (string, required)
- `target` (string, required)
- `targetPort` (string, required)

### NodePosition

- `x` (double, required)
- `y` (double, required)

## Examples

**Response**

```json
{
  "data": [
    {
      "id": "string",
      "name": "string",
      "definition": {
        "graph": {
          "nodes": [
            {
              "id": "string",
              "type": "source_script",
              "position": {
                "x": 1.1,
                "y": 1.1
              },
              "name": "string",
              "config": {},
              "config_version": 1
            }
          ],
          "edges": [
            {
              "id": "string",
              "source": "string",
              "sourcePort": "string",
              "target": "string",
              "targetPort": "string"
            }
          ]
        },
        "execution": {
          "steps": [
            "string"
          ],
          "params": {}
        }
      },
      "is_starter": true,
      "is_public": true,
      "uses_count": 1,
      "created_at": "2024-01-15T09:30:00Z",
      "updated_at": "2024-01-15T09:30:00Z",
      "description": "string",
      "category": "media",
      "is_favorite": false,
      "created_by": "string"
    }
  ],
  "meta": {
    "request_id": "string",
    "timestamp": "2024-01-15T09:30:00Z"
  },
  "pagination": {
    "limit": 1,
    "next": "string",
    "prev": "string"
  }
}
```

**SDK Code**

```python
import requests

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

headers = {"Authorization": "Bearer <token>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.onepin.ai/api/v1/templates';
const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

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

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

	req.Header.Add("Authorization", "Bearer <token>")

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

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

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

}
```

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

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

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

request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'

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

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

HttpResponse<String> response = Unirest.get("https://api.onepin.ai/api/v1/templates")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://api.onepin.ai/api/v1/templates', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.onepin.ai/api/v1/templates");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.onepin.ai/api/v1/templates")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
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()
```